贝宝:无效的IPN问题 [英] Paypal: Invalid IPN problem

查看:116
本文介绍了贝宝:无效的IPN问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道SO中已经有很多与我的问题相关的问题,但是我还没有得到任何解决方案.我已经实施了贝宝.运行良好.现在,我想在我的Paypal实现中实现ipn.我搜索了一下,发现了一些代码.我已经实现了,但是我得到了无效的ipn.我可以从Paypal交易中获取所有详细信息,但对于ipn总是无效的.我在DoExpressCheckoutPayment.php文件中使用了以下代码

Hi I know that there are many questions already in SO related to my problem but I have not got solution from any of them. I have implemented paypal. It is working well. Now I want to implement ipn in my paypal implementation. I have searched through and found some code. I have implemented that but I am getting invalid ipn. I can get all details from paypal transaction but for ipn it is always invalid. I have used following code in DoExpressCheckoutPayment.php file

$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";

// If testing on Sandbox use: 
$header .= "Host: www.sandbox.paypal.com:443\r\n";
//$header .= "Host: www.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp =fsockopen('ssl://www.sandbox.paypal.com',443,$err_num,$err_str,30);
echo('<br>'.$req);
// assign posted variables to local variables
/*$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];*/

if (!$fp)
{
    echo(' HTTP ERROR');
}
else
{
    fputs ($fp, $header . $req);
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        echo('<br> res is '.$res);
    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

        $mail_From = "From: me@mybiz.com";
        $mail_To = "xxxx@gmail.com";
        $mail_Subject = "VERIFIED IPN";
        $mail_Body = $req;
        foreach ($_SESSION as $key => $value)
        {
            $emailtext .= $key . " = " .$value ."\n\n";
        }
        if(mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From))
        echo('<br>mail 1 sent');
        else
        echo('<br>mail1 not sent');
    }
    else if (strcmp ($res, "INVALID") == 0)
    {
        // log for manual investigation
        $mail_From = "From: me@mybiz.com";
        $mail_To = "xxx@gmail.com";
        $mail_Subject = "INVALID IPN";
        $mail_Body = $req;
        foreach ($_SESSION as $key => $value)
        {
            $emailtext .= $key . " = " .$value ."\n\n";
        }
        if(mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From))
        echo('<br>mail sent');
        else
        echo('<br>not sent');
    }
}
fclose ($fp);
}

我正在其他文件中设置notify_url,而该文件是指向这样的文件

I am setting notify_url in other file which is directing to this file like this

&lt;input type="hidden" name="notify_url" value="http://www.mysite.com/paypal/DoExpressCheckoutPayment.php"/>

我收到以下电子邮件:

**notify_url = http://www.mysite.com/paypal/DoExpressCheckoutPayment.php
cmd=_notify-validate&notify_url=http%3A%2F%2Fwww.mysite.com%2Fpaypal%2FDoExpressCheckoutPayment.php**

有一件事,我注意到我没有从$ _POST得到任何东西.我的$ _POST为空. 请告诉我我错了. 谢谢

One thing that I have notice that I am not getting any thing from $_POST. My $_POST is empty. Please tell me where I am wrong. Thanks

推荐答案

在此处尝试此代码.它与您上面使用的略有不同.它对我有用.

Try this code here. It is slightly different to the one you used above. It works for me.

    <?php
    $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
    $item_name          = $_POST['item_name'];
    $item_number        = $_POST['item_number'];
    $payment_status     = $_POST['payment_status'];
    $payment_amount     = $_POST['mc_gross'];
    $payment_currency   = $_POST['mc_currency'];
    $txn_id             = $_POST['txn_id'];
    $receiver_email     = $_POST['receiver_email'];
    $payer_email        = $_POST['payer_email'];

    if (!$fp) {

        // HTTP ERROR

    } else {
        fputs ($fp, $header . $req);
            while (!feof($fp)) {
            $res = fgets ($fp, 1024);
            if (strcmp ($res, "VERIFIED") == 0) {
                //Process Order
            }else if (strcmp ($res, "INVALID") == 0) {
                //Send Email To You 
            }
        }

        fclose ($fp);
    }
    ?>

这篇关于贝宝:无效的IPN问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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