PayPal IPN未插入数据库

时间:2014-04-06 17:37:15

标签: php mysql paypal paypal-ipn

我在localhost上测试了一个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>

1 个答案:

答案 0 :(得分:1)

我注意到的第一件事是,如果付款的状态为已完成,则您只运行数据库更新。您的付款可能正在等待处理,当然也会跳过代码。

您究竟如何在本地测试?您是否使用了IPN模拟器或者是否运行了实际的沙箱事务,因此系统会像真正的订单一样触发?处理完PHP后,notify_url的实际值是多少?你正在使用$ url,但它的价值是多少?如果它是“localhost”它将无法正常工作。

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