PayPal IPN沙盒脚本

时间:2013-05-15 03:21:16

标签: php paypal paypal-sandbox paypal-ipn

我有一个PayPal IPN脚本,我正在沙盒中测试。我已经在任何地方插入了mail函数,以便我知道最新情况,并且即使在The PayPal Developer Site使用IPN工具时,我总是从PayPal获得“无效响应”...

这是我的脚本,其中*字符表示对机密信息的审查:

<?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);
}
?>

奇怪的是,如果我用ssl://www.sandbox.paypal.com替换ssl://www.paypal.com,脚本似乎可以正常工作。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

您是否已捕获正在接收的POST并捕获您要发回的内容,并将两者进行比较以确保它们正确且完全正确地发回。另请查看发布的here IPN故障排除步骤。他们也可能有助于解决问题。