创建条带订阅计划时指定持续时间



我正在使用Stripe PHP SDK动态创建订阅计划。

use StripePlan;
Plan::create(array(
"amount" => 2000,
"interval" => "month",
"name" => "Amazing Gold Plan",
"currency" => "usd",
"id" => "gold")
);

我想问一下有没有办法提及/处理计划的持续时间。就像我想在有限的时间内按计划订阅一样——假设是3个月,3个月后,我希望该计划自动从订阅中删除。我不想取消整个订阅,因为在我的情况下,一个订阅可能有多个计划。所以我只是想从订阅中删除/分离计划。

我浏览了Stripe SDK文档找到了这个,但没有用。

Subscription Schedule[1]将是您使用阶段[2]自动更改基础Subscription所需要的。

使用时间表可以指定,例如,在第一阶段将迭代3个月的每月价格。然后,您可以在下一阶段定义将要发生的事情,例如以某种方式更改价格,例如添加或删除价格。例如:

StripeSubscriptionSchedule::create([
'customer' => 'cus_xxx',
'start_date' => 'now',
'end_behavior' => 'release',
'phases' => [
[
'items' => [
[
'price' => 'price_print', # Monthly Price
'quantity' => 1,
],
],
'iterations' => 3, # Iterates for 3 months
],
[
'items' => [
[
'price' => 'price_print',
'quantity' => 1,
],
[
'price' => 'price_digital',  # An extra price
'quantity' => 1,
],
],
'iterations' => 1, # Iterate for 1 month
],
],
]);

[1]https://stripe.com/docs/billing/subscriptions/subscription-schedules#managing

[2]https://stripe.com/docs/api/subscription_schedules/object#subscription_schedule_object-相位

我认为你需要创建价格而不是计划,代码会是这样的(不确定我使用不同的平台,但你可以尝试(

use StripePlan;
$price = StripePrice::create([
'product' => '{{PRODUCT_ID}}',
'unit_amount' => 1000,
'currency' => 'usd',
'recurring' => [
'interval' => 'month',
'interval_count' => 2 //Try tweaking this value for change
],
]);

最新更新