Reply
Highlighted
Member
Posts: 5
Registered: ‎07-20-2011
Accepted Solution

Does the PHP test code work?

I'm trying to integrate Authorize.net into my system using the AIM method. I'm using the test code -

<?php
require_once '../../commerce/anet_php_sdk/AuthorizeNet.php'; // Make sure this path is correct.
$transaction = new AuthorizeNetAIM('xxxxxxxxxxxx, 'xxxxxxxxxxxx');
$transaction->amount = '9.99';
$transaction->card_num = '4007000000027';
$transaction->exp_date = '10/16';

$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 $response->error_message;
}
?>

 

I read somewhere that this code is bad and doesn't actually work? I'm getting an error "AuthorizeNet Error: Response Code: 3 Response Subcode: 2 Response Reason Code: 13 Response Reason Text: The merchant login ID or password is invalid or the account is inactive. "

 

I'm using a valid ID etc, I just put xxxxx in this example.

 

Thanks for any help


Accepted Solutions
Highlighted
Solution
Accepted by topic author Quicksilver
‎08-21-2015 01:58 AM
Member
Posts: 5
Registered: ‎07-20-2011

Re: Does the PHP test code work?

The original test code does not in fact work. It doesn't have enough parameters. Why they have it available I don't know.

 

This works:

<?php
require_once '../../commerce/anet_php_sdk/AuthorizeNet.php';
define("AUTHORIZENET_API_LOGIN_ID", "xxxxx");
define("AUTHORIZENET_TRANSACTION_KEY", "xxxxx");
define("AUTHORIZENET_SANDBOX", false);
$sale = new AuthorizeNetAIM;
$sale->amount = "5.99";
$sale->card_num = '6011000000000012';
$sale->exp_date = '04/15';
$response = $sale->authorizeAndCapture();

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;
}
?>

View solution in original post


All Replies
Highlighted
Posts: 1,476
Topics: 33
Kudos: 34
Solutions: 126
Registered: ‎09-14-2009

Re: Does the PHP test code work?

The test code perfectly fine. The result you got proves that as that is a valid response. You're probably using the test server with live credentials or vice versa.

-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Handling Authorize.Net's Webhooks with PHP

Integrate Every Authorize.Net JSON API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post
Highlighted
Member
Posts: 5
Registered: ‎07-20-2011

Re: Does the PHP test code work?

[ Edited ]

How do I change the server that it's using? I'm starting to wonder if it's even worth using the SDK if I'm going to have to modify their code anyways. Sure would have been nice if the TEST CODE was setup to work in TEST MODE.

Highlighted
Contributor
Posts: 43
Registered: ‎06-17-2011

Re: Does the PHP test code work?

It does, at least for me. Consider this ARB example (recurring billing test). I got the following code from the SDK (php) after I created my test aurhorize.net account. It works as it created multiple recurring billing test purchases that I can view by logging into my test merchant account:

 

require_once 'anet_php_sdk/AuthorizeNet.php';
define("AUTHORIZENET_API_LOGIN_ID", "my_login_id_number");
define("AUTHORIZENET_TRANSACTION_KEY", "my_transaction_key");
$subscription = new AuthorizeNet_Subscription;
$subscription->name = "PHP Monthly Magazine";
$subscription->intervalLength = "1";
$subscription->intervalUnit = "months";
$subscription->startDate = "2011-07-28";
$subscription->totalOccurrences = "12";
$subscription->amount = "12.99";
$subscription->creditCardCardNumber = "6011000000000012";
$subscription->creditCardExpirationDate= "2018-10";
$subscription->creditCardCardCode = "123";
$subscription->billToFirstName = "Rasmus";
$subscription->billToLastName = "Doe";

// Create the subscription.

$request = new AuthorizeNetARB;

 $response = $request->createSubscription($subscription);
 $subscription_id = $response->getSubscriptionId();

 

Make sure you properly set things up in the config files. My config.php from the Anet_PHP_SDK which includes this arb example among others: (below is the code from my config.php) and that you have your test account API log in id and transaction key. They are ready to work instantly once you configure things properly.

 

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","MY_LOGIN_ID");    // Add your API LOGIN ID
define("AUTHORIZENET_TRANSACTION_KEY","My_API_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/samples/your_store/"; // Add the URL to your site

 

This honestly worked 'out of the box' for me during my testing.

Highlighted
Solution
Accepted by topic author Quicksilver
‎08-21-2015 01:58 AM
Member
Posts: 5
Registered: ‎07-20-2011

Re: Does the PHP test code work?

The original test code does not in fact work. It doesn't have enough parameters. Why they have it available I don't know.

 

This works:

<?php
require_once '../../commerce/anet_php_sdk/AuthorizeNet.php';
define("AUTHORIZENET_API_LOGIN_ID", "xxxxx");
define("AUTHORIZENET_TRANSACTION_KEY", "xxxxx");
define("AUTHORIZENET_SANDBOX", false);
$sale = new AuthorizeNetAIM;
$sale->amount = "5.99";
$sale->card_num = '6011000000000012';
$sale->exp_date = '04/15';
$response = $sale->authorizeAndCapture();

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;
}
?>

Highlighted
Member
Posts: 5
Registered: ‎07-20-2011

Re: Does the PHP test code work?

The README file makes zero mention of config.php. I don't even see that file in the SDK. The closest I see is AuthorizeNet_Test_Config.php