- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I just started integrating AuthNet using the AIM method.
To start, I copied this script from the samples. Note: I removed the actual login ID and transaction key I am testing with.
What is confusing me is I have just looked up the login credentials and subsituted them in the script. However, I still get error 13. My question is, why would I get this error if the credentials are correct? The account is alive currently and
transactions are being run successfully through the Auth.NET virtual terminal.
Any insight appreciated.
Thank you.
<html>
<head>
<title>Sam Moreland @Grapevine</title>
</head>
<body>
<?php
require_once 'anet_php_sdk/AuthorizeNet.php'; // Make sure this path is correct.
$transaction = new AuthorizeNetCP('REMOVED FOR', 'PRIVACY');
$transaction->amount = '9.99';
$transaction->setTrack1Data('%B4111111111111111^CARDUSER/JOHN^1803101000000000020000831000000?');
$transaction->device_type = '4';
$response = $transaction->authorizeAndCapture();
if ($response->approved) {
echo "<h1>Success! The test credit card has been charged!</h1>";
echo "Transaction ID: " . $response->transaction_id;
} else {
echo "this is what is happening" . $response->error_message;
}
?>
</body>
</html>
Solved! Go to Solution.
02-28-2012 07:47 AM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can look up the ID, but there's always a possibility you have the wrong key. More likely, however, is that you're trying to submit a test transaction using your production account credentials. If you look at the text above the sample code, it specifically mentions putting in your test account login. Try adding this, see if it makes a difference:
$transaction = new AuthorizeNetCP('REMOVED FOR', 'PRIVACY');
// Add this:
$transaction->setSandbox(false);
I ran into this problem myself once.

02-28-2012 08:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can look up the ID, but there's always a possibility you have the wrong key. More likely, however, is that you're trying to submit a test transaction using your production account credentials. If you look at the text above the sample code, it specifically mentions putting in your test account login. Try adding this, see if it makes a difference:
$transaction = new AuthorizeNetCP('REMOVED FOR', 'PRIVACY');
// Add this:
$transaction->setSandbox(false);
I ran into this problem myself once.

02-28-2012 08:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. Adding this code almost fixes things.
I am now able to post a transaction but there is still something odd going on with this script.
$transaction->setSandbox(false);
Specifically, the chunk of code below is not being exectued correctly and I don't know why? That is to say, I can run the script and the transaction is now posted. I verified that. But, I'm not getting any response code back to display to the
end user. The expected result is that I run the script and then depending on the response code I should see either
a.)Success! The test credit card has been charged
b.) The reason code for failure
I see none of those which makes me think there may be something up with the response variable?
Any insight appreciated.
if ($response->approved) {
echo "<h1>Success! The test credit card has been charged!</h1>";
echo "Transaction ID: " . $response->transaction_id;
} else {
echo $response->error_message;
}
02-28-2012 09:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Instead of that block of code, try doing print_r($response); That'll give you a dump of the whole response, assuming there is anything. If there isn't, that tells you something as well.
02-28-2012 09:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Okay, I added the suggested line of code and got back what appears to be a populated response variable. However,
I still don't understand why this block of code is not displaying anything? Or more importantly, how to get at the
response object so I can give feedback to the end-user?
if ($response->approved) {
echo "<h1>Success! The test credit card has been charged!</h1>";
echo "Transaction ID: " . $response->transaction_id;
} else {
echo $response->error_message;
}
Any insight appreciated.
@TJPride wrote:Instead of that block of code, try doing print_r($response); That'll give you a dump of the whole response, assuming there is anything. If there isn't, that tells you something as well.
AuthorizeNetCP_Response Object ( [_response_array:private] => Array ( [0] => 1.0 [1] => 2 [2] => 37 [3] => The credit card number is invalid. [4] => [5] => B [6] => [7] => 4207308167 [8] => 969125A827D0ADCD7F02422677BD88EA [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => [18] => [19] => [20] => XXXX1111 [21] => Visa ) [approved] => [declined] => 1 [error] => [held] => [response_code] => 2 [response_subcode] => [response_reason_code] => 37 [response_reason_text] => The credit card number is invalid. [authorization_code] => [avs_response] => [transaction_id] => 4207308167 [invoice_number] => [description] => [amount] => [method] => [transaction_type] => [customer_id] => [first_name] => [last_name] => [company] => [address] => [city] => [state] => [zip_code] => [country] => [phone] => [fax] => [email_address] => [ship_to_first_name] => [ship_to_last_name] => [ship_to_company] => [ship_to_address] => [ship_to_city] => [ship_to_state] => [ship_to_zip_code] => [ship_to_country] => [tax] => [duty] => [freight] => [tax_exempt] => [purchase_order_number] => [md5_hash] => 969125A827D0ADCD7F02422677BD88EA [card_code_response] => [cavv_response] => [account_number] => [card_type] => Visa [split_tender_id] => [requested_amount] => [balance_on_card] => [response] => |1.0|,|2|,|37|,|The credit card number is invalid.|,||,|B|,||,|4207308167|,|969125A827D0ADCD7F02422677BD88EA|,||,||,||,||,||,||,||,||,||,||,||,|XXXX1111|,|Visa| [version] => 1.0 [avs_code] => B [user_ref] => [card_num] => XXXX1111 [approved_amount] => [card_balance] => )
02-28-2012 10:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There was no error per se - the code ran properly. However, it did generate code 2-37, which is "The credit card number is invalid." Change it to output $response->response_reason_text if the transaction is not approved.
02-28-2012 10:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
All fixed. Thanks for the suggestion on explicitly setting the test flag to false.
Also, I had these issues which I realized were PHP errors.
a.) action="anet_php_sdk/AuthorizeNet.php'"
In the HTML form code I noticed there was a single quote at the end of the filename.
b.) The other problem was, I needed to put the PHP code in a seperate file from the HTML code
Seems to be working now.
I appreciate the time and insight.
02-28-2012 12:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, you don't need to separate PHP and HTML. You can have a PHP file that looks like this:
<?php // My PHP code is here
print <<<BLOCK <!-- My HTML is here -->
BLOCK; ?>
You can print object or associative array values by surrounding them with {}, like {$array['key']}
02-28-2012 12:21 PM
