简体   繁体   English

贝宝IPN沙箱脚本

[英]PayPal IPN Sandbox Script

I have a PayPal IPN script that I'm testing in the sandbox. 我有一个正在沙箱中测试的PayPal IPN脚本。 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 ... 我尽可能在任何地方插入mail功能,以便了解发生的事情,即使在PayPal开发人员网站上使用IPN工具时,我也总是从PayPal收到“无效响应” ...

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. 奇怪的是,如果我将ssl://www.sandbox.paypal.com替换为ssl://www.paypal.com ,则脚本似乎可以正常工作。 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. 您是否已捕获收到的POST并捕获了发回的邮件,并比较了两者以确保正确正确地发回了它们。 Also take a look at the IPN trouble shooting steps posted here . 还可以查看此处发布的IPN故障排除步骤。 They may help to resolve the issue as well. 它们也可能有助于解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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