Class: MonopayRuby::Invoices::SimpleInvoice
- Defined in:
- lib/monopay-ruby/invoices/simple_invoice.rb
Constant Summary collapse
- API_CREATE_INVOICE_URL =
"#{API_URL}/merchant/invoice/create".freeze
- DEFAULT_CURRENCY =
"UAH".freeze
- PAGE_URL_KEY =
"pageUrl".freeze
- INVOICE_ID_KEY =
"invoiceId".freeze
Constants inherited from Base
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#error_messages ⇒ Object
readonly
Returns the value of attribute error_messages.
-
#invoice_id ⇒ Object
readonly
Returns the value of attribute invoice_id.
-
#page_url ⇒ Object
readonly
Returns the value of attribute page_url.
-
#redirect_url ⇒ Object
readonly
Returns the value of attribute redirect_url.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#webhook_url ⇒ Object
readonly
Returns the value of attribute webhook_url.
Instance Method Summary collapse
-
#create(amount, destination: nil, reference: nil) ⇒ Boolean
Create invoice.
-
#initialize(redirect_url: nil, webhook_url: nil) ⇒ SimpleInvoice
constructor
Initialize SimpleInvoice.
Constructor Details
#initialize(redirect_url: nil, webhook_url: nil) ⇒ SimpleInvoice
Initialize SimpleInvoice
20 21 22 23 24 25 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 20 def initialize(redirect_url: nil, webhook_url: nil) @redirect_url = redirect_url @webhook_url = webhook_url @error_messages = [] end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
7 8 9 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 7 def amount @amount end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
7 8 9 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 7 def destination @destination end |
#error_messages ⇒ Object (readonly)
Returns the value of attribute error_messages.
7 8 9 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 7 def @error_messages end |
#invoice_id ⇒ Object (readonly)
Returns the value of attribute invoice_id.
7 8 9 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 7 def invoice_id @invoice_id end |
#page_url ⇒ Object (readonly)
Returns the value of attribute page_url.
7 8 9 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 7 def page_url @page_url end |
#redirect_url ⇒ Object (readonly)
Returns the value of attribute redirect_url.
7 8 9 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 7 def redirect_url @redirect_url end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
7 8 9 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 7 def reference @reference end |
#webhook_url ⇒ Object (readonly)
Returns the value of attribute webhook_url.
7 8 9 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 7 def webhook_url @webhook_url end |
Instance Method Details
#create(amount, destination: nil, reference: nil) ⇒ Boolean
Create invoice
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/monopay-ruby/invoices/simple_invoice.rb', line 33 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) @page_url = JSON.parse(response.body)[PAGE_URL_KEY] @invoice_id = JSON.parse(response.body)[INVOICE_ID_KEY] true rescue Exception => e response_body = JSON.parse(e.response.body) @error_messages << [e., response_body].join(", ") # TODO: use errors and full_messages like rails # TODO: use logger to log errors or successful invoice creation false end end |