Sha256: e5da95195c9472ac4fb1b8579535773fedbc16dd6de95ba7da868c91d153c69a

Contents?: true

Size: 1.02 KB

Versions: 62

Compression:

Stored size: 1.02 KB

Contents

module Workarea
  class Payment
    class Operation
      attr_reader :transactions, :errors

      def initialize(transactions, options = {})
        @transactions = transactions
        @options = options
        @errors = []
      end

      def success?
        errors.empty?
      end

      def complete!
        begin
          complete_each_transaction!
        rescue Exception => e
          rollback!
          raise e
        ensure
          add_transaction_errors
        end
      end

      def rollback!
        transactions
          .select(&:success?)
          .reject(&:canceled?)
          .each { |t| t.cancel!(@options) }
      end

      private

      def complete_each_transaction!
        transactions.each do |transaction|
          transaction.complete!(@options)
          rollback! and break if transaction.failure?
        end
      end

      def add_transaction_errors
        transactions.select(&:failure?).each do |transaction|
          errors << transaction.message
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/payment/operation.rb
workarea-core-3.5.26 app/models/workarea/payment/operation.rb
workarea-core-3.4.45 app/models/workarea/payment/operation.rb
workarea-core-3.5.25 app/models/workarea/payment/operation.rb
workarea-core-3.5.23 app/models/workarea/payment/operation.rb
workarea-core-3.4.44 app/models/workarea/payment/operation.rb
workarea-core-3.5.22 app/models/workarea/payment/operation.rb
workarea-core-3.4.43 app/models/workarea/payment/operation.rb
workarea-core-3.5.21 app/models/workarea/payment/operation.rb
workarea-core-3.4.42 app/models/workarea/payment/operation.rb
workarea-core-3.5.20 app/models/workarea/payment/operation.rb
workarea-core-3.4.41 app/models/workarea/payment/operation.rb
workarea-core-3.5.19 app/models/workarea/payment/operation.rb
workarea-core-3.4.40 app/models/workarea/payment/operation.rb
workarea-core-3.5.18 app/models/workarea/payment/operation.rb
workarea-core-3.4.39 app/models/workarea/payment/operation.rb
workarea-core-3.5.17 app/models/workarea/payment/operation.rb
workarea-core-3.4.38 app/models/workarea/payment/operation.rb
workarea-core-3.5.16 app/models/workarea/payment/operation.rb
workarea-core-3.4.37 app/models/workarea/payment/operation.rb