php - PayPal IPN 未插入数据库

标签 php mysql paypal paypal-ipn

我在本地主机上测试了一个 paypal 捐赠按钮,它第一次将支付金额插入 mysql 数据库(在 phpmyadmin 上验证)。但在那之后它就停止工作了

下面有什么东西可以阻止它工作吗?

config.php

<?php

require "paypal_integration_class/paypal.class.php";
require "config.php";
require "connect.php";

$p = new paypal_class;
$p->paypal_url = $payPalURL;

if ($p->validate_ipn()) {
    if($p->ipn_data['payment_status']=='Completed')
    {
        $amount = $p->ipn_data['mc_gross'] - $p->ipn_data['mc_fee'];

        mysql_query("   INSERT INTO dc_donations (transaction_id,donor_email,amount,original_request)
                        VALUES (
                            '".esc($p->ipn_data['txn_id'])."',
                            '".esc($p->ipn_data['payer_email'])."',
                            ".(float)$amount.",
                            '".esc(http_build_query($_POST))."'
                        )");
    }
}

function esc($str)
{
    global $link;
    return mysql_real_escape_string($str,$link);
}
?>

捐赠按钮

<!-- The PayPal Donation Button -->



<form action="<?php echo $payPalURL?>" method="post" class="payPalForm">
<div>
    <input type="hidden" name="cmd" value="_donations" />
    <input type="hidden" name="item_name" value="Donation" />

    <!-- Your PayPal email: -->
    <input type="hidden" name="business" value="<?php echo $myPayPalEmail?>" />

    <!-- PayPal will send an IPN notification to this URL: -->
    <input type="hidden" name="notify_url" value="<?php echo $url.'/ipn.php'?>" /> 

    <!-- The return page to which the user is navigated after the donations is complete: -->
    <input type="hidden" name="return" value="<?php echo $url.'/thankyou.php'?>" /> 

    <!-- Signifies that the transaction data will be passed to the return page by POST -->
    <input type="hidden" name="rm" value="2" /> 


    <!--    General configuration variables for the paypal landing page. Consult 
            http://www.paypal.com/IntegrationCenter/ic_std-variable-ref-donate.html for more info  -->

    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="cbt" value="Go Back To The Site" />
    <input type="hidden" name="no_shipping" value="1" />
    <input type="hidden" name="lc" value="US" />
    <input type="hidden" name="currency_code" value="USD" />




    <input type="double" name="amount">

    <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest" />

    <!-- You can change the image of the button: -->
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!" />

  <img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</div>
</form>

最佳答案

我注意到的第一件事是,您仅在付款状态为已完成时才运行数据库更新。当然,您的付款可能处于待处理状态,在这种情况下,代码将被跳过。

您在本地测试的具体情况如何?您是否使用了 IPN 模拟器,或者是否运行了实际的沙盒交易,以便系统像真实订单一样触发? PHP处理后你的notify_url的实际值是多少?您正在使用 $url,但它的值(value)是多少?如果它是“本地主机”,它将不起作用。

您是否检查过 PayPal IPN 历史记录以查看它是否显示 IPN 正在发送并且可能收到错误结果?您是否检查过您的 Web 服务器日志以查看该脚本是否被命中?

关于php - PayPal IPN 未插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22897529/

相关文章:

php - 如何安排 PHP 程序按服务器上安排的时间间隔运行?

php - 如何将 EAV 值传递给 Paypal 支付信息

paypal - IPN 与 Paypal 定期付款

php - 在不安装 Zend 优化器的情况下运行 php 文件

javascript - 提交验证后重定向到不同页面

javascript - 使用 PHP 和 AJAX 插入 mysql 不起作用

php - 我该如何解决这个错误?弃用 : mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead

php - 如何在现有注册表单中实现 Paypal 支付按钮

php str_replace 是用什么字符串匹配算法写的?

php - Ajax 仅在 while 循环中获取数据的第一项