PayPal IPN存在问题

时间:2013-04-20 09:35:12

标签: php paypal paypal-ipn

只是想知道是否有人可以帮助我解决有关PayPal IPN的令人沮丧的问题。我的代码是:

<?php
    error_reporting(E_ALL);
    // 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');

    // intantiate the IPN listener
    include('ipnlistener.php');
    $listener = new IpnListener();

    // tell the IPN listener to use the PayPal test sandbox
    $listener->use_sandbox = false;

    // try to process the IPN POST
    try {
       $listener->requirePostMethod();
       $verified = $listener->processIpn();
    } catch (Exception $e) {
       error_log($e->getMessage());
       exit(0);
    }

    // TODO: Handle IPN Response here
    // ... 

    if ($verified) {
       echo 'hello';
       // TODO: Implement additional fraud checks and MySQL storage
       mail('my email here', 'Valid IPN', $listener->getTextReport());
    } else {
       // manually investigate the invalid IPN
       mail('my email here', 'Invalid IPN', $listener->getTextReport());
    }

&GT;

我的ipnlistener.php是这里给出的:https://github.com/Quixotix/PHP-PayPal-IPN

当有人提交付款时,我会在代码中获得有效的IPN电子邮件,但没有其他内容被回显(即hello不回显),并且页面的页脚不存在。这就像拒绝回应任何东西,但确实遵循其他命令。在我的错误日志中,我总是得到'无效的HTTP请求方法'。

有人可以帮忙吗?

感谢。

编辑:只是有必要知道,在

之前回应的任何事情
try {
   $listener->requirePostMethod();
   $verified = $listener->processIpn();
} catch (Exception $e) {
   error_log($e->getMessage());
   exit(0);
}

很好,但之后回复的任何内容都不起作用。

1 个答案:

答案 0 :(得分:0)

requirePostMethod()有意抛出“无效的HTTP请求方法”错误。我们的想法是这个页面应该只接受POST请求。当您在浏览器中查看该页面时,它是一个GET请求。

编辑:当requirePostMethod()抛出异常时,这会阻止PHP解析页面的其余部分,这就是为什么之后的事情不会被回显。

在GitHub上查看有关requirePostMethod的评论=&gt; https://github.com/Quixotix/PHP-PayPal-IPN/blob/master/ipnlistener.php(它位于底部)。

希望有所帮助!