0

我正在尝试从 PayPal IPN 获取详细信息并显示交易是否已被验证。我正在使用下面的代码,如果它被取消,它会显示失败,这是正确的,但即使交易成功,它仍然显示失败。请提供此代码出错的任何想法

    //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 (replaces old headers)
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
//

//error connecting to paypal
if (!$fp) {
    //
}

//successful connection    
if ($fp) {
    fputs ($fp, $header . $req);

    while (!feof($fp)) {
        $res = fgets ($fp, 1024);
        $res = trim($res); //NEW & IMPORTANT

        if (strcmp($res, "VERIFIED") == 0) {
            //insert order into database    
            echo'Success';
        }

        if (strcmp ($res, "INVALID") == 0) {
            //insert into DB in a table for bad payments for you to process later
            echo'Failed';
        }
    }

    fclose($fp);
}
4

0 回答 0