Solved

capture Authorize.net authorized payment using PHP

Posted on 2010-11-25
9
933 Views
Last Modified: 2012-06-21
I want a sample example of PHP code using Authorize.ner API to capture Authorized payment from authorize.net

This will reduce efforts to manually log into auth site and complete payment capture.
0
Comment
Question by:satishmantri
9 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34214808
You might want to ask a moderator to add this to the PHP Zone, and the Web Applications Zone.
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 125 total points
ID: 34217143
This example shows an AUTH_ONLY transaction.  To create an AUTH_CAPTURE or PRIOR_AUTH_CAPTURE, refer to the API manual (http://www.authorize.net/support/AIM_guide.pdf) for the necessary changes.
<?
/* ... code before this point set up various variables and checks for valid data/environment ... */

$x_Test = "FALSE";
if (usr_GLOBALS_TESTMODE) { $x_Test='TRUE'; }

$hashval = $gbl['Company']['CCHash'];
$x_Login=$gbl['Company']['CCLogin'];
$x_Delim_Data="TRUE";
$x_Delim_Char="|";
$x_Encap_Char="";
$x_Type="AUTH_ONLY";

// customer fields
$x_Method="CC";
$x_Tran_Key = $gbl['Company']['CCTrans'];
$x_Amount = sprintf("%1.2f",ceil($cartarr['OrderTotal'] * $payrow['PayPercent'])/100);
$x_FName = $baddrrow['FirstName'];
$x_LName = $baddrrow['LastName'];
$x_Company = $baddrrow['Company'];
$x_Address = $baddrrow['Addr1'];
$x_City = $baddrrow['City'];
$x_State = $baddrrow['State'];
$x_Zip = $baddrrow['Zip'];
$x_Phone = $gbl_CUST->PriPhone;
$x_Card_Num = $cardnum;
$x_Exp_Date = date("m/y", mktime(0, 0, 1, $expmonth, 1, $expyear));
$x_CVV = $cvv;

// standard fields
$fields = "x_version=3.1&x_delim_data=$x_Delim_Data&x_delim_char=$x_Delim_Char&" .
		"x_encap_char=$x_Encap_Char&x_type=$x_Type&x_method=$x_Method&x_duplicate_window=300&" .
		"x_country=US&x_email_customer=FALSE&";

// customized fields
$fields .= "x_login=$x_Login&x_tran_key=$x_Tran_Key&x_test_request=$x_Test&" .
					"x_first_name=$x_FName&x_last_name=$x_LName&x_address=$x_Address&" .
					"x_city=$x_City&x_state=$x_State&x_zip=$x_Zip&x_company=$x_Company&" .
					"x_phone=$x_Phone&x_cust_id=$custid&x_invoice_num=$orderid&" .
					"x_amount=$x_Amount&x_card_num=$x_Card_Num&x_exp_date=$x_Exp_Date&" .
					"x_card_code=$x_CVV";

// execute CURL session to authorize.net, return in $details
$ch = curl_init("https://secure.authorize.net/gateway/transact.dll");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$buffer = curl_exec($ch);
curl_close($ch);
// get the returned array, and set up for the hash check.
$details = explode($x_Delim_Char,$buffer);
$hashval = $hashval . $x_Login . $details[6] . $x_Amount;

/* ... code continues from here to check return from Authorize ... */
?>

Open in new window

0
 
LVL 1

Author Comment

by:satishmantri
ID: 34217182
Payment Authorize code is already in place.

What I want is a code that will capture this Authorize payment without the need of logging into Authorize.net site.

Using some PHP API with Soap or CURL.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 50

Assisted Solution

by:Steve Bink
Steve Bink earned 125 total points
ID: 34217598
The code I presented above shows you the basic method for contacting their API.  To change this code from "AUTH_ONLY" to "PRIOR_AUTH_CAPTURE", you will need to change the type flag (line 12), and add any other necessities as stated by the AIM manual.  For example, you can probably remove the address/customer information, but you will need to add the transaction ID you are targeting.  The manual provides all of this guidance.  Reference the link my previous post.

You will always need to log in to Authorize.net.  The CURL session in the code includes the account login and the account hash, which authenticates the account during the transaction.  Those two fields must be present with every transaction.
0
 
LVL 1

Author Comment

by:satishmantri
ID: 34217872
I will check the manual and your stated script and test.
Will further place My queries or My conclusion when am done.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34877814
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Calculate values in an array 18 32
Form not operating correctly. 1 22
MySQL Grouping 2 19
echo time from sql to input type="time" 9 17
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now