Module: Models::Payable

Extended by:
ActiveSupport::Concern
Included in:
Delivery
Defined in:
app/concerns/models/payable.rb

Has many collapse

Instance Method Summary collapse

Instance Method Details

#balance(ignore_cod = false) ⇒ Object



24
25
26
27
28
29
# File 'app/concerns/models/payable.rb', line 24

def balance(ignore_cod = false)
  return BigDecimal('0.0') if order&.is_store_transfer? || (!ignore_cod && funded_by_cod?)

  balance = (total - total_payments_authorized)
  balance < 0 ? BigDecimal('0.0') : balance
end

#funded_by_cod?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/concerns/models/payable.rb', line 31

def funded_by_cod?
  !cod_collection_type.nil? and chosen_shipping_method&.cod?
end

#paymentsActiveRecord::Relation<Payment>

Returns:

  • (ActiveRecord::Relation<Payment>)

See Also:



9
# File 'app/concerns/models/payable.rb', line 9

has_many :payments, dependent: :nullify

#total_payments_authorized(in_currency = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'app/concerns/models/payable.rb', line 12

def total_payments_authorized(in_currency = nil)
  active = payments.where(state: %w[authorized captured])
  active = active.where(currency: in_currency) if in_currency
  active_total = active.sum(:amount) || BigDecimal('0.0')

  voided_scope = payments.where(state: 'voided').includes(:transactions)
  voided_scope = voided_scope.where(currency: in_currency) if in_currency
  voided_captured_total = voided_scope.sum(&:total_captured)

  active_total + voided_captured_total + paypal_over_capture_headroom_for_balance(in_currency)
end