Sha256: ff7c12a88ed1047bf093d1e0d6e7ff77eb807ec6a590a19a29f46317ecf4e28e

Contents?: true

Size: 1.56 KB

Versions: 81

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Spree
  class Order < Spree::Base
    module Payments
      # processes any pending payments and must return a boolean as it's
      # return value is used by the checkout state_machine to determine
      # success or failure of the 'complete' event for the order
      #
      # Returns:
      #
      # - true if all pending payments processed successfully
      #
      # - true if a payment failed, ie. raised a GatewayError
      #   which gets rescued and converted to TRUE when
      #   :allow_checkout_gateway_error is set to true
      #
      # - false if a payment failed, ie. raised a GatewayError
      #   which gets rescued and converted to FALSE when
      #   :allow_checkout_on_gateway_error is set to false
      #
      def process_payments!
        process_payments_with(:process!)
      end

      def authorize_payments!
        process_payments_with(:authorize!)
      end

      def capture_payments!
        process_payments_with(:purchase!)
      end

      def unprocessed_payments
        payments.select(&:checkout?)
      end

      private

      def process_payments_with(method_name)
        # Don't run if there is nothing to pay.
        return true if payment_total >= total

        unprocessed_payments.each do |payment|
          break if payment_total >= total

          payment.public_send(method_name)
        end
      rescue Core::GatewayError => error
        result = !!Spree::Config[:allow_checkout_on_gateway_error]
        errors.add(:base, error.message) && (return result)
      end
    end
  end
end

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
solidus_core-4.4.2 app/models/spree/order/payments.rb
solidus_core-4.4.1 app/models/spree/order/payments.rb
solidus_core-4.4.0 app/models/spree/order/payments.rb
solidus_core-4.3.4 app/models/spree/order/payments.rb
solidus_core-4.2.4 app/models/spree/order/payments.rb
solidus_core-4.1.5 app/models/spree/order/payments.rb
solidus_core-4.3.3 app/models/spree/order/payments.rb
solidus_core-4.3.2 app/models/spree/order/payments.rb
solidus_core-4.1.4 app/models/spree/order/payments.rb
solidus_core-4.3.1 app/models/spree/order/payments.rb
solidus_core-4.3.0 app/models/spree/order/payments.rb
solidus_core-4.2.3 app/models/spree/order/payments.rb
solidus_core-4.1.3 app/models/spree/order/payments.rb
solidus_core-4.0.4 app/models/spree/order/payments.rb
solidus_core-3.4.6 app/models/spree/order/payments.rb
solidus_core-4.0.3 app/models/spree/order/payments.rb
solidus_core-4.1.2 app/models/spree/order/payments.rb
solidus_core-4.2.2 app/models/spree/order/payments.rb
solidus_core-3.4.5 app/models/spree/order/payments.rb
solidus_core-4.2.1 app/models/spree/order/payments.rb