Sha256: f4fc0f43f75ea900ea3769cc43889896a72d48a13894580cfbf705171791bff1

Contents?: true

Size: 674 Bytes

Versions: 30

Compression:

Stored size: 674 Bytes

Contents

module Spree
  module Cart
    class ChangeCurrency
      prepend Spree::ServiceModule::Base

      def call(order:, new_currency:)
        return failure('Currency not supported') unless supported_currency?(order, new_currency)

        result = order.update!(currency: new_currency) rescue false

        if result
          success(order)
        else
          failure('Failed to update order')
        end
      end

      private

      def supported_currency?(order, currency)
        store = order.store
        supported_currencies = store.supported_currencies_list
        supported_currencies.map(&:iso_code).include?(currency.upcase)
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/services/spree/cart/change_currency.rb
spree_core-4.10.0 app/services/spree/cart/change_currency.rb
spree_core-4.9.0 app/services/spree/cart/change_currency.rb
spree_core-4.8.3 app/services/spree/cart/change_currency.rb
spree_core-4.8.2 app/services/spree/cart/change_currency.rb
spree_core-4.7.3 app/services/spree/cart/change_currency.rb
spree_core-4.6.6 app/services/spree/cart/change_currency.rb
spree_core-4.5.5 app/services/spree/cart/change_currency.rb
spree_core-4.3.3 app/services/spree/cart/change_currency.rb
spree_core-4.4.1 app/services/spree/cart/change_currency.rb
spree_core-4.5.4 app/services/spree/cart/change_currency.rb
spree_core-4.6.5 app/services/spree/cart/change_currency.rb
spree_core-4.7.2 app/services/spree/cart/change_currency.rb
spree_core-4.7.1 app/services/spree/cart/change_currency.rb
spree_core-4.6.4 app/services/spree/cart/change_currency.rb
spree_core-4.7.0 app/services/spree/cart/change_currency.rb
spree_core-4.6.3 app/services/spree/cart/change_currency.rb
spree_core-4.6.2 app/services/spree/cart/change_currency.rb
spree_core-4.6.1 app/services/spree/cart/change_currency.rb
spree_core-4.6.0 app/services/spree/cart/change_currency.rb