I've taken over a website project. Somebody dropped the ball, so I have to try and finish this. Their current site is still active, and I'm trying to get the test "buy coffee" site to work on a separate i.p. location, where we'll point the name when we're done. But I can't get the test account to work. I tried customer service over the phone and through live chat. They only sent me here to the forum.
The API is AIM. The API login and authorization key are most definitely correct. I looked in the AuthorizeNetAIM.php and set this:
const LIVE_URL = 'https://secure.authorize.net/gateway/transact.dll';
const SANDBOX_URL = 'https://secure.authorize.net/gateway/transact.dll';
(also tried: const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; and still doesn't work)
I've tried with test acount info. I've set a new Authorization key. Still doesn't work.
In the config file, I tried both:
define("AUTHORIZENET_SANDBOX",FALSE);
and
define("AUTHORIZENET_SANDBOX",TRUE);
No matter what, the error is always the same:
response code 3, response reason code 13.
If you care to see, the files are right here: http://216.38.52.184/samples/your_store/
02-28-2012 09:00 AM
Well, assuming you are in fact using a valid login ID and transaction key (a space, missing character, etc. could screw it up, so could using an old key, etc.), then the problem must be that you aren't submitting to the correct URL. The sandbox URL should be https://test.authorize.net/gateway/transact.dll , and sandbox needs to be set to TRUE - which you did, but it may be getting overwritten at the transaction level. Check the transaction code, see if there's anything that looks like this:
$sale = new AuthorizeNetAIM("YOUR_API_LOGIN_ID","YOUR_TRANSACTION_KEY"); $sale->setSandbox(false);
I always set it individually for each transaction just to make sure (when testing with your sandbox account, you'd obviously use true).
02-28-2012 09:25 AM
hmmm.. still no luck. I've found a file called "AuthorizeNetAIM_Test.php" inside the "anet_php_sdk/test/" folder a file
This had several if statements like this:
public function testAuthCaptureLiveServerTestRequest() { if (MERCHANT_LIVE_API_LOGIN_ID) { $sale = new AuthorizeNetAIM(MERCHANT_LIVE_API_LOGIN_ID,MERCHANT_LIVE_TRANSACTION_KEY); $sale->setSandbox(false); $sale->setFields( array( 'amount' => rand(1, 1000), 'card_num' => '6011000000000012', 'exp_date' => '0415' ) ); $sale->setField('test_request', 'TRUE'); $response = $sale->authorizeAndCapture(); $this->assertTrue($response->approved); } }
I changed the sandbox field to setSandbox(true): and still get error 13.
I also found a file called "AuthorizeNet_Test_Config.php" in the same location
It had several fields for the api and key. I filled those in, and still got an error. It is absolutely the correct information. I'm stumped.
<?php /** * Tests for the AuthorizeNet PHP SDK */ /** * Enter your test account credentials to run tests against sandbox. */ define("xxxxxxxx", ""); define("xxxxxxxxxxxxxxxx", ""); define("AUTHORIZENET_MD5_SETTING", ""); /** * Enter your live account credentials to run tests against production gateway. */ define("xxxxxxxx", ""); define("xxxxxxxxxxxxxxxx", ""); /** * Card Present Sandbox Credentials */ define("xxxxxxxx", ""); define("xxxxxxxxxxxxxxxx", ""); define("AUTHORIZENET_LOG_FILE", dirname(__FILE__) . "/log"); // Clear logfile file_put_contents(AUTHORIZENET_LOG_FILE, ""); if (!function_exists('curl_init')) { throw new Exception('AuthorizeNetSDK needs the CURL PHP extension.'); } if (!function_exists('simplexml_load_file')) { throw new Exception('The AuthorizeNet SDK requires the SimpleXML PHP extension.'); } require_once dirname(dirname(__FILE__)) . '/AuthorizeNet.php'; require_once 'PHPUnit/Framework.php'; if (AUTHORIZENET_API_LOGIN_ID == "") { die('Enter your merchant credentials in '.__FILE__.' before running the test suite.'); }
02-28-2012 09:47 AM
I don't know if this may be the problem, but I got an email from the customer service that includes this message:
If you are integrating your website with Advanced Integration Method (AIM) using PHP, please be aware that the gateway URL is listed twice--once in the cURL configuration, and once again in the main body of the code. Using the test gateway URL in the cURL section of the code will create an Error 13 as cURL would connect to the incorrect server.
Where can I find this to check? I'm looking through the files, and not finding it obvious. Sorry, I'm such a beginner on this.
02-28-2012 10:08 AM
Maybe you should go back to a fresh, unconfigured copy of the PHP SDK.
http://developer.authorize.net/downloads/
To integrate, reference the sample code in the AIM.markdown file in the doc folder. Set your login info and sandbox on the transaction level only, this will override the SDK config:
$sale = new AuthorizeNetAIM( 'YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY'); $sale->setSandbox(true); $sale->setFields(array( 'amount' => '1999.99', 'card_num' => '6011000000000012', 'exp_date' => '04/15' )); $response = $sale->authorizeAndCapture(); print_r($response);
02-28-2012 10:41 AM
Going to try that now..
quick question: I see on the requirements, that I need:
PHP 2.0 and higer (I have 5.3.)
cURL extension enabled
SimpleXML enabled.
Is that possibly the problem? I don't know yet if they are enabled. I'm trying to reach the hosting company to see?
I can't find the php.ini file anywhere, either.
02-28-2012 11:10 AM - edited 02-28-2012 11:13 AM
You probably have cURL and SimpleXML on your hosting - it's fairly standard. If not, then you can ask your hosting company to recompile with those additions, and if they won't, switch to better hosting.
It'll probably tell you or throw an error if they're missing.
02-28-2012 12:14 PM
Ok.. I'm still having no success. Let me take it a step at a time.. So, on the processing page, I have this code on checkout_form.php:
<form method="post" action="<?php echo (AUTHORIZENET_SANDBOX ? AuthorizeNetDPM::SANDBOX_URL : AuthorizeNetDPM::LIVE_URL)?>" id="checkout_form"> <?php $time = time(); $fp_sequence = $time; $fp = AuthorizeNetDPM::getFingerprint(AUTHORIZENET_API_LOGIN_ID, AUTHORIZENET_TRANSACTION_KEY, $amount, $fp_sequence, $time); $sim = new AuthorizeNetSIM_Form( array( 'x_amount' => $amount, 'x_fp_sequence' => $fp_sequence, 'x_fp_hash' => $fp, 'x_fp_timestamp' => $time, 'x_relay_response'=> "TRUE", 'x_relay_url' => $coffee_store_relay_url, 'x_login' => AUTHORIZENET_API_LOGIN_ID, 'x_test_request' => TEST_REQUEST, ) ); echo $sim->getHiddenFieldString(); } ?>
All the x_'variables' are populated in the form. But how is 'x_login' getting AUTHORIZENET_API_LOGIN_ID? I know this may seem like a silly question to the experienced coder, for me it sadly isn't. How is it getting used on process_sale.php? Process_sale.php looks like this, below and shows no link to any of the configuration files?:
<?php require_once 'coffee_store_settings.php'; if ($METHOD_TO_USE == "AIM") { $transaction = new AuthorizeNetAIM; $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields( array( 'amount' => $amount, 'card_num' => $_POST['x_card_num'], 'exp_date' => $_POST['x_exp_date'], 'first_name' => $_POST['x_first_name'], 'last_name' => $_POST['x_last_name'], 'address' => $_POST['x_address'], 'city' => $_POST['x_city'], 'state' => $_POST['x_state'], 'country' => $_POST['x_country'], 'zip' => $_POST['x_zip'], 'email' => $_POST['x_email'], 'card_code' => $_POST['x_card_code'], ) ); $response = $transaction->authorizeAndCapture(); if ($response->approved) { // Transaction approved! Do your logic here. header('Location: thank_you_page.php?transaction_id=' . $response->transaction_id); } else { header('Location: error_page.php?response_reason_code='.$response->response_reason_code.'&response_code='.$response->response_code.'&response_reason_text=' .$response->response_reason_text); } } elseif (count($_POST)) { $response = new AuthorizeNetSIM; if ($response->isAuthorizeNet()) { if ($response->approved) { // Transaction approved! Do your logic here. // Redirect the user back to your site. $return_url = $site_root . 'thank_you_page.php?transaction_id=' .$response->transaction_id; } else { // There was a problem. Do your logic here. // Redirect the user back to your site. $return_url = $site_root . 'error_page.php?response_reason_code='.$response->response_reason_code.'&response_code='.$response->response_code.'&response_reason_text=' .$response->response_reason_text; } echo AuthorizeNetDPM::getRelayResponseSnippet($return_url); } else { echo "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in config.php"; } }
The above file is including the file: coffee_store_settings.php. This in turn, includes ../config.php
in config.php, I show: ( I commented out the
<?php /** * This file contains config info for the sample app. */ // Adjust this to point to the Authorize.Net PHP SDK require_once 'anet_php_sdk/AuthorizeNet.php'; $METHOD_TO_USE = "AIM"; // $METHOD_TO_USE = "DIRECT_POST"; // Uncomment this line to test DPM define("AUTHORIZENET_API_LOGIN_ID",""); // Add your API LOGIN ID define("AUTHORIZENET_TRANSACTION_KEY",""); // Add your API transaction key define("AUTHORIZENET_SANDBOX",true); // Set to false to test against production define("TEST_REQUEST", "FALSE"); // You may want to set to true if testing against production // You only need to adjust the two variables below if testing DPM define("AUTHORIZENET_MD5_SETTING",""); // Add your MD5 Setting. $site_root = "http://YOURDOMAIN/your_store/"; // Add the URL to your site //if (AUTHORIZENET_API_LOGIN_ID == "") { // die('Enter your merchant credentials in config.php before running the sample app.'); //}
and the above references AuthroizeNet.php which has:
require dirname(__FILE__) . '/lib/shared/AuthorizeNetRequest.php';
require dirname(__FILE__) . '/lib/shared/AuthorizeNetTypes.php';
require dirname(__FILE__) . '/lib/shared/AuthorizeNetXMLResponse.php';
require dirname(__FILE__) . '/lib/shared/AuthorizeNetResponse.php';
require dirname(__FILE__) . '/lib/AuthorizeNetAIM.php';
From there, I assume that I should be concerned with AuthorizeNetRequest.php
Inside this, I changed this:
public function __construct($api_login_id = false, $transaction_key = false) { $this->_api_login = ($api_login_id ? $api_login_id : (defined('AUTHORIZENET_API_LOGIN_ID') ? AUTHORIZENET_API_LOGIN_ID : "")); $this->_transaction_key = ($transaction_key ? $transaction_key : (defined('AUTHORIZENET_TRANSACTION_KEY') ? AUTHORIZENET_TRANSACTION_KEY : "")); $this->_sandbox = (defined('AUTHORIZENET_SANDBOX') ? AUTHORIZENET_SANDBOX : true); $this->_log_file = (defined('AUTHORIZENET_LOG_FILE') ? AUTHORIZENET_LOG_FILE : false); }
to this:
public function __construct($api_login_id = false, $transaction_key = false) { $this->_api_login = ($api_login_id ? $api_login_id : (defined('xxxxxxxx') ? AUTHORIZENET_API_LOGIN_ID : "")); $this->_transaction_key = ($transaction_key ? $transaction_key : (defined('xxxxxxxxxxxxxxxx') ? AUTHORIZENET_TRANSACTION_KEY : "")); $this->_sandbox = (defined('AUTHORIZENET_SANDBOX') ? AUTHORIZENET_SANDBOX : true); $this->_log_file = (defined('AUTHORIZENET_LOG_FILE') ? AUTHORIZENET_LOG_FILE : false); }
I tried both $this->_sandbox = (defined('AUTHORIZENET_SANDBOX') ? AUTHORIZENET_SANDBOX : true);
and $this->_sandbox = (defined('AUTHORIZENET_SANDBOX') ? AUTHORIZENET_SANDBOX : false);
also, within the authorizeNetAIM.php, I put this:
const LIVE_URL = 'https://secure.authorize.net/gateway/transact.dll';
const SANDBOX_URL = 'https://secure.authorize.net/gateway/transact.dll';
Still... nothing.
02-28-2012 01:21 PM
Ick. If you're using AIM, then why is your code using DPM?
As I said, do a fresh install of the SDK, and if using AIM, start from the code in AIM.markdown in the doc folder of your SDK. If using DPM instead, go here and look at the PHP section:
http://www.authorize.net/support/DirectPost_guide.pdf
Many of the documentation pdfs are rather murky, but the code examples in this one are pretty good.
It'll take far longer to try to figure out how to fix the wall of code you posted. Scrap the sample app, the code is messy and apparently not working for you.
02-28-2012 05:59 PM