paypal - 如何使用 paypal 订阅 IPN 以及如何知道是否有人取消

标签 paypal

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

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

这是我的代码:这会创建订阅按钮吗?我用在 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);
}

最佳答案

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

关于paypal - 如何使用 paypal 订阅 IPN 以及如何知道是否有人取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18769925/

相关文章:

objective-c - 在 iPad native 应用程序中每月订阅的 Paypal 付款

php - API 凭据不正确

paypal - PayFlow 定期付款

google-chrome - Chrome 中无法使用 PayPal 网页

paypal - 如何建立 Paypal 退款网址?

django - 集成 django-paypal

php - Paypal sizeof() : Parameter must be an array or an object that implements Countable

android - 如何在Paypal中实现拆分交易?

Paypal 沙箱给出内部服务器错误

安卓java.security.NoSuchAlgorithmException : KeyManagerFactory SunX509 implementation not found