Class: MonoMerchant::Invoice::Create

Inherits:
ApiRequest show all
Defined in:
lib/mono-merchant/invoice/create.rb

Overview

Create invoice

Constant Summary

Constants inherited from ApiRequest

ApiRequest::API_URL, ApiRequest::DEFAULT_CURRENCY

Instance Attribute Summary collapse

Attributes inherited from ApiRequest

#errors, #type

Instance Method Summary collapse

Methods inherited from ApiRequest

#url

Constructor Details

#initialize(amount, currency: DEFAULT_CURRENCY, items: [], hold: false, reference: nil, redirect_url: nil, webhook_url: nil, email: nil, destination: nil, comment: nil) ⇒ Create

Returns a new instance of Create.

Parameters:

  • amount (BigDecimal, Integer)

    (cents) to request payment

  • destination (String) (defaults to: nil)
    • additional info about payment

  • reference (String) (defaults to: nil)
    • bill number or other reference

  • comment (String) (defaults to: nil)
    • internal service info

  • currency (String) (defaults to: DEFAULT_CURRENCY)
    • currency iso code

  • hold (Boolean) (defaults to: false)
    • if payment type is ‘hold’ (default: ‘debit’)

  • email (String) (defaults to: nil)
    • client email

  • items (Array) (defaults to: [])
    • cart content

  • redirect_url (String) (defaults to: nil)
    • url where user will be redirected after payment

  • webhook_url (String) (defaults to: nil)
    • url where Monobank will send webhook after payment



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mono-merchant/invoice/create.rb', line 19

def initialize(amount, currency: DEFAULT_CURRENCY, items: [], hold: false, reference: nil, redirect_url: nil, webhook_url: nil, email: nil, destination: nil, comment: nil)
  @amount = convert_to_cents(amount)
  @destination = destination
  @reference = reference
  @comment = comment
  @customer_emails = [email] if email
  @redirect_url = redirect_url
  @webhook_url = webhook_url
  @currency = Money::Currency.new(currency)
  @items = items.map { |i| Item.new(i).to_hash.presence }
  @payment_type = hold ? 'hold' : 'debit'
  super()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MonoMerchant::ApiRequest

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def amount
  @amount
end

#commentObject (readonly)

Returns the value of attribute comment.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def comment
  @comment
end

#currencyObject (readonly)

Returns the value of attribute currency.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def currency
  @currency
end

#customer_emailsObject (readonly)

Returns the value of attribute customer_emails.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def customer_emails
  @customer_emails
end

#destinationObject (readonly)

Returns the value of attribute destination.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def destination
  @destination
end

#itemsObject (readonly)

Returns the value of attribute items.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def items
  @items
end

#payment_typeObject (readonly)

Returns the value of attribute payment_type.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def payment_type
  @payment_type
end

#redirect_urlObject (readonly)

Returns the value of attribute redirect_url.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def redirect_url
  @redirect_url
end

#referenceObject (readonly)

Returns the value of attribute reference.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def reference
  @reference
end

#webhook_urlObject (readonly)

Returns the value of attribute webhook_url.



7
8
9
# File 'lib/mono-merchant/invoice/create.rb', line 7

def webhook_url
  @webhook_url
end