Refund payments using Authorize.net AIM API

3.4k views Asked by At

I am trying to find a way to refund payments using Authorize.net's AIM API. I found sample code located here: https://github.com/stymiee/Authorize.Net-XML. Here is the code that I am using from the sample:

require('../../config.inc.php');
require('../../AuthnetXML.class.php');

$xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER);
$xml->createTransactionRequest(array(
    'refId' => rand(1000000, 100000000),
    'transactionRequest' => array(
        'transactionType' => 'refundTransaction',
        'amount' => 5,
        'payment' => array(
            'creditCard' => array(
                'cardNumber' => 'XXXX1111',
                'expirationDate' => '122016'
            )
        ),
        'authCode' => '2165668159'
    ),
));

I keep getting an error message saying that the card code is missing. Any thoughts on what is missing to allow a refund to go through?

NEW CODE:

 $xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY);
 $xml->createTransactionRequest(array(
    'refId' => rand(1000000, 100000000),
    'transactionRequest' => array(
        'transactionType' => 'refundTransaction',
        'amount' => 1.00,
        'payment' => array(
            'creditCard' => array(
                'cardNumber' => 'XXXX1014',
                'expirationDate' => '122025',
            )
        ),
        'refTransId' => '4928163616',
    ),
));
1

There are 1 answers

13
John Conde On BEST ANSWER
$xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY);
$xml->createTransactionRequest(array(
    'refId' => rand(1000000, 100000000),
    'transactionRequest' => array(
        'transactionType' => 'refundTransaction',
        'amount' => 1.00,
        'payment' => array(
            'creditCard' => array(
                'cardNumber' => 'XXXX1014',
                'expirationDate' => '122025',
            )
        ),
        'refTransId' => '4928163616',
        'transactionSettings' => array(
            'setting' => array(
                0 => array(
                    'settingName' => 'emailCustomer',
                    'settingValue' => 'true'
                ),
            )
        ),
    ),
));