#native_company# #native_desc#
#native_cta#

Anacom Page 2

By Michael Reynolds
on May 10, 2001

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.