Sha256: ba086e1f1023c449fb4a0fa18947b781f4a9b395f0b7e25415cd0022535be03b

Contents?: true

Size: 972 Bytes

Versions: 43

Compression:

Stored size: 972 Bytes

Contents

class Spree::ReimbursementType::StoreCredit < Spree::ReimbursementType
  extend Spree::ReimbursementType::ReimbursementHelpers

  class << self
    def reimburse(reimbursement, return_items, simulate)
      unpaid_amount = return_items.sum(&:total).to_d.round(2, :down)
      payments = store_credit_payments(reimbursement)
      reimbursement_list = []

      # Credit each store credit that was used on the order
      reimbursement_list, unpaid_amount = create_refunds(reimbursement, payments, unpaid_amount, simulate, reimbursement_list)

      # If there is any amount left to pay out to the customer, then create credit with that amount
      if unpaid_amount > 0.0
        reimbursement_list, _unpaid_amount = create_credits(reimbursement, unpaid_amount, simulate, reimbursement_list)
      end

      reimbursement_list
    end

    private

    def store_credit_payments(reimbursement)
      reimbursement.order.payments.completed.store_credits
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
solidus_core-2.5.2 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.5.1 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.5.0 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.5.0.rc1 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.5.0.beta2 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.5.0.beta1 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.4.2 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.3.1 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.4.1 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.2.2 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.1.1 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.0.3 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-1.4.2 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-1.3.2 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.4.0 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.4.0.rc1 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.4.0.beta1 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.3.0 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.3.0.rc3 app/models/spree/reimbursement_type/store_credit.rb
solidus_core-2.3.0.rc2 app/models/spree/reimbursement_type/store_credit.rb