我有一个带有帐户系统的网站。我正在销售一些服务。我正在使用贝宝动态订阅按钮进行销售。我的问题是,当 IPN 从 paypal 发回时,我怎么知道是哪个用户付款的?我有一个将付款信息发送到贝宝的工作脚本和另一个从贝宝接收信息并将其插入数据库的脚本,但我不知道如何知道哪个用户发送了付款。我正在寻找如何实现这一点的想法。
发送按钮:
<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="user@example.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="1">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="a3" value="<?php echo $pay_value; ?>">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
</form>
ipn脚本:
<?php
// tell PHP to log errors to ipn_errors.log in this directory
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');
// intantiate the IPN listener
include('include/ipnlistener.php');
include('include/conn.php');
$listener = new IpnListener();
// tell the IPN listener to use the PayPal test sandbox
$listener->use_sandbox = true;
// try to process the IPN POST
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
} catch (Exception $e) {
error_log($e->getMessage());
exit(0);
}
if ($verified) {
$errmsg = ''; // stores errors from fraud checks
// Make sure the payment status is "Completed"
if ($_POST['payment_status'] != 'Completed') {
}
exit(0);
}
if ($_POST['txn_type'] == 'subscr_eot') {
$link = mysql_connect($conn_host,$conn_user,$conn_pass) or die('Connection to mysql failed!');
mysql_select_db($conn_db,$link) or die('Connection to database failed!');
$sql = mysql_query("UPDATE user_data SET paid='0.00' WHERE uid='$userID'");
mysql_close($link);
if (!empty($errmsg)) {
// manually investigate errors from the fraud checking
$body = "IPN failed fraud checks: \n$errmsg\n\n";
$body .= $listener->getTextReport();
mail('user@example.com', 'IPN Fraud Warning', $body);
} else {
$link = mysql_connect($conn_host,$conn_user,$conn_pass) or die('Connection to mysql failed!');
mysql_select_db($conn_db,$link) or die('Connection to database failed!');
$sql = mysql_query("UPDATE user_data SET paid='$paid' WHERE uid='$userID'");
mysql_close($link);
}
} else {
// manually investigate the invalid IPN
mail('user@example.com', $listener->getTextReport());
}
?>