Reply
Highlighted
Contributor
Posts: 10
Registered: ‎08-03-2011

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.

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

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

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.

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

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

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

Highlighted
Contributor
Posts: 10
Registered: ‎08-03-2011

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

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?

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

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

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

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

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

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.