Module: Spree::ReimbursementType::ReimbursementHelpers

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#eligible_refund_methodsObject

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



7
8
9
# File 'core/app/models/spree/reimbursement_type/reimbursement_helpers.rb', line 7

def eligible_refund_methods
  @eligible_refund_methods
end

Instance Method Details

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



23
24
25
26
27
28
29
# File 'core/app/models/spree/reimbursement_type/reimbursement_helpers.rb', line 23

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

  [reimbursement_list, unpaid_amount]
end

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



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

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