Sha256: 7721234c2e5975ba02fe9d98900f6313a7c166feaf9205eb6a3ce4d0cbad6b4d

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true
module Workarea
  decorate Payment::Purchase::CreditCard, with: :cim do
    def complete!
      return unless Workarea::Payment::StoreCreditCard.new(tender, options).save!

      transaction.response = handle_active_merchant_errors do
        gateway.create_customer_profile_transaction(auth_capture_args)
      end
    end

    def cancel!
      return unless transaction.success?

      transaction.cancellation = handle_active_merchant_errors do
        gateway.create_customer_profile_transaction(void_args)
      end
    end

    private

    def auth_capture_args
      {
        transaction: {
          type: :auth_capture,
          customer_profile_id: customer_profile_id,
          customer_payment_profile_id: customer_payment_profile_id,
          amount: auth_amount,
          order: {
            invoice_number: tender.payment.id.first(20) # auth net has max length 20 for this field
          }
        }
      }
    end

    def void_args
      {
        transaction: {
          type: :void,
          customer_profile_id: customer_profile_id,
          customer_payment_profile_id: customer_payment_profile_id,
          trans_id: transaction.response.authorization
        }
      }
    end

    def customer_profile_id
      tender.gateway_profile_id
    end

    def customer_payment_profile_id
      tender.token
    end

    # cim requeires dollar amount (not cents)
    # eg $4.25
    def auth_amount
      tender.amount.to_s.to_f
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-authorize_cim-2.1.1 app/models/workarea/payment/purchase/credit_card.decorator