Reply
Highlighted
Member
Posts: 1
Registered: ‎08-01-2011

AIM Test Script working but not the actual script provided

Hey All,

I am having a merchant account at authorized.net and want to host my own secure payment form and send transactions to the payment gateway using an end-to-end secure sockets layer (SSL) connection. hence, I ended up applying AIM.

 

I downloaded the sample app written for Handling Online Payments at:

http://community.developer.authorize.net/t5/The-Authorize-Net-Developer-Blog/Handling-Online-Payment...

 

I also used the code mainly designed for to connect to Authorize.net using the AIM method and to generate a post using Authorize.net's Advanced Integration Method (AIM) and display the results of this post to the screen.

after providing some specific set of fieds like:

$post_url = "https://secure.authorize.net/gateway/transact.dll";

$post_values = array(
	
	// the API Login ID and Transaction Key must be replaced with valid values
	"x_login"			=> "XXXXX",
	"x_tran_key"		=> "XXXXXXXXX",

	"x_version"			=> "3.1",
	"x_delim_data"		=> "TRUE",
	"x_delim_char"		=> "|",
	"x_relay_response"	=> "FALSE",

	"x_type"			=> "AUTH_CAPTURE",
	"x_method"			=> "CC",
	"x_card_num"		=> "XXXXXXXXXX",
	"x_exp_date"		=> "XXXX",

	"x_amount"			=> "0.99",
	"x_description"		=> "Sample Transaction",

	"x_first_name"		=> "Payam",
	"x_last_name"		=> "Parsinejad",
	"x_address"			=> "XXXXX",
	"x_city"			=> "XX",
	"x_state"			=> "XX",
	"x_zip"				=> "XXX",
	"x_country"			=> "United States",
	"x_phone"			=> "XXXX",
	"x_email"			=> "XXXXXx",
	
);

foreach( $post_values as $key => $value )
	{ $post_string .= "$key=" . urlencode( $value ) . "&"; }
$post_string = rtrim( $post_string, "& " );

 

This sample code uses the CURL library for php to establish a connection:

$request = curl_init($post_url); // initiate curl object
	curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
	curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
	curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
	curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
	$post_response = curl_exec($request); // execute curl post and store results in $post_response
	// additional options may be required depending upon your server configuration
	// you can find documentation on curl options at http://www.php.net/curl_setopt
curl_close ($request); // close curl object 

 

 and then publishes all the responses and info regarding the transaction. e.g. payment approved or declined because of this and that error.

 

in my case this way works and makes the payment approved. 

 

but once I use this method (from: https://developer.authorize.net/integration/fifteenminutes/#custom):

<?php
require_once 'anet_php_sdk/AuthorizeNet.php'; // Make sure this path is correct.
$transaction = new AuthorizeNetAIM('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY');
$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;
}
?>

 providing all the same information neeeded regarding my merchant account it gets me an error. which is:

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 am wondering what I missed to include. not sure how to change the post url (against LIVE account) in latest method but I am sure everything provided is correct and same as sample test code.

its important for me to get some result back whether the payment approved, declined or something else happend regrading the payment. 

 

It be really appreciated if you could help me out in this :)

 

Thanks,

Payam

 

 

 

Highlighted
All Star
Posts: 1,072
Registered: ‎08-17-2009

Re: AIM Test Script working but not the actual script provided

Hi Payam,

 

That error you are receiving means that you are submitting test credentials against the live server or vice versa. If you're trying to submit a live transaction, make sure the API Login ID/Transaction Key you are using is from your live account, and not your test account. Then also make sure that the call is going to https://secure.authorize.net/gateway/transact.dll instead of the test server (https://test.authorize.net/gateway/transact.dll). Lastly, make sure any sandbox code is set to "false" for a live request. Then see if that fixes things. 

 

Thanks,

 

Michelle

Developer Community Manager

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: AIM Test Script working but not the actual script provided

Also, there's a built-in AIM interface in the PHP API. Why are you implementing this directly using CURL rather than using the AIM interface? Download the PHP SDK if you haven't yet, look in the doc folder for a file called AIM.markdown, and take a look. CURL is fun and all, but it'll make for cleaner code if you can avoid using it.

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: AIM Test Script working but not the actual script provided

Here's some sample code, just so I'm not objecting without contributing something useful:

 

    $authorize = new AuthorizeNetAIM(
        $GLOBALS['_authorize_id'], $GLOBALS['_authorize_key']);
    $authorize->setSandbox(false);

    $fields = array(
        'first_name' => $_POST['first'],
        'last_name' => $_POST['last'],
        'company' => $_POST['company'],
        'address' => $_POST['address'],
        'city' => $_POST['city'],
        'state' => $_POST['state'],
        'zip' => $_POST['zip'],
        'country' => 'US',

        'phone' => $_POST['phone'],
        'email' => $_POST['email'],

        'customer_ip' => $_SERVER['REMOTE_ADDR'],

        'description' => "{$_POST['type']} initial fee for " . count($_POST['zips']) . " zip codes with {$population} total estimated population",
        'amount' => $_POST['initial_payment'],

        'card_num' => $_POST['card_number'],
        'exp_date' => sprintf('%02d%02d', $_POST['card_exp_month'], ($_POST['card_exp_year'] % 1000)),
        'card_code' => $_POST['card_ccv']
    );
    $authorize->setFields($fields);    
    $authorize->setCustomField('payment_type', 'ONE-TIME');

    $result = $authorize->authorizeAndCapture();

    if ($result->error || $result->{'response_code'} != 1)
        $errors[] = "Charge declined - {$result->response_reason_text}";