Sha256: 8eca615d120cf0f8e3488bc82c6f1f1989067358422eb0a99674ac2068d3d5eb

Contents?: true

Size: 1.42 KB

Versions: 27

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

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

27 entries across 27 versions & 2 rubygems

Version Path
solidus_core-2.6.6 app/models/spree/reimbursement_performer.rb
solidus_core-2.7.4 app/models/spree/reimbursement_performer.rb
solidus_core-2.7.3 app/models/spree/reimbursement_performer.rb
solidus_core-2.6.5 app/models/spree/reimbursement_performer.rb
solidus_core-2.7.2 app/models/spree/reimbursement_performer.rb
solidus_core-2.6.4 app/models/spree/reimbursement_performer.rb
solidus_core-2.6.3 app/models/spree/reimbursement_performer.rb
solidus_core-2.7.1 app/models/spree/reimbursement_performer.rb
solidus_core-2.6.2 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.10 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.9 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.8 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.7 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.6 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.5 app/models/spree/reimbursement_performer.rb
solidus_core_devise_token_auth-2.8.0.alpha.4 app/models/spree/reimbursement_performer.rb