function VerifyIPN($ipn){ $req = 'cmd=_notify-validate'; foreach ($ipn as $key => $value) { if (!eregi("^[_0-9a-z-]{1,30}$",$key) || !strcasecmp ($key, 'cmd')) { unset($key); unset($val); } if ($key != '') { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } } // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ((isset($ipn['test_ipn']) ? 'www.sandbox.paypal.com' : 'www.paypal.com'), 80, $errno, $errstr, 30); if (!$fp) { header('Status: 404 Not Found');// HTTP ERROR exit; } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); } fclose($fp); $res=trim($res); if (strcmp ($res, "VERIFIED") == 0) { /** * VALID IPN */ return 1; }else{ /** * FAKE/BAD IPN */ return 0; } } return 0; } /** * Returns status of IPN, * 4 - Complete * 3 - Pending * 2 - Denied (Received denied) * 1 - Failed * 0 - Invalid IPN (Fail?) * * @param Array $ipn * @return integer */ function IPNStatus($ipn){ if(VerifyIPN($ipn)) { if ($ipn['payment_status'] === 'Completed') return 4; else if ($ipn['payment_status'] === 'Pending') return 3; else if ($ipn['payment_status'] === 'Denied') return 2; else if ($ipn['payment_status'] === 'Failed') return 1; else return 0; }else{ return 0;// Fake IPN } ; } function ProcessIPN($ipn){ $ppstatus=IPNStatus($ipn); if($ppstatus == 1 || $ppstatus == 2) { //denied/failed } else if($ppstatus == 4) { //successful payment }elseif($ppstatus == 3){ $pr=$_POST['pending_reason']; if($pr == 'unilateral'){ $pr = 'unilateral - The owner has not verified that they own the paypal email address. You must wait until the email is claimed (and hope it is not someone elses)

You may login to your paypal account and CANCEL the payment.

In the future you should never send money to unverified accounts.'; } if($pr == 'echeck') { $pr = 'echeck - You paid with eCheck and you must wait until the check clears before you are credited.'; } if($pr == 'intl') { $pr = 'intl - The owner of the paypal address you paid is an international account and does not have a withdraw setup. The admin must manually accept this payment. You will be credited once the admin accepts payment.'; } if($pr == 'verify') { $pr = 'verify - The admin has not yet verified his or her paypal account. You will be credited once the admin verifies the account and accepts the payment.'; } if($pr == 'upgrade') { $pr = 'upgrade - You paid with a credit card and the admin does not have the correct account type to accept these payments. The admin must upgrade the account and accept it for you to be credited.'; } $email = "

Payment Pending

Pending Reason: {$pr}

Possibly you did not use an instant transfer method. As soon as the payment completes you will receive an email and your account will be credited. If payment fails you will also receive notification.

If payment passes but you still do not see your purchase listed on the premium page, then email the administrator Explaining

{$ipn['verify_sign']}
"; }else{ //hacking attempt if this is reached. echo "

Error

Invalid IPN
"; } }