duanqiang9212 2013-08-26 01:30
浏览 38

Paypal IPN Sandbox无法正常工作

I've been searching the forums but have had no luck using Sandbox IPN to get a response. I've followed many tips but can't get things working - it looks like the www.sandbox.paypal.com isn't working/responding as if I use production I get an IPN Invalid response as expected. You can see the commented out lines of code in my example below.

Does anyone have any idea why this may not be working?

<?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
"; 
$header .= "Content-Type: application/x-www-form-urlencoded
"; 
$header .= "Content-Length: " . strlen($req) . "

"; 
*/

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

";

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

"; 
            } 
            mail($email, "Live-VERIFIED IPN", $emailtext . "

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

";
            } 
            mail($email, "Live-INVALID IPN", $emailtext . "

" . $req); 
        } 

    } 
    fclose ($fp);
}

?>

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题