I'm trying to make refunds using ActiveMerchant gem. After reading the API, I use the refund method like this:
response = PaymentGateway.refund(nil,transaction_id)
, where transaction_id is my 17 characters transaction ID. When I execute this code, I've got this error in my logs:
Refund error: transaction 90C30922TK2262948, booking 5569, response= #
<ActiveMerchant::Billing::PaypalExpressResponse:0x00000110a4c048 @params=
{"timestamp"=>"2013-12-28T11:58:46Z", "ack"=>"Failure",
"correlation_id"=>"17b440dc61a09", "version"=>"72", "build"=>"8951431",
"refund_transaction_id"=>nil, "message"=>"The transaction id is not valid",
"error_codes"=>"10004", "Timestamp"=>"2013-12-28T11:58:46Z", "Ack"=>"Failure",
"CorrelationID"=>"17b440dc61a09", "Errors"=>{"ShortMessage"=>"Transaction refused
because of an invalid argument. See additional error messages for details.",
"LongMessage"=>"The transaction id is not valid", "ErrorCode"=>"10004",
"SeverityCode"=>"Error"}, "Version"=>"72", "Build"=>"8951431",
"RefundTransactionID"=>nil}
The id parameter doesn't seem to be accepted by the Paypal API. I'm using the transfer method, but I'd rather use the refund one.
Take a look at this paypal_api
This is what your refund should look like
# Refunds a transaction.
#
# For a full refund pass nil for the amount:
#
# gateway.refund nil, 'G39883289DH238'
#
# This will automatically make the :refund_type be "Full".
#
# For a partial refund just pass the amount as usual:
#
# gateway.refund 100, 'UBU83983N920'
#
def refund(money, identification, options = {})
commit 'RefundTransaction', build_refund_request(money, identification, options)
end