你能通过API取消PayPal的自动付款吗?(通过托管按钮创建的订阅)

25
可以通过API取消PayPal的自动付款吗?它是通过托管按钮创建的“订阅”。
我有“自动付款编号”和“交易ID”。
5个回答

26

可以。

您可以使用ManageRecurringPaymentsProfileStatus API挂起或取消一个配置文件。您也可以重新启用被挂起的配置文件。然而,如果已达到最大失败支付次数,则需要在重新激活配置文件之前增加失败支付次数。

请参阅此参考文献

根据PayPal,可以使用ManageRecurringPayments API执行以下三种操作:

  • 取消 - 只有处于活动或挂起状态的配置文件才可以取消。
  • 挂起 - 只有处于活动状态的配置文件可以挂起。
  • 重新启用 - 只有处于挂起状态的配置文件可以重新启用。

3
这只适用于“Paypal Pro/Express付款”吗?OP所说的是普通的Paypal订阅系统。 - erikcw
1
您不能使用下面答案中提到的API取消旧订阅。 - Usman Zaheer
您可以取消“旧”订阅,但无法使用API查看“旧”订阅的详细信息。 - gunwin

5

在找到解决方案之前,我看到了这个帖子,现在来分享一下答案。(C#.Net 解决方案)

你需要以下 NuGet 包:

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

以下是参考文献:
using PayPal.Api;
using PayPal.PayPalAPIInterfaceService;
using PayPal.PayPalAPIInterfaceService.Model;

以下是代码:

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

1
你的代码非常优秀,简洁明了,帮助我解决了问题。谢谢。 - Sunil

3
"通过网站支付标准的“订阅”按钮创建订阅。在2009年之前,订阅配置文件ID以S-XXXXXXXX开头。您无法通过任何API调用管理这些订阅。在2009年之后,订阅配置文件ID以I-XXXXXX开头。您可以通过ManageRecurringPaymentsProfileStatus API调用取消这些订阅。"
"遇到了同样的问题,刚刚阅读了Robert的内容,它有效,您可以使用API取消标准网站订阅。"

2
是的,您无法使用API取消'S'前缀订阅。 - Usman Zaheer
1
您现在使用API或Paypal页面创建的任何新内容都将与I相关,S只是旧的。 - Usman Zaheer
很奇怪。你的商业账户是新的吗?针对哪个订阅按钮制作的? - Usman Zaheer
1
不完全正确。 我有两个PayPal账户。 其中一个订阅都以S-开头,它们无法管理。 另一个以I-开头,可以通过API进行管理。 PayPal就像是一种癌症 :/ - John
我知道这个帖子很旧了 - 但我想让你知道,我刚刚在这里编写了一个Phantom.js脚本,可以让你从代码中取消旧的S-*订阅。这为我们节省了很多时间。http://blog.degree.no/2015/10/cancelling-old-s-paypal-subscriptions-from-code/ - Njål Arne Gjermundshaug
显示剩余5条评论

1

0

我认为你不能使用API来取消Paypal标准支付事件专业版的付款,只有快速结账才能起作用。我尝试过并收到了错误消息:“订阅配置文件不受定期付款API支持。” 你可以在这里找到更多信息。


只有在尝试检索订阅详细信息时才会出现此错误。 “任何”订阅都可以编辑其状态。 - gunwin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接