Sha256: 69dea211647b0c2b50e8837482bfe459fd8db4bc110e64fb8279ff634e74683f

Contents?: true

Size: 799 Bytes

Versions: 34

Compression:

Stored size: 799 Bytes

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
        Workarea.config.auto_capture ? 'purchase!' : 'authorize!'
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.25 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.24 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.23 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.22 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.21 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.20 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.19 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.18 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.17 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.16 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.15 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.14 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.13 app/models/workarea/checkout/collect_payment.rb
workarea-core-3.4.12 app/models/workarea/checkout/collect_payment.rb