Posts: 12
Registered: ‎11-16-2011

CIM API (php) for refunding entire or partial transactions

I just started looking into the official PHP API code for the CIM module in order to allow my back-office software to be able to do refunds, but in the API docs, at least in the markup sample code, they do not show the structure for performing refunds, whether complete refunds for a transaction or alternatively a partial refund of a transaction.  In my case I would know the transaction # and customer ID, but I would prefer not to have to query ANet to get the customer's last 4 card digits.


First off, why would the CIM API library show refunds as a possible transaction type and then not even bother to include some sample code so that I do not have to sort through the CIM XML docs to try to figure out how to structure the call? It shows the very simple Void code, but someone seems to have gotten lazy on the sample code.


Does anyone have refund code in php that uses the official PHP API library?  Both partial and full refunds would be needed for my purposes (as for many merchants i suspect).


This must have been done a million times, I would prefer to be able to use the API library without having to worry about its guts.


Thanks, folks.

Ben Cahan

Posts: 591
Registered: ‎08-21-2009

Re: CIM API (php) for refunding entire or partial transactions

Hi Ben,


The only unique field required for a (standard) refund is the original transaction ID. Here is an example of a basic refund request through CIM with the PHP SDK:

	$transaction = new AuthorizeNetTransaction;
	$transaction->amount = "9.79";
	$transaction->customerProfileId = $customerProfileId;
	$transaction->customerPaymentProfileId = $paymentProfileId;
	$transaction->transId = $transId; // original transaction ID

	$response = $request->createCustomerProfileTransaction("Refund", $transaction);
	$transactionResponse = $response->getTransactionResponse();

$transactionId = $transactionResponse->transaction_id; ?>


As for a partial or full refund, the only  thing that changes is the value of the amount.