php - PayPal IPN不起作用(在沙箱上)

时间:2012-06-24 00:08:23

标签: php mysql paypal sandbox paypal-ipn

更新:我甚至尝试让整个PHP脚本只是一行,在查看脚本时通过电子邮件发送给我,但它仍然没有给我发电子邮件。 < / p>

我已经尝试了一切,或者我觉得。我已经设置了脚本(非常基本,所以我可以学习如何使用它)根据IPN响应插入一行(已完成,无效等)

然而,它似乎没有做任何事情。

我尝试过使用沙盒内置的IPN测试仪,但它没有做任何事情。我尝试过使用基于Sandbox的捐赠者按钮&#34; notify_url&#34;作为隐藏的输入类型,它不会做任何事情。

实际插入行的唯一时间是我直接通过浏览器访问文件(当然是IPN文件)。在这种情况下,它会插入一行表示这是无效的付款。

在狄更斯,我做错了什么或PayPal的沙盒暂时搞砸了?

<?php
require("../functions.php");
sql();

// read the post from PayPal system and add 'cmd'
$req = 'cmd=' . urlencode('_notify-validate');

foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);


// assign posted variables to local variables
$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 (strcmp ($res, "VERIFIED") == 0) {
    // check the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct
    // process payment
    if($payment_status == "Completed") {
        mysql_query("INSERT INTO donators (username)
VALUES ('completed')");
    } else {
        mysql_query("INSERT INTO donators (username)
        VALUES ('wrong payment status')");
    }

}
else if (strcmp ($res, "INVALID") == 0) {
    mysql_query("INSERT INTO donators (username)
    VALUES ('invalid')");
}
?>

捐赠者表格:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="QJUZ2AGANUWYS">
<input name="notify_url" value="http://mysite.com/libs/paypal/ipn.php" type="hidden">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

3 个答案:

答案 0 :(得分:0)

可能无效的付款可能来自您使用信用卡或沙盒帐户信用卡模拟的事实。 抛弃条件if (strcmp ($res, "VERIFIED") == 0) {,你会没事的。

我不知道沙箱的内置IPN测试仪,对不起,这里可能会有人帮助你。

答案 1 :(得分:0)

  

正如此页面所说:   https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetExpressCheckoutDetails

     

“自版本63.0以来,NOTIFYURL已弃用。请使用   PAYMENTREQUEST_0_NOTIFYURL代替。 “

Link to post here

此外,作为代码注入点,将您的IPN地址放在HTML代码中。任何人都可以查看它,因此知道文件的位置。出于安全考虑,将其放在您的后台PHP脚本中,位于函数调用Paypal functions内的ConfirmPayment文件中。

答案 2 :(得分:0)

你试过修剪$ res吗?

strcmp(trim($res), "VERIFIED")

而不是

strcmp($res, "VERIFIED")

这就是最终让它为我工作的......

相关问题