简体   繁体   中英

PayPal IPN Sandbox Script

I have a PayPal IPN script that I'm testing in the sandbox. I have inserted the mail function everywhere possible just so that I know whats going on, and I always get an "Invalid Response" from PayPal, even when using the IPN tool at The PayPal Developer Site ...

Here is my script, where the * character represents censorship of confidential information:

<?php
mysql_connect('localhost', '************', '******************');
mysql_select_db('*************');
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$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 ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$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'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($payment_status != 'Completed') {
    mail('**********************', 'ERROR', 'PayPal IPN Error: Payment Status INVALID');
    exit();
}
if ($reciever_email != '***********************') {
    mail('***********************', 'ERROR', 'PayPal IPN Error: Reciever Email INVALID');
    exit();
}
if ($payment_currency != 'USD') {
    mail('***********************', 'ERROR', 'PayPal IPN Error: CURRENCY INVALID');
    exit();
}
mail('***********************', 'PAYPAL TRANSACTION COMPLETE', 'PayPal Transaction Complete! $' . $payment_amount);
}
else if (strcmp ($res, "INVALID") == 0) {
mail('***********************', 'ERROR', 'PayPal IPN Error: RESPONSE INVALID');
exit();
}
}
fclose ($fp);
}
?>

The odd thing is, if I replace ssl://www.sandbox.paypal.com with ssl://www.paypal.com , the script seems to work fine. Any assistance here is greatly appreciated!

Have you capture the POST that you are receiving and captured what you are sending back and compared the two to make sure that they are being sent back correctly and exactly as is. Also take a look at the IPN trouble shooting steps posted here . They may help to resolve the issue as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM