【问题标题】:paypal IPN php script贝宝 IPN php 脚本
【发布时间】:2012-09-29 08:59:49
【问题描述】:

我刚刚意识到我在 php 中的 paypal ipn 处理程序不再工作(我什么也没做),我使用 the sample php script provided by paypal.

我尝试通过多次测试来隔离问题,此时我可以说问题不是“VERIFIED”或“INVALID”,而是来自以下几行:

[...]

fputs ($fp, $header . $req);
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0)
        {
        // check the payment_status is Completed

[...]

有人知道paypal是否改变了某些东西或为什么它不起作用?

谢谢'

ps:如果我将代码放在所有 paypal 测试之前(“if (!$fp)”行之前),它就可以正常工作

这是我的代码,我评论了“数据库进程”在哪里工作,哪里不工作。

<?php

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value)
{
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$payment_status = $_POST['payment_status'];


// DATABASE PROCESS WORKS (BEFORE THE PAYPAL TESTS)



if (!$fp)
{
    // HTTP ERROR
}
else
   {

// DATABASE PROCESS WORKS

    fputs ($fp, $header . $req);
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0)
        {
            // check the payment_status is Completed
            // check that txn_id has not been previously processed
            // check that receiver_email is your Primary PayPal email
            // check that payment_amount/payment_currency are correct
            // process payment


// DATABASE PROCESS NOT WORKING

        }
        else if (strcmp ($res, "INVALID") == 0)
        {
            // log for manual investigation

// DATABASE PROCESS NOT WORKING
        }
    }
fclose ($fp);
}

?>

【问题讨论】:

  • 你检查过关于这个问题的error_log吗?
  • 请问如何查看error_log?

标签: php paypal handler paypal-ipn


【解决方案1】:

尝试在 x.xom 上使用更新后的脚本 https://www.x.com/instant-payment-notification-4

它使用 CURL 而不是 fsock

【讨论】:

    【解决方案2】:

    当服务器未正确配置套接字或未配置 openSSL 模块时发生此错误。

    或

    您可以尝试使用以下代码示例,使用 file_get_contents 代替 $fp 代码

    <?php
    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';
    
    foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }
    
    // for live mode
    $url="https://www.paypal.com/cgi-bin/webscr";
    // for developement mode
    $url="https://www.sandbox.paypal.com/cgi-bin/webscr";
    
    // instead of use of fopen you can use
    $res=file_get_contents($url"?".$req);
    // compare response
    if (strcmp (trim($res), "VERIFIED") == 0) {
    // check the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct
    // process payment
    }
    else if (strcmp (trim($res), "INVALID") == 0) {
    // log for manual investigation
    }
    
    ?>
    

    如果 file_get_contents 不起作用,那么您可以使用 CURL 获取响应...

    如果有任何问题,请告诉我?

    谢谢

    【讨论】:

    • 我试过你的脚本,但它根本不适合我,即使我把“数据库进程”放在“验证”测试之前。这是我的脚本,也许你会找到一个错误:pastebin.com/XFLuQKnG我在评论中写了数据库进程正在工作的地方
    • 您只需在x.com/instant-payment-notification-4使用新的贝宝脚本
    猜你喜欢
    • 2013-01-04
    • 2015-06-16
    • 2012-01-07
    • 2014-06-30
    • 2013-03-06
    • 2013-03-23
    • 2012-08-06
    • 2016-05-09
    • 2023-03-11
    相关资源
    最近更新 更多