On this page: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECRecurringPayments
it says that it's possible to cancel a PayPal subscriptio开发者_JS百科n using their API. Knowing the SubscriptionId can anyone give me some code example how to do this?
Many thanks.
Did you manage to find an easy solution ? I'm looking for this as well. Thanks!
Update : After searching, the "ManageRecurringPaymentsProfileStatus" is very easy to use through a simple POST request.
Make sure that your user, password or signature are not visible (in other words, do this on your server and NOT on your client via javascript or html posts).
Below a simple working example in Python. It works and I'm now using it daily.
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'})
The response is a string that looks like this:
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
The 'ACK' field indicates 'Failure' or 'Success'.
In answer to comments below, note that it DOES enable me to cancel the subscriptions that have been created through a dynamically created link such as :
<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>
Note that I do not use the flag 'modify' at all.
精彩评论