Class: PensioAPI::Transaction
- Inherits:
-
Object
- Object
- PensioAPI::Transaction
- Includes:
- Mixins::ID, Mixins::MethodMissing, Mixins::Timestamps
- Defined in:
- lib/pensio_api/transaction.rb
Direct Known Subclasses
Constant Summary collapse
- STATUS_RECURRING_CONFIRMED =
constants for transaction statuses
'recurring_confirmed'- STATUS_RELEASED =
'released'- STATUS_CAPTURED =
'captured'- STATUS_CAPTURED_FAILED =
'captured_failed'- RESERVATION_SUCCESS_STATUSES =
[STATUS_RECURRING_CONFIRMED]
- CHARGE_SUCCESS_STATUSES =
[STATUS_CAPTURED]
Instance Attribute Summary collapse
-
#captured_amount ⇒ Object
readonly
Returns the value of attribute captured_amount.
-
#card_holder_currency ⇒ Object
readonly
Returns the value of attribute card_holder_currency.
-
#card_masked_pan ⇒ Object
readonly
Returns the value of attribute card_masked_pan.
-
#card_status ⇒ Object
readonly
Returns the value of attribute card_status.
-
#card_token ⇒ Object
readonly
Returns the value of attribute card_token.
-
#chargeback_events ⇒ Object
readonly
Returns the value of attribute chargeback_events.
-
#merchant_currency ⇒ Object
readonly
Returns the value of attribute merchant_currency.
-
#order_id ⇒ Object
readonly
Returns the value of attribute order_id.
-
#payment_source ⇒ Object
readonly
Returns the value of attribute payment_source.
-
#recurring_default_amount ⇒ Object
readonly
Returns the value of attribute recurring_default_amount.
-
#refunded_amount ⇒ Object
readonly
Returns the value of attribute refunded_amount.
-
#reserved_amount ⇒ Object
readonly
Returns the value of attribute reserved_amount.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #billing_address ⇒ Object
- #captured? ⇒ Boolean
-
#initialize(transaction_body) ⇒ Transaction
constructor
A new instance of Transaction.
- #refund(options = {}) ⇒ Object
- #reserved? ⇒ Boolean
- #terminal ⇒ Object
- #to_reservation ⇒ Object
- #to_subscription ⇒ Object
Methods included from Mixins::Timestamps
Methods included from Mixins::MethodMissing
Methods included from Mixins::ID
Constructor Details
#initialize(transaction_body) ⇒ Transaction
Returns a new instance of Transaction.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pensio_api/transaction.rb', line 30 def initialize(transaction_body) @raw = transaction_body @status = @raw['TransactionStatus'] @captured_amount = BigDecimal(@raw['CapturedAmount']) @reserved_amount = BigDecimal(@raw['ReservedAmount']) @refunded_amount = BigDecimal(@raw['RefundedAmount']) @recurring_default_amount = BigDecimal(@raw['RecurringDefaultAmount']) @card_status = @raw['CardStatus'] @card_token = @raw['CreditCardToken'] @card_masked_pan = @raw['CreditCardMaskedPan'] @order_id = @raw['ShopOrderId'] @merchant_currency = @raw['MerchantCurrency'].to_i @card_holder_currency = @raw['CardHolderCurrency'].to_i @payment_source = @raw['PaymentSource'] map_chargeback_events end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class PensioAPI::Mixins::MethodMissing
Instance Attribute Details
#captured_amount ⇒ Object (readonly)
Returns the value of attribute captured_amount.
8 9 10 |
# File 'lib/pensio_api/transaction.rb', line 8 def captured_amount @captured_amount end |
#card_holder_currency ⇒ Object (readonly)
Returns the value of attribute card_holder_currency.
17 18 19 |
# File 'lib/pensio_api/transaction.rb', line 17 def card_holder_currency @card_holder_currency end |
#card_masked_pan ⇒ Object (readonly)
Returns the value of attribute card_masked_pan.
14 15 16 |
# File 'lib/pensio_api/transaction.rb', line 14 def card_masked_pan @card_masked_pan end |
#card_status ⇒ Object (readonly)
Returns the value of attribute card_status.
12 13 14 |
# File 'lib/pensio_api/transaction.rb', line 12 def card_status @card_status end |
#card_token ⇒ Object (readonly)
Returns the value of attribute card_token.
13 14 15 |
# File 'lib/pensio_api/transaction.rb', line 13 def card_token @card_token end |
#chargeback_events ⇒ Object (readonly)
Returns the value of attribute chargeback_events.
19 20 21 |
# File 'lib/pensio_api/transaction.rb', line 19 def chargeback_events @chargeback_events end |
#merchant_currency ⇒ Object (readonly)
Returns the value of attribute merchant_currency.
16 17 18 |
# File 'lib/pensio_api/transaction.rb', line 16 def merchant_currency @merchant_currency end |
#order_id ⇒ Object (readonly)
Returns the value of attribute order_id.
15 16 17 |
# File 'lib/pensio_api/transaction.rb', line 15 def order_id @order_id end |
#payment_source ⇒ Object (readonly)
Returns the value of attribute payment_source.
18 19 20 |
# File 'lib/pensio_api/transaction.rb', line 18 def payment_source @payment_source end |
#recurring_default_amount ⇒ Object (readonly)
Returns the value of attribute recurring_default_amount.
11 12 13 |
# File 'lib/pensio_api/transaction.rb', line 11 def recurring_default_amount @recurring_default_amount end |
#refunded_amount ⇒ Object (readonly)
Returns the value of attribute refunded_amount.
10 11 12 |
# File 'lib/pensio_api/transaction.rb', line 10 def refunded_amount @refunded_amount end |
#reserved_amount ⇒ Object (readonly)
Returns the value of attribute reserved_amount.
9 10 11 |
# File 'lib/pensio_api/transaction.rb', line 9 def reserved_amount @reserved_amount end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/pensio_api/transaction.rb', line 7 def status @status end |
Class Method Details
.find(options = {}) ⇒ Object
54 55 56 57 |
# File 'lib/pensio_api/transaction.rb', line 54 def self.find(={}) request = Request.new('/merchant/API/payments', ) Responses::Transaction.new(request) end |
Instance Method Details
#billing_address ⇒ Object
84 85 86 87 88 |
# File 'lib/pensio_api/transaction.rb', line 84 def billing_address @billing_address ||= if @raw.has_key?('CustomerInfo') && @raw['CustomerInfo'].has_key?('BillingAddress') BillingAddress.new(@raw['CustomerInfo']['BillingAddress']) end end |
#captured? ⇒ Boolean
59 60 61 |
# File 'lib/pensio_api/transaction.rb', line 59 def captured? captured_amount >= reserved_amount && CHARGE_SUCCESS_STATUSES.include?(self.transaction_status) end |
#refund(options = {}) ⇒ Object
75 76 77 78 |
# File 'lib/pensio_api/transaction.rb', line 75 def refund(={}) request = Request.new('/merchant/API/refundCapturedReservation', .merge(transaction_id: self.id)) Responses::Refund.new(request) end |
#reserved? ⇒ Boolean
63 64 65 |
# File 'lib/pensio_api/transaction.rb', line 63 def reserved? RESERVATION_SUCCESS_STATUSES.include?(self.transaction_status) end |
#terminal ⇒ Object
80 81 82 |
# File 'lib/pensio_api/transaction.rb', line 80 def terminal @terminal ||= Terminal.all.find { |t| t.title == @raw['Terminal'] } end |
#to_reservation ⇒ Object
67 68 69 |
# File 'lib/pensio_api/transaction.rb', line 67 def to_reservation Reservation.new(self) end |
#to_subscription ⇒ Object
71 72 73 |
# File 'lib/pensio_api/transaction.rb', line 71 def to_subscription Subscription.new(self) end |