Skip to content

Commit ae98294

Browse files
Create nochexapcphp.php
1 parent faaeba9 commit ae98294

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

PHP/nochexapcphp.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
// Payment confirmation from http post
3+
4+
$your_email = '[email protected]'; // your merchant account email address
5+
6+
7+
function http_post($server, $port, $url, $vars) {
8+
// get urlencoded vesion of $vars array
9+
$urlencoded = "";
10+
foreach ($vars as $Index => $Value) // loop round variables and encode them to be used in query
11+
$urlencoded .= urlencode($Index ) . "=" . urlencode($Value) . "&";
12+
$urlencoded = substr($urlencoded,0,-1); // returns portion of string, everything but last character
13+
14+
$headers = "POST $url HTTP/1.0\r\n"; // headers to be sent to the server
15+
$headers .= "Content-Type: application/x-www-form-urlencoded\r\n";
16+
$headers .= "Host: www.nochex.com\r\n";
17+
$headers .= "Content-Length: ". strlen($urlencoded) . "\r\n\r\n"; // length of the string
18+
19+
//$hostip = @gethostbyname("www.nochex.com");
20+
21+
/*echo "Nochex IP Address = " . $hostip . "<br/><br/>";
22+
23+
echo "Headers = " . $headers . "";*/
24+
25+
$fp = fsockopen($server, $port, $errno, $errstr, 20); // returns file pointer
26+
if (!$fp) return "ERROR: fsockopen failed.\r\nError no: $errno - $errstr"; // if cannot open socket then display error message
27+
28+
fputs($fp, $headers); //writes to file pointer
29+
30+
fputs($fp, $urlencoded);
31+
32+
$ret = "";
33+
while (!feof($fp)) $ret .= fgets($fp, 1024); // while it’s not the end of the file it will loop
34+
fclose($fp); // closes the connection
35+
return $ret; // array
36+
}
37+
38+
// uncomment below to force a DECLINED response
39+
//$_POST['order_id'] = "1";
40+
41+
//HTTPS
42+
$response = http_post("ssl://www.nochex.com", 443, "/apcnet/apc.aspx", $_POST);
43+
44+
// HTTP
45+
//$response = http_post("www.nochex.com", 80, "/apcnet/apc.aspx", $_POST);
46+
47+
// stores the response from the Nochex server
48+
$debug = "IP -> " . $_SERVER['REMOTE_ADDR'] ."\r\n\r\nPOST DATA:\r\n";
49+
foreach($_POST as $Index => $Value)
50+
$debug .= "$Index -> $Value\r\n";
51+
$debug .= "\r\nRESPONSE:\r\n$response";
52+
53+
echo $debug;
54+
55+
if (!strstr($response, "AUTHORISED")) { // searches response to see if AUTHORISED is present if it isn’t a failure message is displayed
56+
$msg = "APC was not AUTHORISED.\r\n\r\n$debug"; // displays debug message
57+
}
58+
else {
59+
$msg = "APC was AUTHORISED."; // if AUTHORISED was found in the response then it was successful
60+
// whatever else you want to do
61+
}
62+
63+
mail($your_email, "APC Debug", $msg); // sends an email explaining whether APC was successful or not, the subject will be “APC Debug” but you can change this to whatever you want.
64+
?>

0 commit comments

Comments
 (0)