I am attempting to connect to a foreign server to do credit card processing.
I'm posting to a bank we'll call "epay.bank.com" and to a script we'll call "/link/authorizepd.asp".
When I post, I get a long, long delay and then no data. The bank is providing no support, and their sample PHP code is PHP3 (and wrong).
Can anyone see a problem with my code?
Thanks in advance.
function Authorize($host, $usepath, $postdata="") {
# open socket to filehandle
$timeout=120;
$fp = pfsockopen($host, 443, $errno, $errstr, $timeout);
if( !$fp ) {
print "$errstr ($errno)<br>\n";
} else {
fputs( $fp, "POST $usepath HTTP/1.1\r\n" );
fputs( $fp, "User-Agent: AGENT/0.007\r\n" );
fputs( $fp, "Accept: */*\r\n" );
fputs( $fp, "Accept: www/source\r\n" );
fputs( $fp, "Accept: text/html\r\n" );
fputs( $fp, "Accept: text/plain\r\n" );
$strlength = strlen($postdata);
fputs( $fp, "Content-type: application/x-www-form-urlencoded\r\n" );
fputs( $fp, "Content-length: ".$strlength."\r\n\r\n" );
fputs( $fp, $postdata."\r\n" );
fputs( $fp, "\r\n" );
$output = "";
while( !feof( $fp ) ) {
$output .= fgets( $fp, 1024 );
}
fclose( $fp );
}
return $output;
//print_r($output);
}
$data = "";
$data.= "ePayAccountNum=5555555555";
$data.= "&password=foobar01";
$data.= "&customerNum=$customerId";
$data.= "&orderNum=$orderId";
$data.= "&transactionAmount=$_POST[totalcart]";
$data.= "&cardHolderZip=$row_bill[zip]";
$data.= "&cardAccountNum=$cardnum";
$data.= "&expirationDate=$carddate";
$Response = Authorize("epay.bank.com","/link/authorizepd.asp", urlencode($data));
$responseArray = split("|", $Response);
print_r($responseArray);
I should add that if I just go to the URL: https://epay.bank.com/link/authorizepd.asp (which, by the way, I'm making up for purposes of this post--that's not the real URL), I get an array back with pipes and numbers. Adding [url]https://[/url] to the host, however produces an error.