Sha256: 85d7e78ebaa8e2b1301a58348889a02de8b06d35b57f084c288ca7b6ad7bb3f3

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true
module Workarea
  decorate Payment::Refund::CreditCard, with: :cim do
    def complete!
      return false unless tender.valid_capture_date?

      validate_reference!

      transaction.response = handle_active_merchant_errors do
        gateway.create_customer_profile_transaction_for_refund(options)
      end
    end

    private

    def options
      {
        transaction: {
          customer_profile_id: customer_profile_id,
          customer_payment_profile_id: customer_payment_profile_id,
          amount: refund_amount,
          trans_id: transaction.reference.response.params['direct_response']['transaction_id'],
          order: {
            invoice_number: tender.payment.id.first(20) # auth net has max length 20 for this field
          }
        }
      }
    end

    def refund_amount
      transaction.amount.to_s.to_f
    end

    def customer_profile_id
      tender.gateway_profile_id
    end

    def customer_payment_profile_id
      tender.token
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-authorize_cim-2.1.3 app/models/workarea/payment/refund/credit_card.decorator