0

我正在使用 paypal IPN 处理来自网站的付款,一切正常,我收到了经过验证的回复并相应地更新了我在数据库中的订单。我遇到的问题是它正在发送多个 IPN 响应。

我知道这可能是因为贝宝在收到我的回调时没有收到 200 响应。

从我所看到的一切都很好。无论如何“欺骗” 200 响应,或者任何人都可以弄清楚为什么我的回调没有发送 200 响应?

这是我的回调:

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

        //FH capture the callback in the callback table
        $callback = "";

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

        Payment::insert_callback($callback);

        // post back to PayPal system to validate
        $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";

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

        // $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
        $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

        $item_name = (isset($_POST['item_name']))? $_POST['item_name'] : $_POST['item_name1'];
        $item_number = (isset($_POST['item_number']))? $_POST['item_number'] : $_POST['item_number1'];
        $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) 
        {

        } 
        else 
        {
            fputs ($fp, $header . $req);
            while (!feof($fp)) 
            {
                $res = fgets ($fp, 1024);
                $res = trim(str_replace('\n', '', $res));
                if (strcmp ($res, "VERIFIED") == 0)
                {
                        Payment::insert_callback('VERIFIED');
                        Payment::update_listing_history($item_number, 1, $callback);
                }
                else if (strcmp ($res, "INVALID") == 0)
                {
                    Payment::insert_callback('INVALID');
                }
            }
            fclose ($fp);
        }
4

0 回答 0