dtzjvj3915 2013-05-15 03:21
浏览 100

PayPal IPN沙盒脚本

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
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "

";
$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!

  • 写回答

1条回答 默认 最新

  • duangaoe9401 2013-05-15 14:38
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决