如何在没有 PayPal 帐户的情况下取消 PayPal 订阅?

Posted

技术标签:

【中文标题】如何在没有 PayPal 帐户的情况下取消 PayPal 订阅?【英文标题】:How to cancel a PayPal subscription without a PayPal account? 【发布时间】:2016-01-21 04:42:23 【问题描述】:

我当前的项目允许用户在不注册贝宝帐户的情况下订阅会员资格。

用户的用户名和密码由我自己的应用程序创建和管理,而不是 PayPal。

谁能告诉我如何创建一个取消订阅的 html 表单?我可以通过发送txn_id 来取消订阅吗?

我相信我可以通过 IPN 获取此信息。

我还应该提一下,我是一名 DBA,而不是真正的开发人员,如果我有点新手,请多多包涵。

提前致谢。

【问题讨论】:

Paypal - payment without account的可能重复 【参考方案1】:

这就是我最终做的事情。

<?php
require 'core/init.php';
require 'core/conn.php';
/*The paypal_transactions table is a table I'm using to store the IPN data.  This is necessary to capture the Profile_ID/Subscr_ID.  The Custom parameter is being used to pass the username.*/

$profileid_sql = "select subscr_id from paypal_transactions where custom ='". escape($user->data()->username)."'";
$result=mysql_query($profileid_sql); 

      while($row=mysql_fetch_array($result)) 
      $profileid = $row['subscr_id'];
      


include 'functions/change_subscription_status.php';
change_subscription_status( $profileid, 'Cancel' );
header('Location: Cancelled.php');
?>

change_subscription_status 函数来了……

<?php

/**
 * Performs an Express Checkout NVP API operation as passed in $action.
 *
 * Although the PayPal Standard API provides no facility for cancelling a subscription, the PayPal
 * Express Checkout  NVP API can be used.
 */
function change_subscription_status( $profile_id, $action ) 

    $api_request = 'USER=' . urlencode( 'API_username' )
                .  '&PWD=' . urlencode( 'API_Password' )
                .  '&SIGNATURE=' . urlencode( 'API_Signature' )
                .  '&VERSION=76.0'
                .  '&METHOD=ManageRecurringPaymentsProfileStatus'
                .  '&PROFILEID=' . urlencode( $profile_id )
                .  '&ACTION=' . urlencode( $action )
                .  '&NOTE=' . urlencode( 'Profile cancelled at store' );

    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp' ); // For live transactions, change to 'https://api-3t.paypal.com/nvp'
    curl_setopt( $ch, CURLOPT_VERBOSE, 1 );

    // Uncomment these to turn off server and peer verification
    // curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
    // curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $ch, CURLOPT_POST, 1 );

    // Set the API parameters for this transaction
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $api_request );

    // Request response from PayPal
    $response = curl_exec( $ch );

    // If no response was received from PayPal there is no point parsing the response
    if( ! $response )
        die( 'Calling PayPal to change_subscription_status failed: ' . curl_error( $ch ) . '(' . curl_errno( $ch ) . ')' );

    curl_close( $ch );

    // An associative array is more usable than a parameter string
    parse_str( $response, $parsed_response );

    return $parsed_response;

?>

【讨论】:

【参考方案2】:

使用paypal api方法ManageRecurringPaymentsProfileStatus(API Operation NVP),使用ACTION参数可以:

取消 - 只能取消处于活动或暂停状态的配置文件。 暂停 - 只能暂停处于活动状态的配置文件。 重新激活 - 只能重新激活处于暂停状态的配置文件。

Paypal Documentation - https://developer.paypal.com/docs/classic/api/merchant/ManageRecurringPaymentsProfileStatus_API_Operation_NVP/

要创建定期配置文件,请遵循以下 (PHP) 示例:

// SetExpressCheckout 的参数,将发送到 PayPal $pada['L_BILLINGAGREEMENTDESCRIPTION0'] = '产品描述'; $pada['L_BILLINGAGREEMENTDESCRIPTION0'] = $pada['L_BILLINGAGREEMENTDESCRIPTION0'] 。 '$'.$product->price.'/month'; $padata['L_PAYMENTREQUEST_0_DESC0'] = $padata['L_BILLINGAGREEMENTDESCRIPTION0'] 。 '$'.$product->price.'/month';$padata['PAYMENTREQUEST_0_NOTIFYURL'] = 'http://site_url/paypal/ipn'; $padata['PAYMENTREQUEST_0_DESC'] = $product->name; $padata['RETURNURL'] = 'http://site_url/paypal/returnurl'; $padata['CANCELURL'] = 'http://site_url/paypal/cancelurl'; $pada['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD'; $pada['PAYMENTREQUEST_0_PAYMENTACTION'] = '销售'; $padata['PAYMENTREQUEST_0_ITEMAMT'] = $product->price;$padata['PAYMENTREQUEST_0_AMT'] = $product->price;$padata['L_BILLINGTYPE0'] = 'RecurringPayments';$ padata['L_PAYMENTREQUEST_0_NAME0'] = $product->name;$padata['L_PAYMENTREQUEST_0_NUMBER0']= '322';$padata['L_PAYMENTREQUEST_0_QTY0'] = '1';$padata[' L_PAYMENTREQUEST_0_AMT0'] = $产品->价格; $paypal_data = http_build_query($pada); $httpParsedResponseAr = $this->PPHttpPost('SetExpressCheckout', $paypal_data); //根据我们从 Paypal 收到的消息进行响应 if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) //使用收到的令牌将用户重定向到 PayPal 商店。 $paypalurl ='https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$httpParsedResponseAr["TOKEN"].''; header('位置:'.$paypalurl); 别的 echo '错误:'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'';

页面返回网址:

$hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] = '重复描述';$hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] = $hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] 。 '$'.$pr->price.'/month';$hosteddata['L_PAYMENTREQUEST_0_NAME0'] = $pr->name;$hosteddata['PROFILEREFERENCE'] = $GetExpressCheckoutDetails['L_PAYMENTREQUEST_0_NUMBER0'] ;$hosteddata['PROFILESTARTDATE'] = date('Ym-d') 。 'T'。 date('H:i:s').'Z';$hosteddata['SUBSCRIBERNAME'] = $GetExpressCheckoutDetails['FIRSTNAME'] 。 ' ' 。 $GetExpressCheckoutDetails['LASTNAME'];$hosteddata['TOKEN'] = urlencode($_POST['token']);$hosteddata['DESC'] = $hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'];$hosteddata['AMT'] = $pr->price;$hosteddata['BILLINGPERIOD'] = '月';$hosteddata['BILLINGFREQUENCY'] = '1';$ hostsdata['TOTALBILLINGCYCLES'] = '12';$hosteddata['REGULARTOTALBILLINGCYCLES'] = '1';$hosteddata['VERSION'] = '74.0';$hosteddata['MAXFAILEDPAYMENTS' ] = '1';$hosteddata['L_PAYMENTREQUEST_0_QTY0'] = '1';$hosteddata['L_BILLINGTYPE0'] = 'RecurringPayments';$hosteddata['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = '数字' ;$hosteddata['L_PAYMENTREQUEST_0_AMT0'] = $pr->price;$hosteddata['INITAMT'] = $pr->price;$hosteddata['L_PAYMENTREQUE ST_0_NUMBER0'] = $pr->id;$hosteddata['PAYMENTREQUEST_0_NOTIFYURL'] = 'http://site_url/paypal/ipn'; $paypal_data = http_build_query($hosteddata); $hosted_saas_response = $this->PPHttpPost('CreateRecurringPaymentsProfile', $paypal_data);

我使用单独的方法将参数发布到贝宝

私有函数 PPHttpPost( $methodName_, $nvpStr_ ) $api_username = 'yourpaypal@email.com'; $api_password = 'QWEQWEWQEQWEQEQWE';$api_signature = 'WQEQWEQWEQWEWQEQWEQWEQWEQWEQWE.cT';$api_endpoint = "https://api-3t.paypal.com/nvp";$version = '124.0' ; $ch = curl_init();curl_setopt($ch, CURLOPT_URL, $api_endpoint); curl_setopt($ch, CURLOPT_VERBOSE, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$api_password&USER=$api_username&SIGNATURE=$api_signature&$nvpStr_"; curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);$httpResponse = curl_exec($ch); 如果(!$http响应) exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')'); // 提取响应详细信息。 $httpResponseAr = explode("&", $httpResponse); $httpParsedResponseAr = 数组(); foreach ($httpResponseAr as $i => $value) $tmpAr = explode("=", $value); 如果(大小($tmpAr)> 1) $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1]; if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) exit("对 $api_endpoint 的 POST 请求 ($nvpreq) 的 HTTP 响应无效。"); 返回 $httpParsedResponseAr;

另一种取消方式是在用户帐户内:

    登录到您的 PayPal 帐户。 点击页面顶部附近的个人资料。 点击我的钱。 点击“我的预先批准的付款”部分中的更新。 点击取消、取消自动计费或取消订阅并按照说明操作。

【讨论】:

感谢您的信息!我只是在遵循该工作流程时遇到了一些麻烦。在此之前,我只是使用贝宝管理的按钮进行订阅。 我测试了它,但因错误而挂断。 “在不在对象上下文中使用 $this” 此行发生错误:“$httpParsedResponseAr = $this -> PPhttpPost('SetExpressCheckout', $paypal_data);”我会继续努力,但如果您能提供任何其他帮助,我们将不胜感激。 $this->PPHttpPost( 因为所有这些功能都在一个类中,如果您使用另一种方式,只需调用方法 PPHttpPost( 没有 $this-> 使用下面的代码我得到这个错误:ACK=Failure&L_ERRORCODE0=10001&L_SHORTMESSAGE0=Internal%20Error& $service_url = 'api-3t.paypal.com/nvp'; $curl = curl_init($service_url); $curl_post_data = array( 'METHOD' => $methodname, 'PWD' => $api_password, 'USER' => $api_username, 'SIGNATURE' => $api_signature, 'PROFILEID' => 'I-9CDRG8MYSSSC', 'ACTION ' => '取消'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); $curl_response = curl_exec($curl);

以上是关于如何在没有 PayPal 帐户的情况下取消 PayPal 订阅?的主要内容,如果未能解决你的问题,请参考以下文章

Google Pay 是不是支持将资金转入 PayPal 帐户?

如何在 IPN 通知 URL 中获取 pay_key?

Paypal 沙盒订阅按钮 - 测试没有 Paypal 帐户的买家?

贝宝定期付款

Paypal 退订返回网址

PayPal 订阅 - 跟踪退款