Module: Spree::ReimbursementType::ReimbursementHelpers

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

Instance Method Summary collapse

Instance Method Details

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


16
17
18
19
20
21
22
# File 'app/models/spree/reimbursement_type/reimbursement_helpers.rb', line 16

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


3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/models/spree/reimbursement_type/reimbursement_helpers.rb', line 3

def create_refunds(reimbursement, payments, unpaid_amount, simulate, reimbursement_list = [])
  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