我正在尝试在每个月向用户收费的网站上创建订阅。付款时,我的数据库中的数据列从0更改为1.如果取消,则同一列将更改回0.
我已经创建了一个购买按钮来执行此操作,一旦他们购买,它会将列更改为1.我需要添加什么才能使用订阅按钮,如果他们取消将其更改回0?< / p>
这是我的代码:这会创建订阅按钮吗?我用paypal上的订阅按钮修改了我的购买按钮。
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="cccc@msn.com">
<input type="hidden" name="item_name" value="$info">
<input type="hidden" name="a3" value="5.00">
<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">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="return" value="http://ccccc.com/application.php">
<input type="hidden" name="cancel_return" value="http://www.ccccc.com/index.php">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="notify_url" value="http://www.ccccc.com/ipn.php">
<input type="hidden" name="custom" value="$uid">
<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!">
</form>
这是我的IPN代码:我需要添加到这里以使其与订阅一起使用,如果他们取消将其更改回0.是否有用户被取消时发送的变量或我是否需要创建一个处理已取消帐户的新文件?
$connection = mysql_connect("localhost","theelit9_chris","");
mysql_select_db("theelit9_date",$connection);
// 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((int)$_POST["custom"]);
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 = "SELECT `txn_id` FROM `log` WHERE `txn_id` = '".$txn_id."'";
$result = mysql_query($txn_id_check);
if (mysql_num_rows($result) !=1 ) {
if ($receiver_email=='xxxx@msn.com') {
if ($payment_amount == '0.01' && $payment_currency == 'USD') {
$log_query = "INSERT INTO `log` VALUES ('','".$txn_id."','".$payer_email."')";
$update_user_level = "UPDATE `users` SET `user_level` = '2', WHERE `id`='".$user_id."'";
mysql_select_db("theelit9_date",$connection);
$retval = mysql_query( $log_query, $connection );
$retval1 = mysql_query( $update_user_level, $connection );
if(! $retval && !$retval1)
{
die('Could not enter data: ' . mysql_error());
}
}
}
}
}
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
答案 0 :(得分:1)
当买家取消订阅时,PayPal会向您发送包含txn_type=subscr_cancel
或txn_type=recurring_payment_profile_cancel
的IPN(具体取决于所创建的订阅的确切类型)。然后,您可以查看subscr_id
或recurring_payment_id
参数,以确定刚刚取消的订阅的订阅ID。