PayPal IPN 侦听器将不再工作 [英] PayPal IPN Listener won't work anymore

查看:40
本文介绍了PayPal IPN 侦听器将不再工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先感谢您的关注.问题来了.

First, Thanks for your attention. Comes to prob.

我正在使用此 IPN 侦听器代码:

I'm using this IPN Listener code:

// IPN LISTENER
// intercetta le variabili IPN inviate da PayPal
$req = 'cmd=_notify-validate';     
// legge l'intero contenuto dell'array POST
foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

// intestazione, prepara le variabili PayPal per la validazione
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";  // www.paypal.com for a live site
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n\r\n";

// apre una connessione al socket PayPal
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

// converte le variabili inviate da IPN in variabili locali
$txn_id = filter_var($_POST['txn_id'], FILTER_SANITIZE_STRING);
$payment_status = filter_var($_POST['payment_status'], FILTER_SANITIZE_STRING);
$receiver_email = filter_var($_POST['receiver_email'], FILTER_SANITIZE_EMAIL);
$payer_email = filter_var($_POST['payer_email'], FILTER_SANITIZE_EMAIL);
$first_name = filter_var($_POST['first_name'], FILTER_SANITIZE_STRING);
$last_name = filter_var($_POST['last_name'], FILTER_SANITIZE_STRING);
$address_street = filter_var($_POST['address_street'], FILTER_SANITIZE_STRING);
$address_city = filter_var($_POST['address_city'], FILTER_SANITIZE_STRING);
$address_state = filter_var($_POST['address_state'], FILTER_SANITIZE_STRING);
$address_zip = filter_var($_POST['address_zip'], FILTER_SANITIZE_STRING);

// verifica l'apertura della connessione al socket
if (!$fp) {

    // se la connessione non avviene l'esecuzione dello script viene bloccata
print("connessione PayPal non avvenuta, si prega di riprovare piu' tardi");

    // in alternativa è per esempio possibile inviare un'email al venditore
} else {

    // elaborazione delle informazioni
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets ($fp, 1024);

        // azioni in caso di risposta positiva da parte di PayPal
        if (stripos($res, "VERIFIED") !== false) {
$myvariables = 1;
$anothermyvariables = "INSERT INTO MyDB ( paid, name, email, date) 
VALUES ('". $txn_id ."','" . $first_name ." ". $last_name .  "','" . $payer_email ."','". the_date('Y-m-d','','',FALSE) . "');";
$wpdb->query($anothermyvariables);
            }

        }

        // azione in caso di risposta negativa da parte di PayPal else
        if (stripos($res, "INVALID") !== false) {
$anothervariablesofmine = 2;
$paypalerr = "Pagamento non riuscito!"; // Payment not success!
        }

    }

    // chiusura della sorgente di dati
    fclose($fp);

以前确实有效,但现在无效...我已经使用 var_dumppayment_status=Completed 测试了 PayPal 返回到我的网站的变量.他们看起来没问题.

It did work previously, but not now... I've tested the variables that PayPal return to my website with var_dump and payment_status=Completed. They seem ok.

我已经测试过是否建立了连接并且它也能正常工作:

I've tested if connection is established and also it works:

if (!$fp) {
ecc..
} else {
print("Connection Established");
etc....

问题来自变量stripos($res, "VERIFIED") stripos($res, "INVALID").var_dump 都以 bool (false) 的形式返回.

The problem comes with variables stripos($res, "VERIFIED") stripos($res, "INVALID"). var_dump returns both as bool (false).

查看 Sandbox profile History(买家和卖家),所有交易结果都完成了.但让我发疯的是,一周后效果很好......我已经搜索了 PayPal 可能对 IPN 侦听器端口、主机或变量进行了一些更改,但似乎没有任何更改.对吗?

Looking on Sandbox profile History (of buyer and seller), all transactions results are completed. But the thing that makes me crazy is that one week later works perfectly... I've searched about maybe some change in IPN listener port, host or variables by PayPal but seems none has changed. Right?

我直接在购买表单的页面中编写了 IPN 侦听器,这意味着 IPN 侦听器的调用也没有 $_POST 变量.对我来说,唯一可能的回复是阻止我的 PayPal 端的 IPN 侦听器的垃圾邮件保护,这可能吗?因为在没有 cmd=_notify-validate 的情况下也调用了侦听器,但它根本不起作用(但进行了一个空白调用,PayPal 可能不太欣赏).

I wrote the IPN Listener directly in the page of buying form, this mean IPN Listener is called also without $_POST variables. Only possible reply for me is a spam protection from IPN Listener in PayPal side that blocked me, it's possible? 'Cause the Listener is called also without cmd=_notify-validate, but simply it just don't work (but made a blank call that perhaps isn't very appreciated by PayPal).

抱歉各位,重新调试(上帝保佑var_dump).将 var_dump 放入 while 循环中:

Sorry guys, re-debugged (God bless var_dump). Putted var_dump in while loop so:

....
        while (!feof($fp)) {
        $res = fgets ($fp, 1024);
var_dump(stripos($res, "VERIFIED"));
print("<br> VERIFIED". stripos($res, "VERIFIED") ."<br>");
var_dump(stripos($res, "INVALID"));
print("<br> INVALID". stripos($res, "INVALID") ."<br>");
...

并找到一个 VERIFIED int(0) 而不是 bool (false)

and find one VERIFIED int(0) instead of bool (false)

我刚换了

 if (stripos($res, "VERIFIED") !== false) {

 if (stripos($res, "VERIFIED") == 0) {

我认为在 INVALID 情况下也是如此.

I think same in INVALID case.

但我仍然不确定这是否正确.

But I'm still not sure if this is right.

这就是问题所在?或者我可能需要改变其他东西?我是否必须同时使用 if 条件(if == 0if !== false)?PayPal 刚刚更改了 VERIFIED 返回值?

That was the problem? Or may I have to change something else? May I have to use both if conditions (if == 0 and if !== false)? PayPal Just changed VERIFIED return value?

推荐答案

我遇到了类似的问题,修复如下:

I had a similar problem, fixed as follows :

有时,当我的听众发回 cmd=_notify-validate 以检查新的 IPN 时,您会得到除VERIFIED"或INVALID"以外的其他信息.

From time to time, when my listener posts back the cmd=_notify-validate to check a new IPN, you'll get something other than "VERIFIED" or "INVALID" back.

有时我会这样:

'8'.chr(13).chr(10).'VERIFIED'.chr(13).chr(10).'0'.chr(13).chr(10).chr(13).chr(10)

'8'.chr(13).chr(10).'VERIFIED'.chr(13).chr(10).'0'.chr(13).chr(10).chr(13).chr(10)

有时我会这样:

'00000008'.chr(13).chr(10).'VERIFIED'.chr(13).chr(10).'00000000'.chr(13).chr(10).chr(13).chr(10))

'00000008'.chr(13).chr(10).'VERIFIED'.chr(13).chr(10).'00000000'.chr(13).chr(10).chr(13).chr(10))

我认为如果除了VERIFIED"或INVALID"之外还检查这两个字符串,你会没事的.如果没有,请告诉我您从 paypal 中得到了什么,但没有通过 stripos($res, "VERIFIED") 和 stripos($res, "INVALID") 测试.

I think if you check for those two strings in addition to "VERIFIED" or "INVALID" you'll be fine. If not, show me what you ARE getting back from paypal that is failng your stripos($res, "VERIFIED") and stripos($res, "INVALID") tests.

另外值得注意的是,我有时会从中间缓存或我的 ISP 中收到错误,或者 paypal 只是超时..所以您的代码需要能够通过稍后对该 IPN 执行 cmd=_notify-validate 来从中恢复.

Also worth noting I sometimes get an error from an intermediate cache or my ISP, or paypal just times out.. so your code needs to be able to recover from that by doing cmd=_notify-validate for that IPN later.

最后...我多年来一直在努力使用 IPN 系统.它总是有点不可靠,文档在几个地方严重错误,并且 IPN 滞后于交易,通常滞后 15 分钟或更长时间.

Lastly... I struggled with IPN systems for many years. It's always a bit unreliable, the documentation is seriously wrong in a couple of places, and IPNs lag behind transactions, often by 15 minutes or more.

我发现使用 API 的 TransactionSearch 和 GetTransactionDetails 方法要好得多.

I have found it is far better is to use the TransactionSearch and GetTransactionDetails methods of the API.

此处的文档:

https://developer.paypal.com/docs/classic/api/merchant/GetTransactionDetails_API_Operation_NVP/

https://developer.paypal.com/docs/classic/api/merchant/TransactionSearch_API_Operation_NVP/

这些是可靠的,并且延迟更少.我有一个 cron 作业,每 15 分钟运行一次,以使用这些方法检查新事务.每次收到 IPN 时,我也会运行新的事务检查.如果您需要有关实施的进一步指导,请告诉我.

These are reliable and have much less lag. I have a cron job that runs every 15 minutes to check for new transactions using those methods. I also run the new transaction check every time I receive an IPN. Let me know if you want further guidance on implementing.

这篇关于PayPal IPN 侦听器将不再工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆