关于IPN确认

时间:2012-03-04 19:08:20

标签: php paypal paypal-ipn

一直在尝试将PayPal整合到我的网站中,但没有任何运气......我已经使用沙箱来检查我的付款...它确实需要付款但是在通知我的服务器端程序时它没有这样做..我在我的服务器端php文件中使用了IPN示例代码,该文件是在沙箱中定义的,我使用的是我自己的url,这是在godaddy中托管的...只是为了检查我是否已经使用会话来调用,以便通知返回它会设置一个会话,但它仍然没有添加任何会话......现在有一个实时难度....这里是我一直在使用的代码。

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
session_start();
    if($mode=='live')
    {
        $url=" https://www.paypal.com/cgi-bin/webscr";
        $email="fghsdfg";
        $_SESSION['url']=$url;
        $_SESSION['email']=$email;
        $_SESSION['subtotal']=$subtotal;
    }
    else if($mode=='sandbox')
    {
        $url= "https://www.sandbox.paypal.com/cgi-bin/webscr";
        $email="nilesh_1329707350_biz@gmail.com";
        $_SESSION['url']=$url;
        $_SESSION['email']=$email;
        $_SESSION['subtotal']=$subtotal;
    }
    ?>

                    <form action="<?php echo $url; ?>" method="post">
                    <input type="hidden" name="cmd" value="_xclick"/>
                    <input type="hidden" name="business" value="<?php echo $email; ?>"/>
                    <input type="hidden" name="item_name" value="shopping cart"/>
                    <input type="hidden" name="currency_code" value="GBP"/>
                    <input type="hidden" name="amount" value="<?php echo $subtotal;?>"/>
                    <input type="hidden" name="return" value="<?php echo SITE_URL; ?>"/>
                    <input type="hidden" name="cancel_return" value="<?php echo SITE_URL."/shoppingCart.php" ?>"/>
                    <input type="hidden" name="notify_url" value="http://my website url where the php file is " />
                    <input type="hidden" name="rm" value="2"/>
                    <input type="hidden" name="custom" value="<?php echo $customer_ID;?>"/>
                    <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
                    </form>`

在我的PHP文件中,我有这个代码

<?php


// 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
$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.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$_SESSION['hello']="hello";
// PAYMENT VALIDATED & VERIFIED!

}

else if (strcmp ($res, "INVALID") == 0) {

// PAYMENT INVALID & INVESTIGATE MANUALY!

}
}
fclose ($fp);
}
?>

哪个来自IPN示例代码。我真的很感激,如果有人能告诉我为什么这不起作用。

0 个答案:

没有答案