?
Solved

capture Authorize.net authorized payment using PHP

Posted on 2010-11-25
9
Medium Priority
?
960 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 111

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 51

Accepted Solution

by:
Steve Bink earned 500 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 51

Assisted Solution

by:Steve Bink
Steve Bink earned 500 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 143

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 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