Sha256: 9a36321dbb8afd7a3be0091d433501965263de949e1b926fc828ea1e5a712c79

Contents?: true

Size: 1.11 KB

Versions: 27

Compression:

Stored size: 1.11 KB

Contents

module Workarea
  class Checkout
    class CollectPayment
      delegate :payment, to: :@checkout

      def initialize(checkout)
        @checkout = checkout
        @order = checkout.order
      end

      def valid?
        if balance > 0
          payment.errors.add(
            :base,
            I18n.t('workarea.payment.insufficient_payment', balance: balance)
          )

          return false
        end

        true
      end

      def balance
        @order.total_price - payment.tendered_amount
      end

      def purchase
        return true if @order.total_price.zero?
        return false unless valid?

        payment.send(action, checkout: @checkout)
      end

      def action
        # TODO deprecated, remove in v3.6
        return 'purchase!' if Workarea.config.auto_capture

        if @order.items.all?(&:shipping?)
          Workarea.config.checkout_payment_action[:shipping]
        elsif @order.items.any?(&:shipping?)
          Workarea.config.checkout_payment_action[:partial_shipping]
        else
          Workarea.config.checkout_payment_action[:no_shipping]
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.26 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.25 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.23 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.22 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.21 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.20 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.19 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.18 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.17 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.16 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.15 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.14 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.13 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.12 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.11 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.10 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.9 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.8 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.5.7 app/models/workarea/checkout/collect_payment.rb