Hi there everyone!
I'm trying to troubleshoot my PayPal IPN page but am having a problem figuring out how to. I've used the IPN simulator and it says that it was successful, but when I get my error report, it says that it failed because !$fp. Could someone help me figure out how I should test why $fp = fsockopen ('tls://www.sandbox.paypal.com', 443, $errno, $errstr, 30) is failing? Here's my code:
/* Response from Paypal */
$error = 'The Following issues were encountered: ';
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
$req .= "&$key=$value";
}
// assign posted variables to local variables
$txn_id = $_POST['txn_id'];
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$custom = $_POST['custom'];
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('tls://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
$error .= '<br>Error talking to the payment mothership!';
} else {
fputs($fp, $header . $req);