苦苦挣扎的贝宝通知网址
Posted
技术标签:
【中文标题】苦苦挣扎的贝宝通知网址【英文标题】:Struggling with paypal notify url 【发布时间】:2015-05-06 06:40:46 【问题描述】:我已经在这里工作了很长时间,从这里阅读了无数的教程、指南等,但没有运气!
我在我的网站上设置了一个贝宝购买按钮。使用 Paypal 的沙箱对此进行了测试后,付款部分可以正常工作。然而,在返回网站时,它并没有给用户他们购买的东西!
这是在他们可以选择购买的页面上:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="custom" value="<?=$person?>">
<input type="hidden" name="business" value="myemail@email.com">
<input type="hidden" name="item_name" value="5000 Credits for <?=$person?>">
<input type="hidden" name="item_number" value="5000 Credits">
<input type="hidden" name="amount" value="5.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="notify_url" value="<?=$site[location]?>ipn.php">
<input type="hidden" name="return" value="<?=$site[location]?>creditsdone.php">
<input type="hidden" name="cancel_return" value="<?=$site[location]?>">
<input src="images/buy_button.gif" type="image" name="submit" >
</form>
creditsdone.php 只是说“感谢您的购买”。这有效,因为您在购买成功后会返回此内容。
但是 ipn.php 页面不起作用。在返回网站时,不会向玩家帐户添加任何积分。
ipn.php页面如下:
<?
include("funcs.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 ('www.paypal.com', 80, $errno, $errstr, 30);
// assign posted variables to local variables
// note: additional IPN variables also available -- see IPN documentation
/*$item_name = $_POST['item_name'];
$receiver_email = $_POST['receiver_email'];
$item_number = $_POST['item_number'];
$invoice = $_POST['invoice'];
$payment_status = $_POST['payment_status'];
$payment_gross = $_POST['payment_gross'];
$txn_id = $_POST['txn_id'];
$payer_email = $_POST['payer_email'];
*/
if (!$fp)
// ERROR
echo "$errstr ($errno)";
else
fputs ($fp, $header . $req);
while (!feof($fp))
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
echo "<pre>";
print_r($_POST);
if($_POST[payment_status]=="Completed")
if ((!fetch("SELECT tranid FROM $tab[paypal] WHERE tranid='$txn_id';")) && ($business == "myemail@email.com"))
$subexpire = time()+864000;
if($payment_gross == "5.00")$turns="5000";
elseif($payment_gross == "10.00")$turns="7250";
elseif($payment_gross == "25.00")$turns="10000";
elseif($payment_gross == "50.00")$turns="12500";
elseif($payment_gross == "100.00")$turns="25000";
elseif($payment_gross == "200.00")$turns="57500";
elseif($payment_gross == "300.00")$turns="90000";
elseif($payment_gross == "400.00")$turns="132500";
elseif($payment_gross == "500.00")$turns="180000";
elseif($payment_gross == "1000.00")$turns="400000";
elseif($payment_gross == "15000.00")$turns="700000";
else$turns="0";
$expires=$time+864000;//10 days
$total=$payment_gross-$payment_fee;
//update database to add turns to user in game they bought for
mysql_query("UPDATE $tab[user] SET status='supporter', statusexpire='$expires', credits=credits+$turns WHERE username='$custom'");
//insert into database paypal information
$buying_user = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '". $custom ."'"));
$time = time();
$fetch_the_games = mysql_query("SELECT * FROM games WHERE starts < $time AND ends > $time");
while($credit_games = mysql_fetch_array($fetch_the_games))
mysql_query("UPDATE r$credit_games[round]_pimp SET status = '". supporter ."' WHERE code = '". $buying_user[code] ."'");
mysql_query("INSERT INTO $tab[paypal] (tranid,amount,fee,user,datebought) VALUES ('$txn_id','$payment_gross','$payment_fee','$custom','$time');");
//send email to admin about transaction from paypal--ADMIN-check database to make sure transaction went through to game
mail_2("$turns credits where bought!","\nDear Admin,\n\nYou just received a payment from $custom for $turns credits\n\nCost: $$payment_gross\nFee: $$payment_fee\n----------\nTotal: $$total","myemail@email.com");
elseecho"Cannot refresh transaction!";
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is an email address in your PayPal account
// process payment
else if (strcmp ($res, "INVALID") == 0)
// log for manual investigation
fclose ($fp);
?>
我知道这看起来很混乱,我对 php 很陌生,完全被卡住了,所以任何帮助或提示将不胜感激!
谢谢!
【问题讨论】:
你为调试ipn.php做了什么?确认它的命中,确认值,确认数据库查询... 在testing PayPal IPN 上查看本指南,您应该能够找到您的问题。 谢谢安德鲁,我会看看。另外,对不起,Dagon,我对编码很陌生。我从不久前购买的一个脚本中获得了上述内容,并且在我自学 php 时一直在慢慢添加它。我了解基础知识,但上面的代码有点过头了!我不太清楚你所说的调试 ipn.php 是什么意思? 您需要学习 50 多种可能性来调试、回显和检查每个变量、每个查询 【参考方案1】:问题来了
mysql_query("UPDATE r$credit_games
改成
mysql_query("UPDATE credit_games
或任何您的查询名称。
一定是 credit_games 你给 $ 的错误,所以请暂停一下,睡几个小时,然后继续工作,呵呵。
【讨论】:
不,因为他使用来自 IPN 的返回值而不是返回 url 我想我在这里找到了错误 mysql_query("UPDATE r$credit_games it must be credit_games you have a $giving error 谢谢罗德里戈,我再试一次!以上是关于苦苦挣扎的贝宝通知网址的主要内容,如果未能解决你的问题,请参考以下文章