我在尝试获取 PayPal IPN 订阅 ID 时遇到了最困难的时刻
我在尝试获取 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 表没有更新。可能是什么问题。 *我有自动返回功能
I'm having the most difficult time trying to get the PayPal IPN subscription Id. This is my IPN page.
<?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);
}
}
?>
This is my form
<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>
The Mysql Table doesnt update.. What could be the problem. *I do have auto return on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,这并不是真正的答案,但我无法正确地将我的建议纳入评论中。
尝试设置一个额外的表用于测试目的,该表将接收每笔交易的 ipn 信息的原始转储。然后,您可以查看收到的内容,以确定其未插入表中的原因。
要存储所有原始数据,您可以这样做:
另外,不要向 IPN 处理程序脚本添加任何回显或打印。无论如何,没有人会看到它。
您可能需要向测试表添加一些额外的字段,您可以在其中存储进度标记,以查看脚本在崩溃之前已经进行了多远。
Sorry this isn't really an answer per-say but I couldn't get my suggestion into a comment properly
Try setting up an extra table for testing purposes that will receive a raw dump of the ipn information for each transaction. You can then take a look at what was received to determine why it is not being inserted in your table.
To store all of the raw data you can do like so:
Also, don't add any echos or prints to the IPN handler script. No one is going to see it anyway.
You might want to add some extra fields to the test table where you can store progression markers to see how far your script is getting before bombing out.
尝试通过电子邮件发送您从 PayPal 返回的 IPN 数据,看看是否可以获取数据。如果您可以获取数据,则问题出在您的查询中。
Try to do an email the ipn data which you are getting back from paypal and see if you can get data. If you can get data then problem is in your query.