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".
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.
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(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With