|
Anacom
Making the Connection
Once curl is installed, it's time to make the connection. Anacom offers
modules for direct connection via Perl, Java, and executables for Windows
NT, but not PHP --- so I wrote my own. Here is the function I use for
connecting to Anacom:
<XMP>
<?php
//////////////////////////////////////////////////////////
// PostAnacom.php
//
// a PHP function for connecting to Anacom and
// charging a credit card while returning the result
// to the calling script for reading and/or processng
//
//////////////////////////////////////////////////////////
// this function connects to Anacom and reads the result
function GetAnacomResult($fulltotal, $ordernumber,
$ccname, $baddress, $bcity,
$bstate, $bzip, $bcountry,
$bphone, $email, $trantype,
$username, $ccnumber, $month, $year)
{
// the UPGI version we are currently using
$version = "1.1";
// path to curl
$curl = "/usr/local/bin/curl";
// URL for posting to Anacom
$anacom_url
"https://www.payment-gateway.net/servlet/com.anacom.aai.Aai";
// build the data string that contains the
// credit card info and customer data
$data = "target_app=WebCharge_v6.00&";
$data .= "fulltotal=$fulltotal&";
$data .= "ordernumber=$ordernumber&";
$data .= "ccname=$ccname&";
$data .= "baddress=$baddress&";
$data .= "bcity=$bcity&";
$data .= "bstate=$bstate&";
$data .= "bzip=$bzip&";
$data .= "bcountry=$bcountry&";
$data .= "bphone=$bphone&";
$data .= "email=$email&";
$data .= "trantype=$trantype&";
$data .= "response_mode=simple&";
$data .= "username=$username&";
$data .= "ccnumber=$ccnumber&";
$data .= "month=$month&";
$data .= "year=$year&";
$data .= "connection_method=POST&";
$data .= "delimited_fmt_field_delimiter==&";
$data .= "delimited_fmt_include_fields=true&";
$data .= "delimited_fmt_value_delimiter=|&";
$data .= "delimitedresponse=Y&";
$data .= "include_extra_field_in_response=N&";
$data .= "last_used_response_num=5&";
$data .= "response_fmtŪlimited&";
$data .= "upg_auth=zxcvlkjh&";
$data .= "merch_ip=$REMOTE_ADDR&";
$data .= "upg_version=version&";
$data .= "yes=Y";
// replace all whitespace with a plus sign for the query string
$data = ereg_replace(" ", "+", $data);
// post the data
exec("$curl -d \"$data\" $anacom_url", $return_string);
// split up the results into name=value pairs
$tmp = explode("|", $return_string[0]);
for($i=0;$i<count($tmp);$i++)
{
$tmp2 = explode("=", $tmp[$i]);
$$tmp2[0] = $tmp2[1];
}
// check for approval or error
if($Approval)
{
$card_status[0] = "approved";
$card_status[1] = "$Approval";
}
elseif($Error)
{
$card_status[0] = "error";
$card_status[1] = "$Error";
}
// return the card status as an array
return $card_status;
}
?>
</XMP>
It's pretty simple, but it does the trick. Note this line:
<XMP>
exec("$curl -d \"$data\" $anacom_url", $return_string);
</XMP>
This is where the work is actually done. An exec call is made to curl and
the query string is passed to Anacom via the POST method. The result is read
in the variable $return_string. The variable $curl will need to point to the
location where curl lives.
[ Next Page ]
| Comments: | ||
| PHP/MySQL not store credit card for payment | Nick | 12/09/05 20:44 |
| RE: Authorize.net Scripts? | AuthnetScripts.com | 12/04/02 06:39 |
| RE: post the docs in the story | Kevin McArthur | 11/14/02 14:34 |
| RE: exec call | Kevin McArthur | 11/14/02 14:30 |
| New Versions Out | Kevin McArthur | 11/14/02 14:25 |
| RE: Alternative to Anacom? | Vadim Fedukovich | 10/14/02 20:21 |
| Installing cURL on windows. | Peter | 09/19/02 14:26 |
| RE: Authorize.net script (referrer url problem) | Brian Winkers | 06/10/02 12:24 |
| CURLOPT_HTTPHEADER | Michael | 06/04/02 11:36 |
| Authorize.net script (referrer url problem) | Kevin | 05/25/02 12:19 |
| Serious security flaw | Michael | 05/22/02 14:38 |
| RE: Curl and persistent connections | Jeffrey | 05/19/02 02:46 |
| Curl and persistent connections | Jateen Mistry | 05/14/02 10:08 |
| Use TrustCommerce TCLink instead | Joseph Waterman | 05/07/02 17:32 |
| RE: just use Payflow Plus from Verisign | nhyde | 04/24/02 23:15 |
| Improved version for authorize.net | Kevin McArthur | 03/10/02 02:35 |
| cURL and PHP for HTTPs post | Dimitar Apostolov | 02/18/02 07:11 |
| RE: Authorize.net Scripts? | scoob | 02/13/02 13:07 |
| RE: Installing Curl on Virtual Hosts | terry chay | 02/03/02 09:17 |
| RE: curl interface the php | terry chay | 02/03/02 09:10 |
| RE: Authorize.net Scripts? | Surojit Niyogi | 09/27/01 13:12 |
| Is this safe? PHP & cURL | Ron L | 09/18/01 22:57 |
| Authorize.net script | David | 09/03/01 13:23 |
| Authorize.net | Rob | 08/13/01 12:48 |
| Authorize.net Scripts? | JohnC | 07/24/01 11:45 |
| curl interface the php | sankar lal | 07/18/01 05:01 |
| Installing Curl on Virtual Hosts | Joe | 07/11/01 22:49 |
| Secure connection? | Alexander Davydov | 06/26/01 08:12 |
| Anacom dead --- switch to Authorize.Net | Michael Reynolds | 06/21/01 19:10 |
| RE: exec call | Eric Thelin | 06/20/01 05:39 |
| RE: just use Payflow Plus from Verisign | Scott | 06/13/01 13:09 |
| ereg_replace() or urencode() ? | Maxim Maletsky | 05/30/01 09:33 |
| Alternative to Anacom? | Nils-Fredrik Kaland | 05/30/01 06:08 |
| HTTPS Connections... | Rafael Bastidas | 05/23/01 07:04 |
| Another Script/Payment Service | Rachael | 05/22/01 12:39 |
| credit card type? | crazney | 05/19/01 06:52 |
| are these required? | crazney | 05/19/01 06:00 |
| Michael Reynolds. | Russ Levinton | 05/17/01 07:22 |
| RE: Curl in PHP | Michael Reynolds | 05/16/01 13:17 |
| just use Payflow Plus from Verisign | ccbcreg | 05/14/01 11:11 |
| libcurl | HellHound | 05/14/01 07:04 |
| RE: exec call | Michael | 05/12/01 08:32 |
| Curl in PHP | Richard Thomas | 05/11/01 12:36 |
| post the docs in the story | mike | 05/11/01 08:18 |
| exec call | Andy Worthington | 05/11/01 07:50 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


