Solved

capture Authorize.net authorized payment using PHP

Posted on 2010-11-25
9
927 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The viewer will learn how to dynamically set the form action using jQuery.

760 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

21 Experts available now in Live!

Get 1:1 Help Now