-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
monopay-ruby (1.0.0) | ||
monopay-ruby (1.1.0) | ||
base64 (~> 0.1.1) | ||
json (~> 2.5) | ||
money (~> 6.13) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require_relative 'simple_invoice' | ||
|
||
module MonopayRuby | ||
module Invoices | ||
class AdvancedInvoice < MonopayRuby::Invoices::SimpleInvoice | ||
attr_reader :basketOrder, :otherParams | ||
|
||
def create(amount, destination: nil, reference: nil, basketOrder: {}, otherParams: {}) | ||
@basketOrder = basketOrder | ||
@otherParams = otherParams | ||
|
||
super(amount, destination: destination, reference: reference) | ||
end | ||
|
||
# Request body required for Monobank API | ||
# | ||
# @return [Hash] request body | ||
def request_body | ||
# TODO: add "ccy" and another missing params | ||
# TODO: remove nil valued params | ||
request_body = { | ||
amount: amount, | ||
redirectUrl: redirect_url, | ||
webHookUrl: webhook_url, | ||
merchantPaymInfo: { | ||
reference: reference, | ||
destination: destination | ||
|
||
} | ||
} | ||
|
||
request_body[:merchantPaymInfo][:basketOrder] = basketOrder if basketOrder.any? | ||
request_body.merge!(otherParams).to_json | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module MonopayRuby | ||
VERSION = "1.0.0" | ||
VERSION = "1.1.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe MonopayRuby::Invoices::AdvancedInvoice do | ||
describe "#new" do | ||
let!(:redirect_url) { "https://redirect.example.com" } | ||
let!(:webhook_url) { "https://webhook.example.com" } | ||
|
||
context "with keyword parameters" do | ||
subject { described_class.new(redirect_url: redirect_url, webhook_url: webhook_url) } | ||
|
||
it "initializes with correct redirect_url" do | ||
expect(subject.redirect_url).to eq(redirect_url) | ||
end | ||
|
||
it "initializes with correct webhook_url" do | ||
expect(subject.webhook_url).to eq(webhook_url) | ||
end | ||
end | ||
|
||
context "without keyword parameters" do | ||
subject { described_class.new(redirect_url, webhook_url) } | ||
|
||
it "raises an ArgumentError" do | ||
expect { subject }.to raise_error(ArgumentError) | ||
end | ||
end | ||
|
||
context "without parameters" do | ||
subject { described_class.new } | ||
|
||
it { is_expected.to be_a(described_class) } | ||
end | ||
end | ||
|
||
describe "#create" do | ||
context "when request is successful" do | ||
let(:simple_invoice_instance) { described_class.new } | ||
let(:invoice_id) { "p2_9ZgpZVsl3" } | ||
let(:page_url) { "https://pay.mbnk.biz/p2_9ZgpZVsl3" } | ||
let(:basket_order) { { name: "product", qty: 1 } } | ||
let(:other_params) { { ccy: 9 } } | ||
let(:response_example) { { "invoiceId": invoice_id, "pageUrl": page_url } } | ||
|
||
before do | ||
allow(RestClient).to receive(:post).and_return(double(body: response_example.to_json)) | ||
end | ||
|
||
it "returns true" do | ||
expect(simple_invoice_instance.create(2000, basketOrder: basket_order, otherParams: other_params)).to be_truthy | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters