【问题标题】:Specify Duration while creating Stripe Subscription Plan在创建 Stripe 订阅计划时指定持续时间
【发布时间】:2021-04-16 09:56:05
【问题描述】:

我正在使用 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 文档找到了这个,但无济于事。

【问题讨论】:

  • 我认为你需要创建价格而不是计划
  • @ashokpoudel:我检查了计划 api,但同样的问题在这里 stripe.com/docs/api/prices/create
  • 我还应该补充一点,当 3 个月期限过去时,可以通过 API 自己管理价格行项目来手动处理升级或降级方案。您可以通过调用 API 更改订阅行项目来完成此操作。可以在此处找到升级或降级的示例:stripe.com/docs/billing/subscriptions/…

标签: php laravel stripe-payments laravel-cashier


【解决方案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

【讨论】:

    【解决方案2】:

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

    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
        ],
    ]);
    

    【讨论】:

      猜你喜欢
      • 2019-02-28
      • 1970-01-01
      • 1970-01-01
      • 2021-12-25
      • 2016-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      相关资源
      最近更新 更多