Class: MonopayRuby::Invoices::AdvancedInvoice

Inherits:
SimpleInvoice show all
Defined in:
lib/monopay-ruby/invoices/advanced_invoice.rb

Constant Summary

Constants inherited from SimpleInvoice

SimpleInvoice::API_CREATE_INVOICE_URL, SimpleInvoice::DEFAULT_CURRENCY, SimpleInvoice::INVOICE_ID_KEY, SimpleInvoice::PAGE_URL_KEY

Constants inherited from Base

Base::API_URL

Instance Attribute Summary collapse

Attributes inherited from SimpleInvoice

#destination, #error_messages, #invoice_id, #page_url, #redirect_url, #reference, #webhook_url

Instance Method Summary collapse

Methods inherited from SimpleInvoice

#initialize

Constructor Details

This class inherits a constructor from MonopayRuby::Invoices::SimpleInvoice

Instance Attribute Details

#additional_paramsObject (readonly)

Returns the value of attribute additional_params.



8
9
10
# File 'lib/monopay-ruby/invoices/advanced_invoice.rb', line 8

def additional_params
  @additional_params
end

#amountObject (readonly)

Returns the value of attribute amount.



8
9
10
# File 'lib/monopay-ruby/invoices/advanced_invoice.rb', line 8

def amount
  @amount
end

Instance Method Details

#create(amount, additional_params: {}) ⇒ Boolean

Create invoice for Monobank API

This method sets up the required instance variables and then calls the ‘create` method from the parent class with the relevant parameters.

Examples:

Create a payment with amount and additional parameters

create(100, additional_params: { merchantPaymInfo: { destination: "Happy payment", reference: "ref123" } })

Parameters:

  • amount (Numeric)

    The amount of the payment.

  • additional_params (Hash) (defaults to: {})

    (optional) Additional parameters for the payment.

    • :merchantPaymInfo [Hash] Information about the merchant payment.

      • :destination [String] The destination of the payment.

      • :reference [String] A reference for the payment.

Returns:

  • (Boolean)

    The result of the ‘create` method in the parent class, which returns true if invoice was created successfully, false otherwise



26
27
28
29
30
31
32
33
# File 'lib/monopay-ruby/invoices/advanced_invoice.rb', line 26

def create(amount, additional_params: {})
  @amount = amount
  @additional_params = additional_params
  @destination = @additional_params.dig(:merchantPaymInfo, :destination)
  @reference = @additional_params.dig(:merchantPaymInfo, :reference)

  super(amount, destination: @destination, reference: @reference)
end