Class: DPay::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/dpay/payment/transaction.rb,
sig/dpay/payment/transaction.rbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Transaction

Returns a new instance of Transaction.

Parameters:

  • data (Hash[String, untyped])


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dpay/payment/transaction.rb', line 12

def initialize(data)
  @raw = data
  tx = data["transaction"].is_a?(Hash) ? data["transaction"] : {}

  @id = Internal::Coerce.string(tx["id"]) || ""
  @value = Internal::Coerce.money(tx["value"])
  @status = Internal::Coerce.string(tx["status"]) || ""
  @payment_method = Internal::Coerce.string(tx["payment_method"])
  @creation_date = Internal::Coerce.string(tx["creation_date"])
  @payment_date = tx["payment_date"].is_a?(String) ? tx["payment_date"] : nil
  @settled = Internal::Coerce.boolean(tx["settled"])
  @refunded = Internal::Coerce.boolean(tx["refunded"])
  @refunded_amount = Internal::Coerce.money(tx["refunded_amount"])
  @available_refund_amount = Internal::Coerce.money(tx["available_refund_amount"])
  @fully_refunded = Internal::Coerce.boolean(tx["fully_refunded"])
  @direct = Internal::Coerce.boolean(tx["direct"])
  @gateway_id = tx["gateway_id"].is_a?(String) ? tx["gateway_id"] : nil
  @payer = data["payer"].is_a?(Hash) ? data["payer"] : {}
  @refunds = Internal::Coerce.list(data["refunds"]).map { |refund| TransactionRefund.from_api(refund) }
  freeze
end

Instance Attribute Details

#available_refund_amountMoney (readonly)

Returns the value of attribute available_refund_amount.

Returns:



5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def available_refund_amount
  @available_refund_amount
end

#creation_dateString? (readonly)

Returns the value of attribute creation_date.

Returns:

  • (String, nil)


5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def creation_date
  @creation_date
end

#gateway_idString? (readonly)

Returns the value of attribute gateway_id.

Returns:

  • (String, nil)


5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def gateway_id
  @gateway_id
end

#idString (readonly)

Returns the value of attribute id.

Returns:

  • (String)


5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def id
  @id
end

#payerHash[String, untyped] (readonly)

Returns the value of attribute payer.

Returns:

  • (Hash[String, untyped])


5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def payer
  @payer
end

#payment_dateString? (readonly)

Returns the value of attribute payment_date.

Returns:

  • (String, nil)


5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def payment_date
  @payment_date
end

#payment_methodString? (readonly)

Returns the value of attribute payment_method.

Returns:

  • (String, nil)


5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def payment_method
  @payment_method
end

#rawHash[String, untyped] (readonly)

Returns the value of attribute raw.

Returns:

  • (Hash[String, untyped])


5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def raw
  @raw
end

#refunded_amountMoney (readonly)

Returns the value of attribute refunded_amount.

Returns:



5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def refunded_amount
  @refunded_amount
end

#refundsArray[TransactionRefund] (readonly)

Returns the value of attribute refunds.

Returns:



5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def refunds
  @refunds
end

#statusString (readonly)

Returns the value of attribute status.

Returns:

  • (String)


5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def status
  @status
end

#valueMoney (readonly)

Returns the value of attribute value.

Returns:



5
6
7
# File 'lib/dpay/payment/transaction.rb', line 5

def value
  @value
end

Class Method Details

.from_api(data) ⇒ Transaction

Parameters:

  • data (Hash[String, untyped])

Returns:



8
9
10
# File 'lib/dpay/payment/transaction.rb', line 8

def self.from_api(data)
  new(data)
end

Instance Method Details

#direct?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/dpay/payment/transaction.rb', line 50

def direct?
  @direct
end

#fully_refunded?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dpay/payment/transaction.rb', line 46

def fully_refunded?
  @fully_refunded
end

#paid?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/dpay/payment/transaction.rb', line 34

def paid?
  @status == TransactionStatus::PAID || @status == TransactionStatus::CAPTURED
end

#refunded?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/dpay/payment/transaction.rb', line 42

def refunded?
  @refunded
end

#settled?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/dpay/payment/transaction.rb', line 38

def settled?
  @settled
end