dongxi7609 2013-06-16 16:25 采纳率: 0%
浏览 32

paypal ipn listener错误

I'm implementing an IPN listener for Paypal Adaptive Payments, I downloaded the sample code from here:

https://cms.paypal.com/cms_content/IT/it_IT/files/developer/IPN_PHP_41.txt

Then I made a transaction (with sandbox) but I think the sample is wrong because the code returns some errors in my error_log file:

[16-Jun-2013 16:11:34 UTC] PHP Warning:  stripslashes() expects parameter 1 to be string, array given in /var/www/actions/IPNListener.php on line 7
[16-Jun-2013 16:11:34 UTC] PHP Notice:  Undefined variable: header in /var/www/actions/IPNListener.php on line 12
[16-Jun-2013 16:11:34 UTC] PHP Notice:  Undefined index: item_name in /var/www/actions/IPNListener.php on line 18

The Undefined index is not only "item_name" but ALL INDEXES!!!!!

The transaction works correctly and the IPN is called by paypal automatically after the transaction...but the paypal sample code does not work at all! Do you know how to fix it?

  • 写回答

1条回答 默认 最新

  • duanmie9682 2013-06-16 16:34
    关注

    Try this one

    <?php
    //Build the data to post back to Paypal
    $postback = 'cmd=_notify-validate'; 
    
    // go through each of the posted vars and add them to the postback variable
    foreach ($_POST as $key => $value) {
       $value = urlencode(stripslashes($value));
       $postback .= "&$key=$value";
    }
    
    // build the header string to post back to PayPal system to validate
    $header = "POST /cgi-bin/webscr HTTP/1.0
    ";
    $header .= "Content-Type: application/x-www-form-urlencoded
    ";
    $header .= "Content-Length: " . strlen($postback) . "
    
    ";
    
    // Send to paypal or the sandbox depending on whether you're live or developing
    // comment out one of the following lines
    //$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);//open the connection
    $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
    // or use port 443 for an SSL connection
    //$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
    
        if (!$fp) 
        {
            // HTTP ERROR Failed to connect
            //error handling
        }
        else // if we've connected OK
        {
            fputs ($fp, $header . $postback);//post the data back
            while (!feof($fp)) 
            {
                $response = fgets ($fp, 1024);
    
                if (strcmp ($response, "VERIFIED") == 0) //It's verified
                {
                    //do something
                }
                else if (strcmp ($response, "INVALID") == 0) 
                { 
                    //the Paypal response is INVALID, not VERIFIED
                    // This implies something is wrong
                }
            } //end of while
            fclose ($fp);
        }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据