[英]Paypal IPN script not working
For some reason my script connects to the database and has no errors however nothing in the database seems to update. 由于某种原因,我的脚本连接到数据库并且没有错误,但是数据库中的任何内容似乎都没有更新。 I cannot find anything wrong with it.
我找不到任何问题。 Here is my code:
这是我的代码:
// 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'];
$user_id = mysql_real_escape_string($_POST['custom']);
$today = date("F j, Y, g:i a");
echo "hi";
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($payment_status=='Completed') {
$txn_id_check = mysql_query("SELECT 'txn_id' FROM 'log' WHERE 'txn_id' ='".$txn_id."'");
if (mysql_num_rows($txn_id_check) !=1) {
if ($receiver_email=='HiddenForStackQuestion') {
if ($payment_amount=='29.95' && $payment_currency=='USD') {
$log_query = mysql_query("INSERT INTO 'log' VALUES ('','".$txn_id."','".$payer_email."')");
$update_premium = mysql_query("UPDATE 'users' SET authLevel='1', startDate='".$today."' WHERE 'fbID'='".$user_id."'");
}
}
}
}
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
And Here is my button. 这是我的按钮。
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="hiddenForStackQuestion">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="hiddenForStackQuestion">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="hiddenForStackQuestion">
<input type="hidden" name="cancel_return" value="hiddenForStackQuestion">
<input type="hidden" name="src" value="1">
<input type="hidden" name="a3" value="29.95">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="notify_url" value="hiddenForStackQuestion" />
<input type="hidden" name="custom" value="<?php echo $userId ?>" />
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-SubscriptionsBF:btn_subscribeCC_LG.gif:NonHosted">
<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!" style="border:none;">
</form>
I have been on this for awhile but am having no luck. 我已经有一段时间了,但是没有运气。 Anyone see what is wrong?
有人看错了吗?
This 这个
<input type="hidden" name="notify_url" value="hiddenForStackQuestion" />
Doesn't happen to be hosted on localhost, I hope? 我希望不是托管在localhost上吗? An IPN POST is initiated by PayPal's servers, and as such must be a FQDN.
IPN POST由PayPal的服务器启动,因此必须是FQDN。 localhost won't work.
本地主机无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.