Module: Kaui::PaymentState
- Included in:
- InvoicePayment, Payment
- Defined in:
- app/models/kaui/payment_state.rb
Constant Summary collapse
- REFUNDABLE_TRANSACTION_TYPES =
%w[CAPTURE PURCHASE].freeze
Instance Method Summary collapse
- #amount_capturable ⇒ Object
- #amount_refundable ⇒ Object
- #capturable? ⇒ Boolean
- #chargebackable? ⇒ Boolean
- #fully_refunded? ⇒ Boolean
- #paid_amount_to_money ⇒ Object
- #refundable? ⇒ Boolean
-
#returned_amount_to_money ⇒ Object
TODO: Better name?.
- #total_authed_amount_to_money ⇒ Object
- #voidable? ⇒ Boolean
Instance Method Details
#amount_capturable ⇒ Object
18 19 20 |
# File 'app/models/kaui/payment_state.rb', line 18 def amount_capturable auth_amount - captured_amount end |
#amount_refundable ⇒ Object
14 15 16 |
# File 'app/models/kaui/payment_state.rb', line 14 def amount_refundable captured_amount + purchased_amount - refunded_amount end |
#capturable? ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/kaui/payment_state.rb', line 22 def capturable? maybe = false transactions.each do |transaction| next unless transaction.status == 'SUCCESS' return false if transaction.transaction_type == 'VOID' maybe = true if transaction.transaction_type == 'AUTHORIZE' end maybe && refunded_amount.zero? end |
#chargebackable? ⇒ Boolean
40 41 42 |
# File 'app/models/kaui/payment_state.rb', line 40 def chargebackable? refundable? end |
#fully_refunded? ⇒ Boolean
57 58 59 |
# File 'app/models/kaui/payment_state.rb', line 57 def fully_refunded? refunded_amount == captured_amount || refunded_amount == purchased_amount end |
#paid_amount_to_money ⇒ Object
48 49 50 |
# File 'app/models/kaui/payment_state.rb', line 48 def paid_amount_to_money captured_amount_to_money + purchased_amount_to_money end |
#refundable? ⇒ Boolean
7 8 9 10 11 12 |
# File 'app/models/kaui/payment_state.rb', line 7 def refundable? transactions.each do |transaction| return true if transaction.status == 'SUCCESS' && REFUNDABLE_TRANSACTION_TYPES.include?(transaction.transaction_type) end false end |
#returned_amount_to_money ⇒ Object
TODO: Better name?
53 54 55 |
# File 'app/models/kaui/payment_state.rb', line 53 def returned_amount_to_money refunded_amount_to_money + credited_amount_to_money end |
#total_authed_amount_to_money ⇒ Object
44 45 46 |
# File 'app/models/kaui/payment_state.rb', line 44 def total_authed_amount_to_money auth_amount_to_money + purchased_amount_to_money end |
#voidable? ⇒ Boolean
33 34 35 36 37 38 |
# File 'app/models/kaui/payment_state.rb', line 33 def voidable? transactions.each do |transaction| return false if transaction.status == 'SUCCESS' && transaction.transaction_type == 'VOID' end capturable? && captured_amount.zero? end |