2010-12-03 25 views
12

本頁內容: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECRecurringPayments您如何通過api取消PayPal訂閱?

它表示可以使用API​​取消PayPal訂閱。知道SubscriptionId任何人都可以給我一些代碼示例如何做到這一點?

非常感謝。

+0

您有沒有收到除「*失敗*」/「*配置文件ID無效*」以外的回覆?據我發現,你不能取消這種「正常」創建的訂閱(沒有* CreateRecurringPaymentsProfile *)。把訂閱ID放在那裏並不能解決問題(就像我一樣)。 – nssmart 2011-03-21 23:00:21

+2

「訂閱是通過網站付款標準」訂閱「按鈕創建的,2009年之前,訂閱配置文件ID以S-XXXXXXXX開頭,您無法通過任何API調用管理這些訂閱。與I-XXXXXX。您可以通過ManageRecurringPaymentsProfileStatus API調用取消這些訂閱。「 如果遇到同樣的問題,只能通過Robert來閱讀它,它可以工作,您可以使用API​​取消標準網站訂閱。 – 2012-05-04 12:01:39

回答

15

您是否設法找到簡單的解決方案?我也在尋找這個。謝謝!

更新:搜索後,「ManageRecurringPaymentsProfileStatus」通過簡單的POST請求非常容易使用。

確保您的用戶,密碼或簽名不可見(換句話說,在服務器上執行此操作,而不是通過javascript或html文章在您的客戶端上執行此操作)。

下面是一個簡單的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 =失敗& VERSION = 54%2E0 & BUILD = 1704252 & L_ERRORCODE0 = 11552 & L_SHORTMESSAGE0 =無效%20profile%20ID & L_LONGMESSAGE0 =的%20profile%20ID%圖20是%20invalid & L_SEVERITYCODE0 =錯誤

'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&currency_code=EUR&no_note=1&no_shipping=1&lc=FR&custom=xxxxx&notify_url=https%3A%2F%2Fyournotifyurl.com%2Fipn&charset=utf-8&country=FR&a1=0&t1=D&p1=31" target="_blank">Subscribe</a>

請注意,我不使用標誌「修改「。