【问题标题】:Paypal set unlimited cycles for recurring payments贝宝为定期付款设置无限周期
【发布时间】:2015-04-01 19:26:48
【问题描述】:

我正在尝试为我的移动应用集成 Paypal 定期付款。到目前为止,我设法使用 https://github.com/paypal/PayPal-PHP-SDK 在各种 PHP 应用程序上实现 Paypal 付款,但这是我第一次实现定期付款

我正在尝试使用以下代码为计费计划构建付款:

        $paymentDefinition = new PaymentDefinition();
        $paymentDefinition->setName('Mobile App subscription')
            ->setType('REGULAR')
            ->setFrequency('Month')
            ->setFrequencyInterval("1")
            ->setCycles("1")
            ->setAmount(
                new Currency(
                    array(
                        'value' => 50, 
                        'currency' => 'USD'
                    )
                )
            );

从 Paypal 文档中,我了解到“setCycles”应设置为 0 以实现无限订阅。使用 PHP SDK 将其设置为 0 会返回 400 错误。

一切看起来都很好,我收到了第一笔付款,但我不确定将 Cycle 设置为“1”是否能完成我正在寻找的工作。

【问题讨论】:

    标签: php paypal sdk payment recurring


    【解决方案1】:

    我遇到了同样的问题,我的解决方案是完全删除 setCycles,请参阅此处的计划和付款定义类的示例:

    $plan = new Plan();
        $plan->setName('Some example name')
            ->setDescription('A short description of the plan')
            ->setType('INFINITE');
    
    $paymentDefinition = new PaymentDefinition();
        $paymentDefinition->setName('Regular Payments')
            ->setType('REGULAR')
            ->setFrequency('Month')
            ->setFrequencyInterval("1")
            ->setAmount(new Currency(array('value' => 100, 'currency' => 'USD')));enter code here
    

    【讨论】:

      【解决方案2】:

      刚刚找到解决办法:

      https://developer.paypal.com/docs/api/#paymentdefinition-object

      此付款定义中的周期数。对于 INFINITE 类型的计划,对于 REGULAR 类型的 payment_definition,应将周期设置为 0。必填。

      所以,基本上你必须将计划的类型设置为“无限”才能将周期设置为 0。

      谢谢。

      【讨论】:

      • 能否请您添加代码。当我输入“INFINITE”并循环到 0 时,我得到了同样的错误
      • 您找到解决方案了吗?这里的所有答案都过时了。 @sarath
      【解决方案3】:

      对于新的/v1/billing/plans,设置"total_cycles"=0

      参考:https://developer.paypal.com/docs/api/subscriptions/v1/#definition-billing_cycle

      【讨论】:

        【解决方案4】:

        我也有类似的问题,关注https://developer.paypal.com/docs/subscriptions/integrate/#3-create-a-plan

        我复制了他们提供的 CURL 示例,添加了我的令牌等等。我第一次运行它时将 JSON /billing_cycles/1/total_cycles 设置为 12。这似乎有效。但后来我意识到我无法弄清楚如何将计划指定为infinite。所以我再次尝试删除total_cycles,或者将其设置为0,在这两种情况下我都会收到以下错误:

        {
            "name": "INVALID_REQUEST",
            "message": "Request is not well-formed, syntactically incorrect, or violates schema.",
            "debug_id": "4ae9c3405d9b",
            "details": [{
                "field": "/billing_cycles/1/pricing_scheme",
                "location": "body",
                "issue": "MALFORMED_REQUEST_JSON",
                "description": "The request JSON is not well formed."
            }],
            "links": []
        }
        

        该网址上的文档仅对有限计划与无限计划进行了以下说明:

        You can create either a finite plan or an infinite plan:
        
        Finite Plan - A plan with a fixed number of cycles. Once a buyer subscribes, a finite plan expires after the total number of cycles defined for are completed. For example, a buyer can subscribe to an online tutorial service for 3 cycles.
        
        Infinite Plan - A plan without a fixed number of cycles. Once a buyer subscribes, an infinite plan remains active until cancelation. For example, a buyer can subscribe to a video or music streaming service with no specified end date.
        

        因此,似乎不指定周期数可能是正确的方法,但显然这行不通。我希望他们的文档更清晰。

        【讨论】:

          猜你喜欢
          • 2010-12-22
          • 2023-04-10
          • 2014-09-14
          • 2016-10-01
          • 2016-02-22
          • 2012-12-17
          相关资源
          最近更新 更多