Module: Kaui::PaymentState

Included in:
InvoicePayment, Payment
Defined in:
app/models/kaui/payment_state.rb

Instance Method Summary collapse

Instance Method Details

#amount_capturableObject


14
15
16
# File 'app/models/kaui/payment_state.rb', line 14

def amount_capturable
  auth_amount - captured_amount
end

#amount_refundableObject


10
11
12
# File 'app/models/kaui/payment_state.rb', line 10

def amount_refundable
  captured_amount + purchased_amount - refunded_amount
end

#capturable?Boolean

Returns:

  • (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

Returns:

  • (Boolean)

36
37
38
# File 'app/models/kaui/payment_state.rb', line 36

def chargebackable?
  refundable?
end

#is_fully_refunded?Boolean

Returns:

  • (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

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

Returns:

  • (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_moneyObject

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_moneyObject


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

Returns:

  • (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