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
- #is_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
14 15 16 |
# File 'app/models/kaui/payment_state.rb', line 14 def amount_capturable auth_amount - captured_amount end |
#amount_refundable ⇒ Object
10 11 12 |
# File 'app/models/kaui/payment_state.rb', line 10 def amount_refundable captured_amount + purchased_amount - refunded_amount end |
#capturable? ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/kaui/payment_state.rb', line 18 def capturable? maybe = false transactions.each do |transaction| if transaction.status == 'SUCCESS' return false if transaction.transaction_type == 'VOID' maybe = true if transaction.transaction_type == 'AUTHORIZE' end end maybe && refunded_amount == 0 end |
#chargebackable? ⇒ Boolean
36 37 38 |
# File 'app/models/kaui/payment_state.rb', line 36 def chargebackable? refundable? end |
#is_fully_refunded? ⇒ Boolean
53 54 55 |
# File 'app/models/kaui/payment_state.rb', line 53 def is_fully_refunded? refunded_amount == captured_amount || refunded_amount == purchased_amount end |
#paid_amount_to_money ⇒ Object
44 45 46 |
# File 'app/models/kaui/payment_state.rb', line 44 def paid_amount_to_money captured_amount_to_money + purchased_amount_to_money end |
#refundable? ⇒ Boolean
3 4 5 6 7 8 |
# File 'app/models/kaui/payment_state.rb', line 3 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?
49 50 51 |
# File 'app/models/kaui/payment_state.rb', line 49 def returned_amount_to_money refunded_amount_to_money + credited_amount_to_money end |
#total_authed_amount_to_money ⇒ Object
40 41 42 |
# File 'app/models/kaui/payment_state.rb', line 40 def total_authed_amount_to_money auth_amount_to_money + purchased_amount_to_money end |
#voidable? ⇒ Boolean
29 30 31 32 33 34 |
# File 'app/models/kaui/payment_state.rb', line 29 def voidable? transactions.each do |transaction| return false if transaction.status == 'SUCCESS' && transaction.transaction_type == 'VOID' end capturable? && captured_amount == 0 end |