Class: Afterpay::Utils::Money

Inherits:
Object
  • Object
show all
Defined in:
lib/afterpay/utils/money.rb

Class Method Summary collapse

Class Method Details

.api_hash(money) ⇒ Object

Converts <oney to API compatible hash format



18
19
20
21
22
23
# File 'lib/afterpay/utils/money.rb', line 18

def self.api_hash(money)
  {
    amount: money.dollars.to_f,
    currency: money.currency.iso_code
  }
end

.from_response(response) ⇒ Money

Converts Afterpay response to ‘Money`

Returns:



8
9
10
11
12
13
14
15
# File 'lib/afterpay/utils/money.rb', line 8

def self.from_response(response)
  return nil if response.nil?

  ::Money.from_amount(
    response[:amount].to_f,
    response[:currency]
  )
end