Sha256: d1f25032cccb8ecf1120784bce4e2f060860b1668ae22a8e25edbf765e386e8b

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Workarea
  class Payment
    class Refund
      class Affirm
        include OperationImplementation
        include CreditCardOperation

        def complete!
          response = gateway.refund(charge_id, transaction.amount)

          transaction.response = if response.success?
           ActiveMerchant::Billing::Response.new(
             true,
             I18n.t(
               'workarea.affirm.refund',
               amount: transaction.amount
             ),
             response.body
           )
          else
           ActiveMerchant::Billing::Response.new(
             false,
             I18n.t('workarea.affirm.refund_failure'),
             response.body
           )
          end
        end

        def cancel!
          # No op - no cancel functionality available.
        end

        private

        def charge_id
          tran = tender.transactions.detect { |t| t.success? & %w[authorize purchase].include?(t.action) }
          tran.response.params['id']
        end

        def gateway
          Workarea::Affirm.gateway
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-affirm-1.0.0 app/models/workarea/payment/refund/affirm.rb