Class: Myrr::Transaction
- Inherits:
-
Object
- Object
- Myrr::Transaction
- Defined in:
- lib/myrr/transaction.rb
Overview
Read-only value object representing a wallet transaction.
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#decline_reason ⇒ Object
readonly
Returns the value of attribute decline_reason.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#merchant_category ⇒ Object
readonly
Returns the value of attribute merchant_category.
-
#merchant_name ⇒ Object
readonly
Returns the value of attribute merchant_name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#amount_dollars ⇒ String
Human-readable amount.
-
#authorized? ⇒ Boolean
Whether the transaction was authorized.
-
#declined? ⇒ Boolean
Whether the transaction was declined.
-
#funding? ⇒ Boolean
Whether this is a funding transaction.
-
#initialize(attrs) ⇒ Transaction
constructor
A new instance of Transaction.
-
#merchant_purchase? ⇒ Boolean
Whether this is a regular merchant purchase.
-
#myrr_pay_topup? ⇒ Boolean
Whether this is a Myrr Pay top-up.
-
#wallet_funding? ⇒ Boolean
Whether this is a wallet funding.
Constructor Details
#initialize(attrs) ⇒ Transaction
Returns a new instance of Transaction.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/myrr/transaction.rb', line 10 def initialize(attrs) @id = attrs["id"] @amount = attrs["amount"] @currency = attrs["currency"] || "usd" @status = attrs["status"] @source = attrs["source"] @merchant_name = attrs["merchant_name"] @merchant_category = attrs["merchant_category"] @decline_reason = attrs["decline_reason"] @created_at = attrs["created_at"] end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
6 7 8 |
# File 'lib/myrr/transaction.rb', line 6 def amount @amount end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/myrr/transaction.rb', line 6 def created_at @created_at end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
6 7 8 |
# File 'lib/myrr/transaction.rb', line 6 def currency @currency end |
#decline_reason ⇒ Object (readonly)
Returns the value of attribute decline_reason.
6 7 8 |
# File 'lib/myrr/transaction.rb', line 6 def decline_reason @decline_reason end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/myrr/transaction.rb', line 6 def id @id end |
#merchant_category ⇒ Object (readonly)
Returns the value of attribute merchant_category.
6 7 8 |
# File 'lib/myrr/transaction.rb', line 6 def merchant_category @merchant_category end |
#merchant_name ⇒ Object (readonly)
Returns the value of attribute merchant_name.
6 7 8 |
# File 'lib/myrr/transaction.rb', line 6 def merchant_name @merchant_name end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/myrr/transaction.rb', line 6 def source @source end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/myrr/transaction.rb', line 6 def status @status end |
Instance Method Details
#amount_dollars ⇒ String
Returns Human-readable amount.
23 24 25 |
# File 'lib/myrr/transaction.rb', line 23 def amount_dollars "$" + format("%.2f", @amount.to_f / 100) end |
#authorized? ⇒ Boolean
Returns Whether the transaction was authorized.
28 29 30 |
# File 'lib/myrr/transaction.rb', line 28 def @status == "authorized" end |
#declined? ⇒ Boolean
Returns Whether the transaction was declined.
33 34 35 |
# File 'lib/myrr/transaction.rb', line 33 def declined? @status == "declined" end |
#funding? ⇒ Boolean
Returns Whether this is a funding transaction.
38 39 40 |
# File 'lib/myrr/transaction.rb', line 38 def funding? @status == "funding" end |
#merchant_purchase? ⇒ Boolean
Returns Whether this is a regular merchant purchase.
53 54 55 |
# File 'lib/myrr/transaction.rb', line 53 def merchant_purchase? @source.nil? || @source == "merchant_purchase" end |
#myrr_pay_topup? ⇒ Boolean
Returns Whether this is a Myrr Pay top-up.
43 44 45 |
# File 'lib/myrr/transaction.rb', line 43 def myrr_pay_topup? @source == "myrr_pay_topup" end |
#wallet_funding? ⇒ Boolean
Returns Whether this is a wallet funding.
48 49 50 |
# File 'lib/myrr/transaction.rb', line 48 def wallet_funding? @source == "wallet_funding" end |