【问题标题】:php - PayPal IPN Not Working (on Sandbox)php - PayPal IPN 不工作(在沙盒上)
【发布时间】:2012-06-25 19:17:34
【问题描述】:

更新:我什至尝试过让整个 PHP 脚本成为一行,在查看脚本时给我发送电子邮件,但它仍然没有给我发送电子邮件。

我什么都试过了,至少我觉得。我已经设置了脚本(非常基本,以便我可以学习如何使用它)以根据 IPN 响应(已完成、无效等)插入一行。

但是,它似乎没有做任何事情。

我尝试过使用沙盒内置的 IPN 测试器,但它没有做任何事情。我尝试使用基于沙盒的捐赠者按钮,并将“notify_url”作为隐藏输入类型,但它什么也没做。

实际插入行的唯一时间是我直接通过浏览器访问文件(当然是 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>

【问题讨论】:

  • 确保您使用的是最新信息。我按照 PayPal 网站上的说明完成了同样的过程,却发现它们已经过时了。我相信您的notify_url 实际上是不正确的,那是我的问题。如果我能找到我用来修复它的信息,我会报告回来。

标签: php mysql paypal sandbox paypal-ipn


【解决方案1】:

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

我不知道沙盒内置的 IPN 测试器,抱歉,可能有人会在这方面为您提供帮助。

【讨论】:

    【解决方案2】:

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

    "NOTIFYURL 自 63.0 版起已弃用。使用 改为 PAYMENTREQUEST_0_NOTIFYURL。 "

    Link to post here

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

    【讨论】:

      【解决方案3】:

      你试过修剪 $res 吗?

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

      而不是

      strcmp($res, "VERIFIED")
      

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

      【讨论】:

        猜你喜欢
        • 2015-11-25
        • 2016-10-02
        • 2014-06-07
        • 2013-12-06
        • 2013-05-09
        • 2011-08-07
        • 2013-07-04
        • 2012-10-10
        • 2012-02-22
        相关资源
        最近更新 更多