用paypal通知网址苦苦挣扎

时间:2015-03-05 01:51:39

标签: php paypal

我已经在这里工作了很长时间,从这里阅读了无数的教程,指南等,而PayPal没有运气!

我在我的网站上设置了paypal购买按钮。通过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" height="22" type="image" width="156" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

creditsdone.php只是说&#34;感谢您的购买。&#34;购买成功后,您可以恢复此功能。

然而,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");

   }else{echo"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很新,完全卡住所以任何帮助或提示都会非常感激!!

谢谢!

1 个答案:

答案 0 :(得分:-1)

问题出在这里

mysql_query("UPDATE r$credit_games 

更改为

 mysql_query("UPDATE credit_games

或者您的查询名称是什么。

它必须是credit_games你有$给出错误所以请暂停,睡几个小时然后继续工作hehehe。