Class: Portmone::Transaction
- Inherits:
-
Object
- Object
- Portmone::Transaction
- Defined in:
- lib/portmone/transaction.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #bill_amount ⇒ Object
- #bill_date ⇒ Object
-
#initialize(data) ⇒ Transaction
constructor
A new instance of Transaction.
- #order_id ⇒ Object
- #paid? ⇒ Boolean
- #pay_order_time ⇒ Object
- #pay_time ⇒ Object
- #reversed? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Transaction
Returns a new instance of Transaction.
5 6 7 8 9 10 11 |
# File 'lib/portmone/transaction.rb', line 5 def initialize(data) raise Error, "Wrong data: Hash expected, got #{data.inspect}" unless data.is_a?(Hash) @timezone = data.delete(:timezone) @currency = data.delete(:currency) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/portmone/transaction.rb', line 3 def data @data end |
Instance Method Details
#bill_amount ⇒ Object
25 26 27 |
# File 'lib/portmone/transaction.rb', line 25 def bill_amount Money.from_amount(data['bill_amount'].to_f, @currency) end |
#bill_date ⇒ Object
13 14 15 |
# File 'lib/portmone/transaction.rb', line 13 def bill_date data['bill_date'] && Date.parse(data['bill_date']) end |
#order_id ⇒ Object
29 30 31 |
# File 'lib/portmone/transaction.rb', line 29 def order_id data.dig('shop_bill_id') end |
#paid? ⇒ Boolean
33 34 35 |
# File 'lib/portmone/transaction.rb', line 33 def paid? status == 'PAYED' || status == 'PREAUTH' end |
#pay_order_time ⇒ Object
21 22 23 |
# File 'lib/portmone/transaction.rb', line 21 def pay_order_time data['pay_order_date'] && ActiveSupport::TimeZone[@timezone].parse(data['pay_order_date']) end |
#pay_time ⇒ Object
17 18 19 |
# File 'lib/portmone/transaction.rb', line 17 def pay_time data['pay_date'] && ActiveSupport::TimeZone[@timezone].parse(data['pay_date']) end |
#reversed? ⇒ Boolean
37 38 39 |
# File 'lib/portmone/transaction.rb', line 37 def reversed? status == 'RETURN' end |