Can you cancel a PayPal automatic payment via API? (Subscription created via Hosted button)

独自空忆成欢 提交于 2019-12-18 03:04:09

问题


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".


回答1:


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.--



回答2:


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();
}



回答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.




回答4:


  • Cancel new I-* Subscriptions using PayPals ManageRecurringPaymentsProfileStatus API.
  • Cancel old S-* Subscriptions by using PhantomJS + this script: http://blog.degree.no/2015/10/cancelling-old-s-paypal-subscriptions-from-code/



回答5:


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.



来源:https://stackoverflow.com/questions/3809587/can-you-cancel-a-paypal-automatic-payment-via-api-subscription-created-via-hos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!