Class: Afterpay::Discount

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, amount:) ⇒ Discount

Returns a new instance of Discount.



7
8
9
10
# File 'lib/afterpay/discount.rb', line 7

def initialize(name:, amount:)
  @name = name
  @amount = amount
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



5
6
7
# File 'lib/afterpay/discount.rb', line 5

def amount
  @amount
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/afterpay/discount.rb', line 5

def name
  @name
end

Class Method Details

.from_response(response) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/afterpay/discount.rb', line 19

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

  new(
    name: response[:displayName],
    amount: Utils::Money.from_response(response[:amount])
  )
end

Instance Method Details

#to_hashObject



12
13
14
15
16
17
# File 'lib/afterpay/discount.rb', line 12

def to_hash
  {
    displayName: name,
    amount: Utils::Money.api_hash(amount)
  }
end