'Why is PayPal IPN Event Listener Not Recognizing Payment Verification
I had a PayPal IPN Listener set-up and working perfectly fine all the way through September of last year (and 8 years prior), but now when I try to use it this year, it's not recognizing VERIFIED or INVALID payments. I used the PayPal Sandbox IPN Tester, and it verifies that the "handshake" is being made, which it is, but payment verification isn't being made. I can't find anything current about PHP PayPal IPN scripts either, so I'm at a loss.
Here is a stripped down version of what I'm using:
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// 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 .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen( 'ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) { // ****************************** PAYMENT IS VERIFIED
$transaction_id = $_POST['txn_id'];
$email = $_POST['payer_email'];
$payment_status = strtolower(trim($_POST['payment_status']));
$last_name = $_POST['last_name'];
$first_name = $_POST['first_name'];
$member_id = cleanQuery($_POST['custom']);
if ($payment_status == "completed" || $payment_status == "pending") {
// DO STUFF IF PAYMENT STATUS IS COMPLETED
}
} else if (strcmp ($res, "INVALID") == 0) { // **********************PAYMENT INVALID OR DID NOT GO THROUGH
// Do stuff for UNFERIFIED
}
} // End Of While Loop
fclose ($fp);
} // Of if(!$fp)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
