非常感谢。
你找到了简单的解决方案吗?我也在寻找。谢谢!
更新: 经过搜索,“ManageRecurringPaymentsProfileStatus”非常容易通过一个简单的POST请求来使用。
确保你的用户名、密码或签名不可见(换句话说,在服务器上执行此操作,而不是通过javascript或html posts在客户端上执行)。
下面是Python的一个简单实例。它有效,我现在每天都在使用它。
import urllib
from google.appengine.api import urlfetch
form_fields = {
"METHOD": "ManageRecurringPaymentsProfileStatus",
"PROFILEID": "xxx", # put your subscription ID here
"ACTION": "cancel",
"USER": "xxx", # Get USER, PWD, and SIGNATURE from your Paypal's account preferences
"PWD": "xxx",
"SIGNATURE": "xxx",
"VERSION": "54.0"
}
api_url = 'https://api-3t.sandbox.paypal.com/nvp' # remove the sandbox part for production
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url=api_url,
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'})
响应是一个字符串,看起来像这样:
TIMESTAMP=2011%2d01%2d28T14%3a47%3a45Z&CORRELATIONID=148ebe1d25566&ACK=Failure&VERSION=54%2e0&BUILD=1704252&L_ERRORCODE0=11552&L_SHORTMESSAGE0=Invalid%20profile%20ID&L_LONGMESSAGE0=The%20profile%20ID%20is%20invalid&L_SEVERITYCODE0=Error
'ACK'字段指示“失败”或“成功”。
回答下面的评论时,请注意它确实使我能够取消通过动态创建的链接创建的订阅,例如:
<a href="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick-subscriptions&business=llcpro_1295263400_biz%40jeregle.com&item_name=Abonnement%20mensuel&a3=41.86&t3=M&p3=1&src=1&sra=1¤cy_code=EUR&no_note=1&no_shipping=1&lc=FR&custom=xxxxx¬ify_url=https%3A%2F%2Fyournotifyurl.com%2Fipn&charset=utf-8&country=FR&a1=0&t1=D&p1=31" target="_blank">Subscribe</a>
请注意,我根本不使用“modify”标志。
public function cancelSubscription(string $billingID, string $reason) : bool {
$token = $this->getAccessToken()->access_token; // Authorization
$url = $this->getCancelURI($billingID); // https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$billingID}/cancel
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, "{
\"reason\":\"{$reason}\"
}");
$headers = [];
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer ' . $token;
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
$result = curl_exec($ch);
if(empty($result)) {
// Logging results since it runs in background and no output is printed to the browser.
$fh = fopen('debug_log.php','a+');
fwrite($fh,PHP_EOL."Result True: {$result}".PHP_EOL);
fclose($fh);
return true;
}
else {
// Logging results since it runs in background and no output is printed to the browser.
$fh = fopen('debug_log.php','a+');
fwrite($fh,PHP_EOL."Result False: {$result}".PHP_EOL);
fclose($fh);
return false;
}
}