Tuesday, 20 August 2013

Authorize.net Payment integration in PHP

These steps assume that your web server is on the public internet and can be accessed via a domain name or IP address.(localhost will not work)

Sign up for a Test Account.

Sign up for a test account to obtain an API Login ID and Transaction Key. These keys will authenticate requests to the payment gateway. 

Download the Authorize.Net PHP SDK and include it in your project. 

The Authorize.Net PHP SDK gives you access to the full suite of APIs.
Download the SDK
You'll need to include the file "anet_php_sdk/AuthorizeNet.php" in your project so make sure you save the SDK into a folder that your web server can access such as your var/www folder or your htdocs folder.

Create a new PHP file that implements the Direct Post Method.

The PHP SDK contains a helper function that implements a demonstration of the Direct Post Method in one line of code. Copy and paste the code below into a new file named "direct_post.php" and fill in any incomplete variables. Make sure your server is publicly accessible and that the $url variable points to this new file.

<?php require_once 'anet_php_sdk/AuthorizeNet.php'; // The SDK $url = "http://YOUR_DOMAIN.com/direct_post.php"; $api_login_id = 'YOUR_API_LOGIN_ID'; $transaction_key = 'YOUR_TRANSACTION_KEY'; $md5_setting = 'YOUR_API_LOGIN_ID'; // Your MD5 Setting $amount = "5.99"; AuthorizeNetDPM::directPostDemo($url, $api_login_id, 
$transaction_key, 
$amount, $md5_setting); ?>

Review and try it out!

Go to http://YOUR_DOMAIN.com/direct_post.php in your web browser and click the "Buy" button.
Verify payment transaction success onyour transaction report.

2 comments: