25

Can you cancel a PayPal automatic payment via API? It's a "Subscription" created via Hosted button.

I have the "Automatic payment number" and the "Transaction ID".

Zack Burt
  • 8,257
  • 10
  • 53
  • 81

5 Answers5

26

Yes.

You can suspend or cancel a profile by using the ManageRecurringPaymentsProfileStatus API. You can also reactivate a suspended profile. If the maximum number of failed payments has already been reached, however, you will need to increase the number of failed payments before reactivating the profile.

Please find this Reference:

Accodring to PAYPAL you can take any of three actions utilizing the ManagerecurringPayments API.

  • Cancel - Only profiles in Active or Suspended state can be canceled.
  • Suspend - Only profiles in Active state can be suspended.-
  • Reactivate - Only profiles in a suspended state can be reactivated.--
gunwin
  • 4,578
  • 5
  • 37
  • 59
Michael Eakins
  • 4,149
  • 3
  • 35
  • 54
  • 3
    Isn't this just for "Paypal Pro/Express payments"? The OP is talking about the regular paypal Subscription system. – erikcw Sep 16 '11 at 15:51
  • 1
    You can not cancel old subscription using API as mentioned in the answer below. – Usman Zaheer Aug 24 '12 at 11:14
  • You CAN cancel an 'old' subscription, you cannot view the details of an 'old' subscription with the API. – gunwin Apr 08 '14 at 23:38
5

I found this thread before finding a solution, and thought I'd come back to give the answer. (C#.Net Solution)

You will require the following nuget packages:

Install-Package RestApiSDK
Install-Package PayPalCoreSDK
Install-Package PayPalMerchantSDK

And the following references:

using PayPal.Api;
using PayPal.PayPalAPIInterfaceService;
using PayPal.PayPalAPIInterfaceService.Model;

Here's the code:

public static void CancelRecurringPayment(string ProfileID)
{
    ManageRecurringPaymentsProfileStatusRequestType request =
        new ManageRecurringPaymentsProfileStatusRequestType();
    ManageRecurringPaymentsProfileStatusRequestDetailsType details =
        new ManageRecurringPaymentsProfileStatusRequestDetailsType();
    request.ManageRecurringPaymentsProfileStatusRequestDetails = details;

    details.ProfileID = ProfileID;

    details.Action = StatusChangeActionType.CANCEL;

    // Invoke the API
    ManageRecurringPaymentsProfileStatusReq wrapper = new ManageRecurringPaymentsProfileStatusReq();
    wrapper.ManageRecurringPaymentsProfileStatusRequest = request;

    Dictionary<string, string> configurationMap = new Dictionary<string, string>();

    configurationMap.Add("mode", "live");
    // Signature Credential
    configurationMap.Add("account1.apiUsername", "APIUSERNAME");
    configurationMap.Add("account1.apiPassword", "APIPASSWORD");
    configurationMap.Add("account1.apiSignature", "APISIGNATURE");

    // Create the PayPalAPIInterfaceServiceService service object to make the API call
    PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

    ManageRecurringPaymentsProfileStatusResponseType manageProfileStatusResponse =
                service.ManageRecurringPaymentsProfileStatus(wrapper);

    // Check for API return status

    Dictionary<string, string> responseParams = new Dictionary<string, string>();
    responseParams.Add("API Status", manageProfileStatusResponse.Ack.ToString());

    if (manageProfileStatusResponse.Ack.Equals(AckCodeType.FAILURE) || (manageProfileStatusResponse.Errors != null && manageProfileStatusResponse.Errors.Count > 0))
    { 
        //FAILURE
        Console.WriteLine(manageProfileStatusResponse.Errors.ToString());
    }
    else
    {
        //SUCCESS
        Console.Write("Success!");
    }
    Console.WriteLine();
}
Doug
  • 3,312
  • 1
  • 24
  • 31
gunwin
  • 4,578
  • 5
  • 37
  • 59
3

"A subscription is created via a Website Payments Standard 'Subscribe' button. Before 2009, the subscription profile ID started with S-XXXXXXXX. You are not able to manage these subscriptions via any API calls. After 2009, the subscription profile ID starts with I-XXXXXX. You are able to cancel these subscriptions via the ManageRecurringPaymentsProfileStatus API call."

Was having the same problem and just read it by Robert and it works, you can cancel standard website subscription using API.

Community
  • 1
  • 1
Usman Zaheer
  • 629
  • 8
  • 24
  • What works? I have the same issue and I can't cancel S- subscriptions. – Tomas Aug 22 '12 at 07:14
  • 2
    Yes, you won't be able to cancel 'S' prefix subscriptions using API. – Usman Zaheer Aug 24 '12 at 11:06
  • How to create subscription with I- prefix? – Tomas Aug 24 '12 at 11:08
  • 1
    Any new you create now using either API or Paypal page would be with I. S are just old ones. – Usman Zaheer Aug 24 '12 at 11:12
  • I have created Subscription button this week and all subscription orders still comes with S- prefix. – Tomas Aug 24 '12 at 11:18
  • That's weird. Is your business account new? Against which the subscription button is made. – Usman Zaheer Aug 24 '12 at 11:37
  • I have business account. To create new button I go to My Account - Profile - My Selling Tools - PayPal Buttons - Create New Button. PayPal generate pay button link with parameter cmd=_s-xclick All subscription starts with S- – Tomas Aug 24 '12 at 11:58
  • my cmd param is "_xclick-subscriptions", not _s-xclick. Perhaps that has something to do with it? Maybe you should revise your button code utilizing some other method than you are currently doing and then the "I" prefixed subscriptions will most likely come through. – offthat Oct 26 '12 at 04:04
  • 1
    Not completely true. I have two paypal accounts. On one the subscriptions are all starting with S- They are not manageable. On the other they start with I- and are manageable by API. PayPal is a cancer :/ – John Mar 29 '14 at 02:29
  • I know this thread is old - but I just want to let you know that I just wrote a Phantom.js script here that will enable you to cancel old S-* subscriptions from code. Saves us a lot of time. http://blog.degree.no/2015/10/cancelling-old-s-paypal-subscriptions-from-code/ – Njål Arne Gjermundshaug Oct 26 '15 at 13:21
1
0

I don't think you can use the API to cancel a payment with Paypal standard payment event pro while only express checkout will work. I tried and got the error message: "Subscription Profiles not supported by Recurring Payment APIs.". You can find out more here.

Steven
  • 1,365
  • 2
  • 13
  • 28
Sareuon
  • 637
  • 1
  • 7
  • 9
  • You will only get this error when trying to retreive subscription details. ''Any'' subscription can have it's status edited. – gunwin Apr 08 '14 at 23:37