Module: Kaui::PaymentState
- Included in:
- InvoicePayment, Payment
- Defined in:
- app/models/kaui/payment_state.rb
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
16 17 18 |
# File 'app/models/kaui/payment_state.rb', line 16 def amount_capturable auth_amount - captured_amount end |
#amount_refundable ⇒ Object
12 13 14 |
# File 'app/models/kaui/payment_state.rb', line 12 def amount_refundable captured_amount + purchased_amount - refunded_amount end |
#capturable? ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/kaui/payment_state.rb', line 20 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
38 39 40 |
# File 'app/models/kaui/payment_state.rb', line 38 def chargebackable? refundable? end |
#fully_refunded? ⇒ Boolean
55 56 57 |
# File 'app/models/kaui/payment_state.rb', line 55 def fully_refunded? refunded_amount == captured_amount || refunded_amount == purchased_amount end |
#paid_amount_to_money ⇒ Object
46 47 48 |
# File 'app/models/kaui/payment_state.rb', line 46 def paid_amount_to_money captured_amount_to_money + purchased_amount_to_money end |
#refundable? ⇒ Boolean
5 6 7 8 9 10 |
# File 'app/models/kaui/payment_state.rb', line 5 def refundable? transactions.each do |transaction| return true if transaction.status == 'SUCCESS' && %w[CAPTURE PURCHASE].include?(transaction.transaction_type) end false end |
#returned_amount_to_money ⇒ Object
TODO: Better name?
51 52 53 |
# File 'app/models/kaui/payment_state.rb', line 51 def returned_amount_to_money refunded_amount_to_money + credited_amount_to_money end |
#total_authed_amount_to_money ⇒ Object
42 43 44 |
# File 'app/models/kaui/payment_state.rb', line 42 def total_authed_amount_to_money auth_amount_to_money + purchased_amount_to_money end |
#voidable? ⇒ Boolean
31 32 33 34 35 36 |
# File 'app/models/kaui/payment_state.rb', line 31 def voidable? transactions.each do |transaction| return false if transaction.status == 'SUCCESS' && transaction.transaction_type == 'VOID' end capturable? && captured_amount.zero? end |