Sha256: a424593d079222f33ccb1d3863b6fcdd5e43c648d40e2772dc1ca0b269b94393

Contents?: true

Size: 1.39 KB

Versions: 100

Compression:

Stored size: 1.39 KB

Contents

module Spree

  class ReimbursementPerformer

    class << self
      class_attribute :reimbursement_type_engine
      self.reimbursement_type_engine = Spree::Reimbursement::ReimbursementTypeEngine

      # Simulate performing the reimbursement without actually saving anything or refunding money, etc.
      # This must return an array of objects that respond to the following methods:
      # - #description
      # - #display_amount
      # so they can be displayed in the Admin UI appropriately.
      def simulate(reimbursement)
        execute(reimbursement, true)
      end

      # Actually perform the reimbursement
      def perform(reimbursement)
        execute(reimbursement, false)
      end

      private

      def execute(reimbursement, simulate)
        reimbursement_type_hash = calculate_reimbursement_types(reimbursement)

        reimbursement_type_hash.flat_map do |reimbursement_type, return_items|
          reimbursement_type.reimburse(reimbursement, return_items, simulate)
        end
      end

      def calculate_reimbursement_types(reimbursement)
        # Engine returns hash of preferred reimbursement types pointing at return items
        # {Spree::ReimbursementType::OriginalPayment => [ReturnItem, ...], Spree::ReimbursementType::Exchange => [ReturnItem, ...]}
        reimbursement_type_engine.new(reimbursement.return_items).calculate_reimbursement_types
      end

    end

  end

end

Version data entries

100 entries across 100 versions & 2 rubygems

Version Path
spree_core-3.0.10 app/models/spree/reimbursement_performer.rb
spree_core-3.1.1 app/models/spree/reimbursement_performer.rb
spree_core-3.1.0 app/models/spree/reimbursement_performer.rb
spree_core-3.1.0.rc4 app/models/spree/reimbursement_performer.rb
spree_core-3.0.9 app/models/spree/reimbursement_performer.rb
spree_core-3.1.0.rc3 app/models/spree/reimbursement_performer.rb
spree_core-3.1.0.rc2 app/models/spree/reimbursement_performer.rb
spree_core-3.1.0.rc1 app/models/spree/reimbursement_performer.rb
solidus_core-1.0.6 app/models/spree/reimbursement_performer.rb
spree_core-3.0.8 app/models/spree/reimbursement_performer.rb
solidus_core-1.2.2 app/models/spree/reimbursement_performer.rb
spree_core-3.0.7 app/models/spree/reimbursement_performer.rb
solidus_core-1.2.1 app/models/spree/reimbursement_performer.rb
solidus_core-1.1.3 app/models/spree/reimbursement_performer.rb
solidus_core-1.0.5 app/models/spree/reimbursement_performer.rb
spree_core-3.0.6.1 app/models/spree/reimbursement_performer.rb
spree_core-3.0.6 app/models/spree/reimbursement_performer.rb
spree_core-3.0.5 app/models/spree/reimbursement_performer.rb
solidus_core-1.2.0 app/models/spree/reimbursement_performer.rb
solidus_core-1.2.0.rc2 app/models/spree/reimbursement_performer.rb