我正在尝试为我的移动应用程序集成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 错误。
一切看起来都很好,我收到了第一笔付款,但我不确定将周期设置为"1"是否可以完成我正在寻找的工作。
我遇到了同样的问题,我的解决方案是删除setCylcles altogther,请参阅此处计划和付款定义类的外观示例:
$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
刚刚找到解决方案:
https://developer.paypal.com/docs/api/#paymentdefinition-object
此付款定义中的周期数。对于无限类型计划,常规类型payment_definition的周期应设置为 0。必填。
因此,基本上您必须将计划的类型设置为"无限"才能将周期设置为 0。
谢谢。
对于新/v1/billing/plans
,设置"total_cycles"=0
参考: https://developer.paypal.com/docs/api/subscriptions/v1/#definition-billing_cycle
我遇到了类似的问题,遵循 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": []
}
该 URL 上的文档仅说明了有关有限计划与无限计划的以下内容:
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.
因此,似乎不指定多个周期可能是正确的方法,但显然这是行不通的。我希望他们的文档更清晰。