Solved

capture Authorize.net authorized payment using PHP

Posted on 2010-11-25
9
939 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 109

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to count occurrences of each item in an array.

825 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