Connecting to Authorize.net with PHP
By Justin Silverton
What is authorize.net?
The Authorize.Net Payment Gateway is a secure Internet bridge between merchant businesses and the credit card and electronic check payment processing networks. We provide merchants with fast, reliable and secure passage for transaction data via a 128-bit Secure Sockets Layer (SSL) Internet Protocol (IP) connection, and manage the complex routing of payment information to the appropriate credit card processors. See a diagram that illustrates a typical Authorize.Net credit card transaction.
The Authorize.Net Payment Gateway is available to merchants seven days a week, 24 hours a day. The payment gateway offers many features and options that can be tailored to specific merchant business models.
Where do I start?
The first thing that you need to do, is signup with a test account. This will allow you to test out transactions to make sure your scripts are interfacing properly with their API. Here is the URL for getting your account:
http://developer.authorize.net/testaccount
API documentation can also be found here:
http://www.authorize.net/support/AIM_guide.pdf
after signing up, you should receive your new account info within 48 hours.
The Code
I have a library available here: (URL). It is originally written by Micah Carrick and is under the GPL/GNU public license. I have made some important additions to the main library, which are needed for it to function properly.
you can get it here: http://www.electronicfiles.net/files/1773/authorize_lib.zip
Requirements: PHP version 4 and above with the CURL extensions enabled
The following 3 files are contained in the above .zip download:
authorizenet.class.php - main class library for connecting to the authorize.net gateway
demo.php - an example driver file that shows how to use the library file. A test transaction is made to the main gateway.
ca-bundle.crt - main certificate file required by CURL for SSL transactions (windows users can place this in c:\windows\system32)
Important Variables that you need to change
Location: authorizenet.class.php
curl_setopt ($ch, CURLOPT_CAINFO,”c:\\windows\\system32\\ca-bundle.crt”);
curl_setopt ($ch,CURLOPT_CAPATH,”c:\\windows\\system32\\ca-bundle.crt”);
change the 3rd parameter “c:\\windows\\system32\\ca-bundle.crt” to the location of your CRT file.
Location: authorizenet.class.php
var $gateway_url = “https://test.authorize.net/gateway/transact.dll”;
it currently points to the authorize.net gateway for test accounts. If you have an account that is performing real transactions, change this variable to the following value: “”https://secure.authorize.net/gateway/transact.dll”
Location: demo.php
$a->add_field(’x_login’, ‘YOUR_USERID’);
$a->add_field(’x_password’, ‘YOUR_PASSWORD’);
change x_login to your Login ID (not partner ID)
and x_password to your password
You should have received both of these in an email from authorize.net
10 Comments so far
Leave a reply






PEAR’s Payment_Process package provides a consistent API for processing online transactions. There is a driver for Authorize.net. Using this package would allow you to build your application in a more generic way and allow you to change payment gateways if needed.
I have tried this PEAR module a couple of weeks ago and it still has a lot of bugs that need to be fixed. This is why I decided to use another library.
The file:
http://www.electronicfiles.net/files/1773/authorize_lib.zip
is not found.
Can you upload it somewhere else or email me the zile?
I am just starting with using authorize.net and need all the help I could get.
sure, I re-uploaded it here:
http://www.jaslabs.com/DownloadFiles/auth_lib.zip
[…] the authorize.net payment gateway is a secure internet bridge between merchant businesses and the credit card and electronic check payment processing networks. we provide merchants with fast, reliable and secure passage for transaction …Read more: here […]
Hi Justin,
I dint find the file “ca-bundle.crt” when i downloaded the zip file,,,
You can find it here:
http://stuff.mit.edu/afs/athena/project/shibboleth/share/curl/curl-ca-bundle.crt
rename it to “ca-bundle.crt”
Thanks a lot,,,
thanks for the info, justin. what are your “important additions to the main library, which are needed for it to function properly” ? doesn’t micah carrick’s work?
“thanks for the info, justin. what are your “important additions to the main library, which are needed for it to function properly” ? doesn’t micah carrick’s work?”
The authorize.net protocols were changed and I had to make a few code additions.