我正在使用 Stripe PHP SDK 动态创建订阅计划。
use \Stripe\Plan;
Plan::create(array(
"amount" => 2000,
"interval" => "month",
"name" => "Amazing Gold Plan",
"currency" => "usd",
"id" => "gold")
);
我想问有没有办法提及/处理计划的持续时间。就像我想在有限的时间内订阅该计划一样,假设 3 个月,3 个月后我希望该计划自动从订阅中删除。我不想取消整个订阅,因为在我的情况下,一个订阅可能有多个计划。所以我只想从订阅中删除/分离该计划。
我已经通过 Stripe SDK 文档找到了这个,但无济于事。
答案 0 :(得分:1)
订阅时间表 [1] 将是您在此处使用阶段 [2] 自动更改基础订阅所需的内容。
使用时间表将允许您指定,例如,将在第一阶段迭代 3 个月的每月价格。然后您可以在下一阶段定义会发生什么,例如以某种方式更改价格,例如添加或删除价格。一个示例可能如下所示:
\Stripe\SubscriptionSchedule::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-phases
答案 1 :(得分:0)
我相信您需要创建价格而不是计划,代码将是这样的(不确定我使用不同的平台,但您可以尝试)
use \Stripe\Plan;
$price = \Stripe\Price::create([
'product' => '{{PRODUCT_ID}}',
'unit_amount' => 1000,
'currency' => 'usd',
'recurring' => [
'interval' => 'month',
'interval_count' => 2 //Try tweaking this value for change
],
]);