Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

capture Authorize.net authorized payment using PHP

Posted on 2010-11-25
9
Medium Priority
?
966 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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
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

Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
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 purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
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…
Suggested Courses

609 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