class PensioAPI::Transaction
Constants
- CHARGE_SUCCESS_STATUSES
- RESERVATION_SUCCESS_STATUSES
- STATUS_CAPTURED
- STATUS_CAPTURED_FAILED
- STATUS_RECURRING_CONFIRMED
constants for transaction statuses
- STATUS_RELEASED
Attributes
captured_amount[R]
card_holder_currency[R]
card_masked_pan[R]
card_status[R]
card_token[R]
chargeback_events[R]
merchant_currency[R]
order_id[R]
payment_source[R]
recurring_default_amount[R]
refunded_amount[R]
reserved_amount[R]
status[R]
Public Class Methods
find(options={})
click to toggle source
# File lib/pensio_api/transaction.rb, line 54 def self.find(options={}) request = Request.new('/merchant/API/payments', options) Responses::Transaction.new(request) end
new(transaction_body)
click to toggle source
# 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
Public Instance Methods
billing_address()
click to toggle source
# 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?()
click to toggle source
# File lib/pensio_api/transaction.rb, line 59 def captured? captured_amount >= reserved_amount && CHARGE_SUCCESS_STATUSES.include?(self.transaction_status) end
refund(options={})
click to toggle source
# File lib/pensio_api/transaction.rb, line 75 def refund(options={}) request = Request.new('/merchant/API/refundCapturedReservation', options.merge(transaction_id: self.id)) Responses::Refund.new(request) end
reserved?()
click to toggle source
# File lib/pensio_api/transaction.rb, line 63 def reserved? RESERVATION_SUCCESS_STATUSES.include?(self.transaction_status) end
terminal()
click to toggle source
# File lib/pensio_api/transaction.rb, line 80 def terminal @terminal ||= Terminal.all.find { |t| t.title == @raw['Terminal'] } end
to_reservation()
click to toggle source
# File lib/pensio_api/transaction.rb, line 67 def to_reservation Reservation.new(self) end
to_subscription()
click to toggle source
# File lib/pensio_api/transaction.rb, line 71 def to_subscription Subscription.new(self) end
Private Instance Methods
map_chargeback_events()
click to toggle source
# File lib/pensio_api/transaction.rb, line 92 def map_chargeback_events @chargeback_events = if raw_chargeback_events.is_a?(Array) raw_chargeback_events.map { |c| PensioAPI::ChargebackEvent.new(c) } else [PensioAPI::ChargebackEvent.new(raw_chargeback_events)] end end
raw_chargeback_events()
click to toggle source
# File lib/pensio_api/transaction.rb, line 100 def raw_chargeback_events @raw_chargeback_events ||= if @raw['ChargebackEvents'] @raw['ChargebackEvents']['ChargebackEvent'] else [] end end