Skip to content

Commit

Permalink
chore: add ability to pass reference and destination by named parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
loqimean committed Jun 19, 2023
1 parent cf770b2 commit c8b1122
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]
## [0.1.1] - 2023-06-19

## [0.1.0] - 2023-06-15
- Fix typo in a `README.md` file
- add ability to pass reference to an invoice by `reference` parameter in a `MonopayRuby::Invoices::SimpleInvoice::create` method
- Use named parameter of `destionation` for "MonopayRuby::Invoices::SimpleInvoice::create" method

- Initial release
## [0.1.0] - 2023-06-18

- Initial public release
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
monopay-ruby (0.1.0)
monopay-ruby (0.1.1)
base64 (~> 0.1.1)
json (~> 2.5)
money (~> 6.13)
Expand Down
11 changes: 7 additions & 4 deletions lib/monopay-ruby/invoices/simple_invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
module MonopayRuby
module Invoices
class SimpleInvoice < MonopayRuby::Base
attr_reader :invoice_id, :page_url, :error_messages, :amount, :destination, :redirect_url, :webhook_url
attr_reader :invoice_id, :page_url, :error_messages, :amount, :destination, :reference, :redirect_url, :webhook_url

API_CREATE_INVOICE_URL = "#{API_URL}/merchant/invoice/create".freeze

CURRENCY = "UAH".freeze
DEFAULT_CURRENCY = "UAH".freeze

PAGE_URL_KEY = "pageUrl".freeze
INVOICE_ID_KEY = "invoiceId".freeze
Expand All @@ -28,11 +28,13 @@ def initialize(redirect_url = nil, webhook_url = nil)
#
# @param [BigDecimal,Integer] amount in UAH (cents) to request payment
# @param [String] destination - additional info about payment
# @param [String] reference - bill number or other reference
# @return [Boolean] true if invoice was created successfully, false otherwise
def create(amount, destination = nil)
def create(amount, destination: nil, reference: nil)
begin
@amount = convert_to_cents(amount)
@destination = destination
@reference = reference

response = RestClient.post(API_CREATE_INVOICE_URL, request_body, headers)
response_body = JSON.parse(response.body)
Expand Down Expand Up @@ -64,14 +66,15 @@ def request_body
redirectUrl: redirect_url,
webHookUrl: webhook_url,
merchantPaymInfo: {
reference: reference,
destination: destination
}
}.to_json
end

def convert_to_cents(amount)
if amount.is_a?(BigDecimal)
Money.from_amount(amount, CURRENCY).cents
Money.from_amount(amount, DEFAULT_CURRENCY).cents
else
amount
end
Expand Down
2 changes: 1 addition & 1 deletion lib/monopay-ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module MonopayRuby
VERSION = "0.1.0"
VERSION = "0.1.1"
end

0 comments on commit c8b1122

Please sign in to comment.