简体   繁体   English

贝宝IPN脚本不起作用

[英]PayPal IPN script is not working

So i recently created PayPal IPN script, but while I was testing it with Sandbox (test) accounts, I saw problem, everything was excellent, except it just didn't insert any data in database, well verified part just didn't work, neather did INVALID part, didn't work. 因此,我最近创建了PayPal IPN脚本,但是当我使用沙盒(测试)帐户对其进行测试时,我看到了问题,一切都非常好,除了它只是没有在数据库中插入任何数据,经过良好验证的部分只是行不通, neather做了无效的部分,没有用。 You can take a look on my script here - 您可以在这里查看我的脚本-

<?php
// PHP 4.1

// 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);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
  if($receiver_email == 'test_1318600337_biz@gmail.com')
  {
      include('../database.php');
      $result = mysql_query("SELECT * FROM `smscodes` WHERE code = '$item_number';");
      $select_id = mysql_fetch_array($result);
      mysql_query('UPDATE `advertisements` SET status="accepted" WHERE id = "'.$select_id['adv-id'].'"');
      mysql_query("DELETE FROM `smscodes` WHERE `code` = '".$item_number."' LIMIT 1");
  }
}
else if (strcmp ($res, "INVALID") == 0) {
$to = 'myemailishere@myemailishere.com';
 mail($to, "Error, something is wrong with paypal script", "Error, something is wrong with paypal script");
}
}
fclose ($fp);
}
?>

And my button is - 我的按钮是-

  <form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" 
      method="post">
      <input type="hidden" name="cmd" value="_xclick">
      <input type="hidden" name="business" value="test_1318600337_biz@gmail.com">
      <input type="hidden" name="currency_code" value="EUR">
      <input type="hidden" name="item_name" value="Add Advertisement">
      <input type="hidden" name="amount" value="3.00">
      <input type="hidden" name="item_number" value="<?php echo $_SESSION['code']; ?>">
      <input type="hidden" name="return" value="http://site.com">
      <input type="hidden" name="notify_url" value="mysite.com/tsatstastast/ipn.php">
      <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" 
          border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
  </form>

In PayPal IPN history it shows succeed with HTTP 200, but I don't have any clues why it doesn't insert anything inside database. 在PayPal IPN历史记录中,它显示了HTTP 200的成功,但是我没有任何线索为什么它没有在数据库中插入任何内容。 database.php file is okay, and it got all information of database inside. database.php文件还可以,并且它包含数据库的所有信息。 Hope you can help me with this problem. 希望你能帮助我解决这个问题。 EDIT: Forgot to mention, with PayPal Test tool, where you insert IPN script code, and it verifies if it is working, everything worked great. 编辑:忘记了,使用PayPal测试工具,您可以在其中插入IPN脚本代码,并验证它是否正常工作,一切都很好。 But with button, and test account it doesn't. 但是使用按钮,而测试帐户则没有。 Oh and smscodes table, it's correct, I'm using same table for paypal and sms payments, so no worries about it ;)! 哦,还有smscodes表,这是正确的,我在贝宝和sms付款中使用了同一个表,所以不用担心;)! EDIT: Tried to change to ssl://www.sandbox.paypal.com but without chance, now ill try to debug it . 编辑:试图更改为ssl://www.sandbox.paypal.com,但没有机会,现在请尝试对其进行调试。 EDIT 3: So I just found the error, it was In paypal sandbox account setting, didn't turn on notificy messages. 编辑3:所以我只是发现错误,这是在Paypal沙箱帐户设置中,没有打开通知消息。 Now i got one message that says mail($to, "Error, something is wrong with paypal script", "Error, something is wrong with paypal script"); 现在我收到一条消息,上面写着邮件($ to,“错误,贝宝脚本有问题”,“错误,贝宝脚本有问题”); , so it failed. ,所以失败了。 What to do, any help would be appreciated! 怎么办,任何帮助将不胜感激! Best regards, Valters 最好的问候,Valters

May it be that you use sandbox url on the form and in the listener you use the official paypal url... You have to use the same url. 可能是您在表单上使用了沙箱网址,而在侦听器中使用了官方的贝宝网址...您必须使用相同的网址。

here 这里

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

and here 和这里

form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 表单名称=“ _ xclick”操作=“ https://www.sandbox.paypal.com/cgi-bin/webscr” method =“ post”>

Try debugging it with the values fsockopen() provides: 尝试使用fsockopen()提供的值对其进行调试:

$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp)
{
    echo $errstr . ' (' . $errno . ')';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM