php - 我在尝试获取 PayPal IPN 订阅 ID 时遇到了最困难的时间

标签 php paypal paypal-ipn

我在尝试获取 PayPal IPN 订阅 ID 时遇到了困难。这是我的 IPN 页面。

<?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) {
// 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("susbcr_signup" == $_POST['txn_type']){

      $_id = $_POST['subscr_id'];



    $websites= "websites";
    $database = "k29803_1";
   mysql_connect("localhost", $username, $password) or die(mysql_error());
   mysql_select_db($database);

  $query = "SELECT * FROM users WHERE username= 'drahoslava' AND password = 'drah0slava'";
  $results = mysql_query($query)or die(mysql_error());
    if(mysql_num_rows($results)==1){
        $add_credits = "UPDATE users SET hash = '$_id'
        WHERE username= 'drahoslava' AND password = 'drah0slava'";
        mysql_query($add_credits) or die(mysql_error());
      echo 'done';


      }

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
  }
  ?>

这是我的表格

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="6ZZUDQCUUXGMS">
  <input type="hidden" name="item_name" value="Baseball Hat Monthly">
  <input type="hidden" name="item_number" value="123">
<input type="hidden" name="notify_url" value="http://www.germcode.kodingen.com/ipn.php" />

<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Mysql 表不更新.. 可能是什么问题。 *我有自动返回

最佳答案

抱歉,这不是一个真正的答案,但我无法将我的建议正确地纳入评论

尝试设置一个额外的表用于测试目的,该表将接收每个事务的 ipn 信息的原始转储。然后,您可以查看收到的内容以确定未将其插入到您的表中的原因。

要存储所有原始数据,您可以这样做:

$IpnSerialized = serialize($_POST);
$RawInsert = "INSERT INTO `IpnRaw` (`IpnDump`) VALUES ('{$IpnSerialized}')";

此外,不要向 IPN 处理程序脚本添加任何回显或打印。无论如何都不会有人看到它。

您可能想在测试表中添加一些额外的字段,您可以在其中存储进度标记,以查看您的脚本在爆炸之前达到了多远。

关于php - 我在尝试获取 PayPal IPN 订阅 ID 时遇到了最困难的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7898739/

相关文章:

php - 在codeigniter中使用两个文件上传按钮

php - Laravel 中 hasMany 和 ownToMany 之间的关系

php - 从哪里开始将 Paypal 集成到我的事件网站?

Facebook 上 iFrame 中的 Paypal

javascript - 为什么 PayPal 无法识别我的 Items Array?

Paypal REST API 和拒付/取消

paypal - 无法获得要识别的新 Paypal SSL CA 证书。与沙盒的握手失败

PayPal - 付款人可以与订户不同吗?

php - ajax php 下拉列表

javascript - jQuery 是在电子商务网站中处理产品变化计算的可接受方法吗?