cancel
Showing results for 
Search instead for 
Did you mean: 

Authorize.NET AIM with Multiple Items/Products using PHP?

Hi I'm developing a web application and needs to Integrate it with Authorize.NET AIM. I have tested the code provided by Authorize.NET it works fine for Single product. This code has an option to use for line items and is commented by default. I uncommented it and then used it but it only shows a single product processing no line items processing.

 

Please see the Authorize.NET AIM Sample Code

 

<?PHP
// By default, this sample code is designed to post to our test server for// developer accounts: https://test.authorize.net/gateway/transact.dll// for real accounts (even in test mode), please make sure that you are// posting to: https://secure.authorize.net/gateway/transact.dll

 

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

 

$post_values = array(

// the API Login ID and Transaction Key must be replaced with valid values

"x_login"=> "API_LOGIN_ID",

"x_tran_key"=> "TRANSACTION_KEY",
"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"=> "4111111111111111",

"x_exp_date"=> "0115",
"x_amount"=> "19.99",

"x_description"=> "Sample Transaction",
"x_first_name"=> "John",

"x_last_name"=> "Doe",

"x_address"=> "1234 Street",

"x_state"=> "WA","x_zip"=> "98004"

// Additional fields can be added here as outlined in the AIM integration

// guide at: http://developer.authorize.net

 

);

 

$post_string = "";

foreach( $post_values as $key => $value ){

     $post_string .= "$key=" . urlencode( $value ) . "&";

}

$post_string = rtrim( $post_string, "& " );

 

$line_items = array("

item1<|>golf balls<|><|>2<|>18.95<|>Y",

"item2<|>golf bag<|>Wilson golf carry bag,

red<|>1<|>39.99<|>Y",

"item3<|>book<|>Golf for Dummies<|>1<|>21.99<|>Y

");

 

foreach( $line_items as $value ){

     $post_string .= "&x_line_item=" . urlencode( $value );

}

$request = curl_init($post_url);

   curl_setopt($request, CURLOPT_HEADER, 0);

   curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);

   curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);

   curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);

   $post_response = curl_exec($request);

curl_close ($request);

 

$response_array = explode($post_values["x_delim_char"],$post_response);

 

 

echo "<OL>\n";

foreach ($response_array as $value){

     echo "<LI>" . $value . "&nbsp;

           </LI>\n";

     $i++;

}

echo "</OL>\n";

 

?>

 

 

Please help to post mutiple items with Authorize.NET AIM.


thanks in Advance

spartan
Member
3 REPLIES 3

Eww. If you're using PHP, use the more PHP-style implementation rather than trying to create XML requests. If you look in your PHP SDK in the doc cubfolder for a file called AIM.markdown (load in Wordpad or equivalent text editor), it'll give you sample code for line items down near the bottom.

TJPride
Expert

tjpride...registered just to tell you how big of a help your post was...I've been pulling what little hair I have out of my head trying to submit multiple items and the method you suggested works so easily.  I appreciate it!

No problem. I really hate working with XML myself when there's a clean PHP layer to work with instead :