Class: Myrr::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/myrr/transaction.rb

Overview

Read-only value object representing a wallet transaction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Transaction

Returns a new instance of Transaction.

Parameters:

  • attrs (Hash)

    Transaction attributes from the API



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

#amountObject (readonly)

Returns the value of attribute amount.



6
7
8
# File 'lib/myrr/transaction.rb', line 6

def amount
  @amount
end

#created_atObject (readonly)

Returns the value of attribute created_at.



6
7
8
# File 'lib/myrr/transaction.rb', line 6

def created_at
  @created_at
end

#currencyObject (readonly)

Returns the value of attribute currency.



6
7
8
# File 'lib/myrr/transaction.rb', line 6

def currency
  @currency
end

#decline_reasonObject (readonly)

Returns the value of attribute decline_reason.



6
7
8
# File 'lib/myrr/transaction.rb', line 6

def decline_reason
  @decline_reason
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/myrr/transaction.rb', line 6

def id
  @id
end

#merchant_categoryObject (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_nameObject (readonly)

Returns the value of attribute merchant_name.



6
7
8
# File 'lib/myrr/transaction.rb', line 6

def merchant_name
  @merchant_name
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/myrr/transaction.rb', line 6

def source
  @source
end

#statusObject (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_dollarsString

Returns Human-readable amount.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    Whether the transaction was authorized



28
29
30
# File 'lib/myrr/transaction.rb', line 28

def authorized?
  @status == "authorized"
end

#declined?Boolean

Returns Whether the transaction was declined.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    Whether this is a wallet funding



48
49
50
# File 'lib/myrr/transaction.rb', line 48

def wallet_funding?
  @source == "wallet_funding"
end