Module: Spree::ReimbursementType::ReimbursementHelpers Private

Included in:
Credit, OriginalPayment, StoreCredit
Defined in:
app/models/spree/reimbursement_type/reimbursement_helpers.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#eligible_refund_methodsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Ordered list of payment methods that are valid for the reimbursement type to use for reimbursing. Leaving this nil allows anything.



5
6
7
# File 'app/models/spree/reimbursement_type/reimbursement_helpers.rb', line 5

def eligible_refund_methods
  @eligible_refund_methods
end

Instance Method Details

#create_credits(reimbursement, unpaid_amount, simulate, reimbursement_list = []) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
# File 'app/models/spree/reimbursement_type/reimbursement_helpers.rb', line 21

def create_credits(reimbursement, unpaid_amount, simulate, reimbursement_list = [])
  credits = [create_credit(reimbursement, unpaid_amount, simulate)]
  unpaid_amount -= credits.sum(&:amount)
  reimbursement_list += credits

  [reimbursement_list, unpaid_amount]
end

#create_refunds(reimbursement, payments, unpaid_amount, simulate, reimbursement_list = []) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/spree/reimbursement_type/reimbursement_helpers.rb', line 7

def create_refunds(reimbursement, payments, unpaid_amount, simulate, reimbursement_list = [])
  payments = sorted_eligible_refund_payments(payments)
  payments.map do |payment|
    break if unpaid_amount <= 0
    next unless payment.can_credit?

    amount = [unpaid_amount, payment.credit_allowed].min
    reimbursement_list << create_refund(reimbursement, payment, amount, simulate)
    unpaid_amount -= amount
  end

  [reimbursement_list, unpaid_amount]
end