Paypal IPN Sandbox无法正常工作

时间:2013-08-26 01:30:21

标签: php paypal paypal-ipn

我一直在搜索论坛但是没有运气使用Sandbox IPN来获得回复。 我已经遵循了许多提示,但无法使事情正常工作 - 看起来像www.sandbox.paypal.com没有工作/响应,好像我使用生产我得到了IPN无效的响应按预期。您可以在下面的示例中看到注释掉的代码行。

有没有人知道为什么这可能不起作用?

<?php 
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', '1'); 
$email = "paypal.admin@exampleurl.com"; 
$header = ""; 
$emailtext = ""; 
// Read the post from PayPal and add 'cmd' 
$req = 'cmd=_notify-validate'; 

if(function_exists('get_magic_quotes_gpc')) 
{ 
    $get_magic_quotes_exits = true;
} 

foreach ($_POST as $key => $value) // Handle escape characters, which depends on setting of magic quotes 
{ 
    if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) 
    { 
        $value = urlencode(stripslashes($value)); 
    } else { 
        $value = urlencode($value); 
    } 
    $req .= "&$key=$value"; 
} 

// Post back to PayPal 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"; 
*/

$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";  // www.paypal.com for a live site
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n\r\n";

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

// Process validation from PayPal 
if (!$fp) { 
// HTTP ERROR 
} else { 
// NO HTTP ERROR 
    fputs ($fp, $header . $req); 

    while (!feof($fp)) { 
         $res = fgets ($fp, 1024); 
         if (stripos($res, "VERIFIED") !== false){
         //if (strcmp ($res, "VERIFIED") == 0) { 
             // TODO: 
             // 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 
            // If 'VERIFIED', send an email of IPN variables and values to the 
            // specified email address 
            foreach ($_POST as $key => $value){ 
            $emailtext .= $key . " = " .$value ."\n\n"; 
            } 
            mail($email, "Live-VERIFIED IPN", $emailtext . "\n\n" . $req); 
        //} else if (strcmp ($res, "INVALID") == 0) { 
        } else if (stripos($res, "VERIFIED") !== false){
        // If 'INVALID', send an email. TODO: Log for manual investigation. 
            foreach ($_POST as $key => $value){ 
                $emailtext .= $key . " = " .$value ."\n\n";
            } 
            mail($email, "Live-INVALID IPN", $emailtext . "\n\n" . $req); 
        } 

    } 
    fclose ($fp);
}

&GT;

0 个答案:

没有答案