1

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',
    ),
));
John Conde
  • 217,595
  • 99
  • 455
  • 496
three3
  • 2,756
  • 14
  • 57
  • 85

1 Answers1

0
$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'
                ),
            )
        ),
    ),
));
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Thanks for your reply. I do not have the Card Code or Expiration date stored on file. I thought to refund a payment, all that was needed was the Transaction ID, Amount, and Last 4 of the card number. Am I missing something? – three3 Jan 30 '13 at 02:48
  • I just played around with the code and it looks like the card code isn't required but the expiration date is. You may also get an error if you don't run a auth_capture transaction before it. I'm going to try that now and see what happens. – John Conde Jan 30 '13 at 02:55
  • @JohnConde Here is a screenshot of the Authorize.net documentation. http://i.imgur.com/KWrC4LX.png It says that only the Transaction ID, Amount, and Last 4 of the card number are needed. Is there a way to do this without the expiration date? – three3 Jan 30 '13 at 02:56
  • Right now I'm getting errors for everything. I wonder if they're having issues with their dev server? – John Conde Jan 30 '13 at 02:56
  • @JohnConde I just used the dev server to do a test "Void" transaction and it worked for me. – three3 Jan 30 '13 at 03:02
  • Weird. I get errors for all transactions and all APIs. And I've been using this code for years. Must be an issue on my end somewhere. – John Conde Jan 30 '13 at 03:08
  • But you're right that all you should need is the Transaction ID, Amount, and Last 4 of the card number. Your code as it is should work. – John Conde Jan 30 '13 at 03:09
  • @JohnConde I just updated my original post with new code at the bottom of the post. This worked for me. The expiration date I used is "fake" but I checked Authorize.net and it was approved. Is there a way to send the refund email like you can in the Merchant Interface? – three3 Jan 30 '13 at 03:12
  • Yes, I updated my answer to reflect your changes and show this setting. – John Conde Jan 30 '13 at 03:15
  • @JohnConde I got an error: The element 'createTransactionRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'transactionSettings' in namespace – three3 Jan 30 '13 at 03:19
  • @JohnConde Awesome! Thank you so much for the help. Everything is working now! – three3 Jan 30 '13 at 03:25
  • That's what I like to hear! – John Conde Jan 30 '13 at 03:28
  • @John Conde i have problem in authorized.net refund. how can i do it friend. please help me – Padmanathan J Dec 05 '13 at 07:33