Sha256: 1165d387a097f99917881babc6b10beba01027dfb747c64a37f855ae48a2bae7

Contents?: true

Size: 1.03 KB

Versions: 18

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module SolidusNexio
  module NexioPaymentCommons
    def purchase(money, source, options = {})
      super(money, source, add_transaction_options(source, options))
    end

    def authorize(money, source, options = {})
      super(money, source, add_transaction_options(source, options))
    end

    def cancel(id)
      transaction = gateway.get_transaction(id)
      return unless transaction

      if Mappings.settled?(transaction.status)
        credit(transaction.amount.to_money.cents, id)
      else
        void(id)
      end
    end

    private

    def add_transaction_options(source, options)
      result = %i[currency billing_address].each_with_object({}) do |key, acc|
        acc[key] = options[key] if options[key].present?
      end
      result[:address] = options[:shipping_address] if options[:shipping_address].present?
      if options[:originator].respond_to?(:order)
        result.merge!(SolidusNexio::NexioData.purchase(options[:originator].order))
      end
      result
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
solidus_nexio-0.7.8 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.7.7 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.7.6 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.7.5 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.7.4 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.7.3 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.7.1 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.7.0 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.9 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.8 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.7 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.6 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.5 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.4 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.3 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.2 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.1 app/models/solidus_nexio/nexio_payment_commons.rb
solidus_nexio-0.6.0 app/models/solidus_nexio/nexio_payment_commons.rb