Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

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 ]

[Page 1]  [Page 2]  


Comments:
PHP/MySQL not store credit card for paymentNick12/09/05 20:44
RE: Authorize.net Scripts?AuthnetScripts.com12/04/02 06:39
RE: post the docs in the storyKevin McArthur11/14/02 14:34
RE: exec callKevin McArthur11/14/02 14:30
New Versions OutKevin McArthur11/14/02 14:25
RE: Alternative to Anacom?Vadim Fedukovich10/14/02 20:21
Installing cURL on windows. Peter09/19/02 14:26
RE: Authorize.net script (referrer url problem)Brian Winkers06/10/02 12:24
CURLOPT_HTTPHEADERMichael06/04/02 11:36
Authorize.net script (referrer url problem)Kevin05/25/02 12:19
Serious security flawMichael05/22/02 14:38
RE: Curl and persistent connectionsJeffrey05/19/02 02:46
Curl and persistent connectionsJateen Mistry05/14/02 10:08
Use TrustCommerce TCLink insteadJoseph Waterman05/07/02 17:32
RE: just use Payflow Plus from Verisignnhyde04/24/02 23:15
Improved version for authorize.netKevin McArthur03/10/02 02:35
cURL and PHP for HTTPs postDimitar Apostolov02/18/02 07:11
RE: Authorize.net Scripts?scoob02/13/02 13:07
RE: Installing Curl on Virtual Hoststerry chay02/03/02 09:17
RE: curl interface the phpterry chay02/03/02 09:10
RE: Authorize.net Scripts?Surojit Niyogi09/27/01 13:12
Is this safe? PHP & cURLRon L09/18/01 22:57
Authorize.net scriptDavid09/03/01 13:23
Authorize.netRob08/13/01 12:48
Authorize.net Scripts?JohnC07/24/01 11:45
curl interface the phpsankar lal07/18/01 05:01
Installing Curl on Virtual HostsJoe07/11/01 22:49
Secure connection?Alexander Davydov06/26/01 08:12
Anacom dead --- switch to Authorize.NetMichael Reynolds06/21/01 19:10
RE: exec callEric Thelin06/20/01 05:39
RE: just use Payflow Plus from VerisignScott06/13/01 13:09
ereg_replace() or urencode() ?Maxim Maletsky05/30/01 09:33
Alternative to Anacom?Nils-Fredrik Kaland05/30/01 06:08
HTTPS Connections...Rafael Bastidas05/23/01 07:04
Another Script/Payment ServiceRachael05/22/01 12:39
credit card type?crazney05/19/01 06:52
are these required?crazney05/19/01 06:00
Michael Reynolds.Russ Levinton05/17/01 07:22
RE: Curl in PHPMichael Reynolds05/16/01 13:17
just use Payflow Plus from Verisignccbcreg05/14/01 11:11
libcurlHellHound05/14/01 07:04
RE: exec callMichael05/12/01 08:32
Curl in PHPRichard Thomas05/11/01 12:36
post the docs in the storymike05/11/01 08:18
exec callAndy Worthington05/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.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.