cancel
Showing results for 
Search instead for 
Did you mean: 

Can someone please provide a sample code for REFUND transaction using CIM api?

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.

mps_sudipta
Contributor
5 REPLIES 5

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.

TJPride
Expert

The documentation and code examples seem less than helpful when it comes to credits.

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?

Usually, people just attempt a void, and if that fails, attempt a refund.

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.