1

我正在尝试在每月向用户收费的网站上创建订阅。当他们付款时,我数据库中的数据列从 0 变为 1。如果他们取消,同一列将变回 0。

我已经创建了一个执行此操作的购买按钮,一旦他们购买,它会将列更改为 1。我需要添加什么来使用订阅按钮,如果他们取消将其更改回 0?

这是我的代码:这会创建订阅按钮吗?我用我在贝宝上找到的订阅按钮修改了我的购买按钮。

  <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);
}
4

1 回答 1

1

当买家取消订阅时,PayPal 将向您发送一个 IPN,其中包含txn_type=subscr_canceltxn_type=recurring_payment_profile_cancel(取决于创建的订阅的确切类型)。然后,您可以查看subscr_idorrecurring_payment_id参数来确定刚刚取消的订阅的订阅 ID。

于 2013-09-13T16:17:59.473 回答