I am using and anet_php_sdk, and CIM and I got the basic transactions working. But I can't figure out how to do a refund transaction using this sdk. Can someone please provide me a sample code? Just assume I already have the customer id, payment profile id, and transaction id in three variables.
08-22-2011 09:20 PM
A void (canceling an unsettled transaction) can be done as follows:
$request = new AuthorizeNetCIM;
$transaction = new AuthorizeNetTransaction; $transaction->transID = $transactionID; $response = $request->createCustomerProfileTransaction('Void', $transaction);
You have to issue a credit if the transaction is already settled.
08-23-2011 07:31 PM
The documentation and code examples seem less than helpful when it comes to credits.
08-23-2011 08:06 PM
Thank you for that code.
But I do not need to simply void a transaction... I need to "refund" it, after it is settled. Any tips?
Also, is it possible to check the settlement status with the help of the API, so that I can create the transaction type properly?
08-23-2011 09:05 PM
Usually, people just attempt a void, and if that fails, attempt a refund.
08-24-2011 04:50 AM
Maybe something like this (untested)?
$request = new AuthorizeNetCIM($authorizeID, $authorizeKey); $transaction = new AuthorizeNetTransaction; $transaction->customerProfileId = $customerProfileId; $transaction->customerPaymentProfileId = $paymentProfileId; $transaction->transID = $idOfTransactionToCredit; $transaction->creditCardNumberMasked = $cardNumberMasked; /* Can be retrieved using getCustomerProfile? */ $transaction->amount = $originalAmount; $response = $request->createCustomerProfileTransaction('Credit', $transaction);
From the docs:
Credit
This transaction type is used to refund a customer for a transaction that was originally processed and successfully settled through the payment gateway.
The payment gateway accepts Credits if the following conditions are met:
The transaction is submitted with the valid Transaction ID of an original, successfully settled transaction.
The amount being requested for refund is less than or equal to the original settled amount.
The sum amount of multiple Credit transactions submitted against the original transaction is less than or equal to the original settled amount.
At least the last four digits of the credit card number used for the original, successfully settled transaction are submitted. An expiration date is not required.
The transaction is submitted within 120 days of the settlement date of the original transaction.
08-24-2011 05:14 AM