Sha256: 1619b309fd5c2988b2ef3a74e4faed2d32a02c0522bd879040f9da3458fab7de

Contents?: true

Size: 1.77 KB

Versions: 43

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

module Spree
  class Reimbursement::ReimbursementTypeEngine
    include Spree::Reimbursement::ReimbursementTypeValidator

    class_attribute :refund_time_constraint
    self.refund_time_constraint = 90.days

    class_attribute :default_reimbursement_type
    self.default_reimbursement_type = Spree::ReimbursementType::OriginalPayment

    class_attribute :expired_reimbursement_type
    self.expired_reimbursement_type = Spree::ReimbursementType::StoreCredit

    class_attribute :exchange_reimbursement_type
    self.exchange_reimbursement_type = Spree::ReimbursementType::Exchange

    def initialize(return_items)
      @return_items = return_items
      @reimbursement_type_hash = Hash.new { |h, k| h[k] = [] }
    end

    def calculate_reimbursement_types
      @return_items.each do |return_item|
        reimbursement_type = calculate_reimbursement_type(return_item)
        add_reimbursement_type(return_item, reimbursement_type)
      end

      @reimbursement_type_hash
    end

    private

    def calculate_reimbursement_type(return_item)
      if return_item.exchange_required?
        exchange_reimbursement_type
      elsif return_item.override_reimbursement_type.present?
        return_item.override_reimbursement_type.class
      elsif return_item.preferred_reimbursement_type.present?
        if valid_preferred_reimbursement_type?(return_item)
          return_item.preferred_reimbursement_type.class
        end
      elsif past_reimbursable_time_period?(return_item)
        expired_reimbursement_type
      else
        default_reimbursement_type
      end
    end

    def add_reimbursement_type(return_item, reimbursement_type)
      return unless reimbursement_type
      @reimbursement_type_hash[reimbursement_type] << return_item
    end
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
solidus_core-2.8.1 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core-2.6.3 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core-2.8.0 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core-2.7.1 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core-2.6.2 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.10 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.9 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.8 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.7 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.6 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.5 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.4 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.3 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.1 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core_devise_token_auth-2.8.0.alpha.0 app/models/spree/reimbursement/reimbursement_type_engine.rb
solidus_core-2.7.0 app/models/spree/reimbursement/reimbursement_type_engine.rb