WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Sample AIM (Advanced Integration Method) PHP Script For Authorize.net using CURL
Categories : CURL, Ecommerce, PHP Click here to Update Your Picture
Jon Olawski
Date : Jan 22nd 2003
Grade : 3 of 5 (graded 14 times)
Viewed : 31107
File : phpAIM.zip
Images : No Images for this code example.
Search : More code by Jon Olawski
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

See also attached file.

<?php
/*******************************************************************************
Sample AIM (Advanced Integration Method) PHP Script For Authorize.net

* Source by Jon Olawski - www.spiderwt.com
* Free to use, modify, distribute!
* Provided with no warranty (if it doesn't work, sorry)
* Download from http://www.spiderwt.com/authorizenet.php
* Donations are greatly appreciated -> https://www.paypal.com/xclick/business=paypal%
40spiderwt.com

Requirements
* PHP 4.0.2 or higher with CURL 7.0.2-beta or higher
* PHP 4.2.3 or higher with CURL 7.9.0 or higher
* Secure Server
* See http://www.php.net/manual/en/ref.curl.php for full PHP & CURL documentation

Introduction
Typically, when using this type of advanced integration you would open up a
socket connection using fsockopen on port 443, then post your fields, and
finally read the response. For whatever reason, I can not seem to get this
to work with Authorize.net. The alternative now is to use CURL (Client URL
Library Functions). This is direct from php.net:

"PHP supports libcurl, a library created by Daniel Stenberg, that allows you to
connect and communicate to many different types of servers with many different
types of protocols. libcurl currently supports the http, https, ftp, gopher,
telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates,
HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp
extension), HTTP form based upload, proxies, cookies, and user+password
authentication."

Authorize.net does provide sample scripts for the SIM (Simple Integration method)
for PHP, but doesn't seem to provide any documentation for the AIM. I hope that
this short sample can help! The AIM allows you, in your script, to process the
transaction and get a response back without the user ever leaving your website.
With the SIM the user posts the information to authorize.net, and then redirects
back to your website.

*******************************************************************************/


#
# Configuration
#
$x_Login="login_id"; // Your authorize.net login
$x_Password=""; // Your authorize.net password (if Password-Required Mode is enabled)

$x_Delim_Data="TRUE"; // Delimited response from the gateway (or set in the Setting Menu)
$x_Delim_Char=","; // Character that will be used to separate fields
$x_Encap_Char=""; // Character that will be used to encapsulate fields

$x_Type="AUTH_CAPTURE"; // Default transaction type
$x_Test_Request="TRUE"; // Make this a test transaction

#
# Customer Information
#
$x_Method="CC";
$x_Amount="99.99";
$x_First_Name="Joe";
$x_Last_Name="Customer";
$x_Card_Num="5424000000000015";
$x_Exp_Date="12/05";

#
# Build fields string to post
#
$fields="x_Version=3.1&x_Login=$x_Login&x_Delim_Date=$x_Delim_Data&x_Delim_Char=$x_Delim_Char&x_Enca
p_Char=$x_Encap_Char";
$fields.="&x_Type=$x_Type&x_Test_Request=$x_Test_Request&x_Method=$x_Method&x_Amount=$x_Amount&x_Fir
st_Name=$x_First_Name";
$fields.="&x_Last_Name=$x_Last_Name&x_Card_Num=$x_Card_Num&x_Exp_Date=$x_Exp_Date";
if($x_Password!='')
{
$fields.="&x_Password=$x_Password";
}

#
# Start CURL session
#
$ch=curl_init("https://secure.authorize.net/gateway/transact.dll");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); // set the fields to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // make sure we get the response back

$buffer = curl_exec($ch); // execute the post

curl_close($ch); // close our session

$details=explode($x_Delim_Char,$buffer); // create an array of the response values

echo "<b>View the page source to see this nice and pretty!</b><br>\n\n";

print_r($details); // print the array

/*******************************************************************************

From here you can read the response from $details and do whatever it is you do!
Remember that the first position in the $details array is 0, not 1. In the
Authorize.net documentation, they show the position in the response starting
with 1, but programmers can't count. Here is an example of what I am talking
about:
The Response Code is the 1st position in the response. That means that
$details[0] is the response code.

The Transaction ID is the 7th position in the response. That means
that $details[6] is the Transaction ID

Refer to the authorize.net AIM documentation for the list of Response codes!

*******************************************************************************/

?>



Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +)
Categories : PHP, Ecommerce, XML, Web Services, CURL
Newbie Notes #8 - A cron trick
Categories : PHP, CURL, Beginner Guides
Amazon book cover handling
Categories : HTML and PHP, PHP, MySQL, Ecommerce
Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers.
Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms
simple shopping cart for php3
Categories : PHP, PHP Classes, Complete Programs, Ecommerce
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
PHP-MySQL shopping cart
Categories : PHP, Ecommerce, Complete Programs
shopping cart class with add/edit/delete product functionality.
Categories : PHP, PHP Classes, Ecommerce
PHP Youtube Downloader - This is a set of PHP functions that can be used to download movies from Youtube.com.
Categories : PHP, CURL, Regexps
Example Shopping cart class
Categories : Ecommerce, PHP, PHP Classes
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases
Validation function for LUHNMod10 and variant. Can discriminate credit card numbers of varying lengths. Uses [Double >> Sum-of-Digits] transform.
Categories : Credit Cards, Authentication, Ecommerce, PHP
PCAC (pretty cool auction client), auction client server applications
Categories : PHP, MySQL, Ecommerce
How to validate an Israeli ID number.
Categories : Ecommerce, PHP, Algorithms
open source online php shop project ecommerce commerce
Categories : PHP, Ecommerce
 bill dalton wrote : 903
This worked exceptionally well. For other folks new to the process (as I was)
there are a few settings within the merchant settings control panel on 
authorize.net. The three settings were the "Delim_Data", "Delim_char", 
and "Encap_Char". Once these were set, transactions were flowing. I was 
getting some minor errors because the `billing address` and other `billing` 
varibles were not set. But as I added those with the same format as the great 
example given here, the minot error eventually disappeared. THANKS JON!!!
 
 Cool Buddy wrote : 923
Hi Olawski Jon!

Well i am using the code provided by you in the example. But i am getting this error :-

(92) The gateway no longer supports the requested method of integration.
 
 Jon Olawski wrote : 924
For those of you with the error "(92) The gateway no 
longer supports the requested method of integration."... 
add the following line to the code: 

curl_setopt ($ch, CURLOPT_POST, 1);

This should fix the problem!
 
 Richard Navarrete wrote : 1009
I`m still getting the (92) error. -- even after I added:
 curl_setopt ($ch, CURLOPT_POST, 1); 

I set the delim, encap, options in the merch. interface and still getting the error.  

please help!
 
 Bob Jacobson wrote : 1054
Also, in case you haven`t seen the major TYPO in this example:

x_delim_date=$x_delim_data

A busy programmer definitely coded this one!

          Bob
 
 Adam Luz wrote : 1057
This script worked great for me. Here are some variables I included that
authorize.net wanted. I modified this script though for customer output
and database entry. I would recommend not using mySql entry, it was design 
for a POBOX script..

<?php 
/******************************************************************************* 
Sample AIM (Advanced Integration Method) PHP Script For Authorize.net 

* Source by Jon Olawski - www.spiderwt.com 
* Free to use, modify, distribute! 
* Provided with no warranty (if it doesn`t work, sorry) 
* Download from http://www.spiderwt.com/authorizenet.php 
* Donations are greatly appreciated -> https://www.paypal.com/xclick/business=paypal% 
40spiderwt.com 

Requirements 
* PHP 4.0.2 or higher with CURL 7.0.2-beta or higher 
* PHP 4.2.3 or higher with CURL 7.9.0 or higher 
* Secure Server 
* See http://www.php.net/manual/en/ref.curl.php for full PHP & CURL documentation 

Introduction 
Typically, when using this type of advanced integration you would open up a 
socket connection using fsockopen on port 443, then post your fields, and 
finally read the response. For whatever reason, I can not seem to get this 
to work with Authorize.net. The alternative now is to use CURL (Client URL 
Library Functions). This is direct from php.net: 

"PHP supports libcurl, a library created by Daniel Stenberg, that allows you to 
connect and communicate to many different types of servers with many different 
types of protocols. libcurl currently supports the http, https, ftp, gopher, 
telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, 
HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP`s ftp 
extension), HTTP form based upload, proxies, cookies, and user+password 
authentication." 

Authorize.net does provide sample scripts for the SIM (Simple Integration method) 
for PHP, but doesn`t seem to provide any documentation for the AIM. I hope that 
this short sample can help! The AIM allows you, in your script, to process the 
transaction and get a response back without the user ever leaving your website. 
With the SIM the user posts the information to authorize.net, and then redirects 
back to your website. 

*******************************************************************************/ 



# Configuration 

$x_Login=""// Your authorize.net login 
$x_Password=""// Your authorize.net password (if Password-Required Mode is enabled) 

$x_Delim_Data="TRUE"// Delimited response from the gateway (or set in the Setting Menu) 
$x_Delim_Char=","// Character that will be used to separate fields 
$x_Encap_Char=""// Character that will be used to encapsulate fields 

$x_Type="AUTH_CAPTURE"// Default transaction type 
$x_Test_Request="TRUE"// Make this a test transaction 


# Customer Information 

$x_Method="CC"
$x_Amount="99.99";  
$x_Last_Name="POBOX"


$x_First_Name="$cc_name";
$x_Address="$cc_address1";
$x_City="$cc_city";
$x_State="$cc_state";
$x_Zip="$cc_zip";
$x_Cust_ID="$box_number$cc_pros";
$x_Invoice_Num="$box_number$cc_pros";
$x_Description="PO Box Charge";
$x_Card_Num="$cc_1$cc_2$cc_3$cc_4";
$x_Exp_Date="$cc_mo$cc_year";
$x_card_code="$cc_digit";









# Build fields string to post 

$fields="x_Version=3.1&x_Login=$x_Login&x_Delim_Data=$x_Delim_Data&x_Delim_Char=$x_Delim_Char&x_Enca 
p_Char=$x_Encap_Char"

$fields .= "&x_Type=$x_Type&x_Test_Request=$x_Test_Request&x_Method=$x_Method&x_Amount=$x_Amount&";
$fields .= "x_First_Name=$x_First_Name&x_Last_Name=$x_Last_Name&x_Card_Num=$x_Card_Num"
$fields .= "&x_Exp_Date=$x_Exp_Date&x_Address=$x_Address&x_City=$x_City&x_State=$x_State";
$fields .= "&x_Zip=$x_Zip&x_Cust_ID=$x_Cust_ID&x_Invoice_Num=$x_Invoice_Num&";
$fields .= "x_Description=$x_Description&x_card_code=$x_card_code"
if(
$x_Password!=``) 

$fields.="&x_Password=$x_Password"



# Start CURL session 

$ch=curl_init("https://secure.authorize.net/gateway/transact.dll"); 
curl_setopt($chCURLOPT_HEADER0); 
curl_setopt($chCURLOPT_POSTFIELDS$fields); // set the fields to post 
curl_setopt($chCURLOPT_RETURNTRANSFER1); // make sure we get the response back 

$buffer curl_exec($ch); // execute the post 

curl_close($ch); // close our session 

$details=explode($x_Delim_Char,$buffer); // create an array of the response values 







/******************************************************************************* 

From here you can read the response from $details and do whatever it is you do! 
Remember that the first position in the $details array is 0, not 1. In the 
Authorize.net documentation, they show the position in the response starting 
with 1, but programmers can`t count. Here is an example of what I am talking 
about: 
The Response Code is the 1st position in the response. That means that 
$details[0] is the response code. 

The Transaction ID is the 7th position in the response. That means 
that $details[6] is the Transaction ID 

Refer to the authorize.net AIM documentation for the list of Response codes! 

*******************************************************************************/ 

?> 

<?
echo <<<END

<body>

<p><b>ABSZone Credit Card Transaction<br></b>
3106 W. Magnolia Blvd<br>
Burbank, C.A. 91505</p>
<p>Name: $details
[69]<br>
Card Number: **** **** **** $cc_4<br>
Expiration Date: $cc_mo/$cc_year<br>
Security Code: $cc_digit</p>
<p>Amount: $$details
[9]</p>
<p>Authorization Code: $details
[4]<br>
Results:<b> $details
[3]</b></p>
<p> </p>
<p>X ___________________________________</p>

</body>

</html>
END;

?>

<?
include(`db.php`);

  
$query "insert into payments
       (cc_1,cc_2,cc_3,cc_4,cc_type,cc_mo,cc_year,cc_digit,months_paid,cc_address1,
    cc_city,cc_state,cc_zip,cc_name,cc_amount,cc_action,p_day,p_month,p_year,
    box_number,payment_type,auth_code) 
    values
    (`$cc_1`, `$cc_2`, `$cc_3`, `$cc_4`, `$cc_type`, `$cc_mo`, `$cc_year`, `$cc_digit`, 
    `$months_paid`, `$cc_address1`, `$cc_city`, `$cc_state`, `$cc_zip`, `$cc_name`, 
    `$cc_amount`, `$cc_action`, `$p_day`, `$p_month`, `$p_year`, `$box_number`, `1`, 
    `$details[4]`)"
;


mysql_query($query) or
         die (
mysql_error());
?>
 
 Sapatarshi Samanta wrote :1727
I am not able to use this code.in my server when i run 
this code the page is going to downloaded and i think it 
was the problem for the curl is not execute properly.have 
any solution.