【问题标题】:PHP Paypal IPN processing won't workPHP Paypal IPN 处理不起作用
【发布时间】:2013-11-02 03:42:06
【问题描述】:

我是电子商务的新手,我已经使用 PHP 开发了一个基于 https://github.com/smhack/Ticket 的票务系统,一切正常,支付工作正常(PayPal 购物车)等......(我正在使用贝宝沙盒)

我已经在 IPN 模拟器上测试了我的 IPN,它可以工作,但是在我的项目中,我不明白为什么 IPN 上的 PHP 代码没有被考虑(插入数据库,发送确认邮件)

HTML:

<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="m.bendriss-facilitator@gpayme.com">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="item_name" value="<?php echo $classTitle;?>">
    <input type="hidden" name="item_number" value="Class">
    <input type="hidden" name="custom" value="<?php echo $id;?>">
    <input type="hidden" name="amount" value="<?php echo $price;?>">
    <input type="hidden" name="return" value="http://www.croisentoi.com/ticket/">
    <input type="hidden" name="notify_url" value="http://www.croisentoi.com/ticket/ipn.php">
    <input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

ipn.php:

<?php

    include('ipnlistener.php');
    include("config.php"); 

    if($sqlTicketservertype = 'mysql'){
    $db = new PDO('mysql:host='.$sqlTicketserver.';dbname='.$sqlTicketdbname, $sqlTicketusername, $sqlTicketpassword);
    }
    // tell PHP to log errors to ipn_errors.log in this directory
    ini_set('log_errors', true);
    ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');

    $listener = new IpnListener();
    $listener->use_sandbox = true;

    try {
        $verified = $listener->processIpn();
    } catch (Exception $e) {
        // fatal error trying to process IPN.
    error_log($e->getMessage());
        exit(0);
    }

    if ($verified) {
        // IPN response was "VERIFIED"
        $email = $_POST['payer_email'];
        $txn = $_POST['txn_id'];
        $firstName = $_POST['first_name']; 
        $lastName = $_POST['last_name'];
        $paymentDate = $_POST['payment_date'];

        $query = $db->PREPARE("INSERT INTO tickets ( email, txn, firstName, lastName, paymentDate  ) VALUES ( '$email', '$txn', '$firstName', '$lastName', '$paymentDate'  )");
        $query->execute();

        mail('bendrissmehdi@gmail.com', 'Valid IPN', $listener->getTextReport());
    } else {
        // IPN response was "INVALID"
        mail('bendrissmehdi@gmail.com', 'Invalid IPN', $listener->getTextReport());
    }

?>

我认为付款OK时应该执行IPN。那么为什么这个文件没有被读取呢?你对此有什么想法吗?

编辑:该项目托管在 http://croisentoi.com/ticket

谢谢

【问题讨论】:

    标签: php paypal paypal-ipn


    【解决方案1】:

    您还必须在 Paypal Sandbox 站点中打开 IPN 通知,以便它在您的 PHP 脚本中工作。继续并使用 ipn url 打开它(稍后您可以使用 php 脚本中的“return”属性覆盖此 url):

    https://www.sandbox.paypal.com/cgi-bin/customerprofileweb?cmd=_profile-ipn-notify

    【讨论】:

    • 谢谢普拉拉德。我现在启用了它们,并在Url of notification 字段中设置了 IPN php 文件的 url。我继续付款,付款完成后,我被重定向到我的网站,但没有执行任何操作,并且数据库仍然为空。我是不是忘记了什么?谢谢。
    • @Mehdi - 在通知 URL 中,检查 POST 变量。当 paypal 向您发送 IPN 通知时,它会添加很多 post 数据,例如 order_name、order_qty、custom 等。我现在不记得确切的名称,但有很多。遍历 $_POST php 数组以获取它们。
    • 我可以看到您在代码中处理了一些变量,但请检查它们的确切名称。暂时,注释掉这段代码,并在响应中写下所有 $_POST 变量,以检查贝宝发送给您的内容。
    • 或者只是为了确定,删除块:“if ($verified)”,看看是否至少收到了变量。然后,您可以检查 $listener->processIPN() 函数是否有任何问题。
    • 我的错,我确实在买家账户而不是卖家账户中设置了 IPN url……抱歉,我没有注意……现在可以正常工作了。谢谢。
    猜你喜欢
    • 2014-06-28
    • 2011-05-07
    • 2017-02-02
    • 1970-01-01
    • 2017-08-01
    • 2014-03-01
    • 2011-11-24
    • 1970-01-01
    • 2013-09-30
    相关资源
    最近更新 更多