gpt4 book ai didi

stripe-payments - Stripe : downgrade a user at "period end"

转载 作者:行者123 更新时间:2023-12-03 07:21:07 26 4
gpt4 key购买 nike

是否可以在周期结束时而不是立即降级用户?我梳理了API Docs但一直无法弄清楚如何实现这一点。

作为解决方法,我目前立即取消用户的订阅,然后为他们订阅较少的订阅,试用到月底。但这是行不通的 - 我需要能够将降级推迟到期限结束(但在请求降级时用 Stripe“记录”它)。

显然,有一些方法可以通过 Webhook 回调和本地跟踪用户订阅来实现此目的,但我希望尽可能避免这种情况。

<小时/>

编辑

在有人问之前 - 我正在使用 Temboo 的 PHP SDK。然而,我并不是在寻找特定于语言的方法,只是在寻找高级操作方法(如果可能的话)。

最佳答案

这里提出的大多数解决方案看起来都像是在 stripe 发布订阅计划后的黑客攻击,这可能是最优雅的解决方案。事实上, strip 文档有一个示例说明了完全相同的场景 here .

第 1 步:从您想要降级的现有订阅中获取 current_period_end 值。

第 2 步:根据现有订阅创建新的订阅计划。

$subscriptionSchedule = $stripe->subscriptionSchedules->create([
'from_subscription' => 'sub_G678SASEGF',
]);

第 3 步:更新新创建的计划,分为两个阶段。 phase 0 是在 current_period_end 结束的当前阶段,phase 1 是在 current_period_end 开始的下一个阶段降级的价格计划。

$stripe->subscriptionSchedules->update(
$subscriptionSchedule->id,
[
'end_behavior' => 'release',
'phases' => [
[
'start_date' => $current_period_start,
'end_date' => $current_period_end,
'items' => [
[
'price' => $current_price_id
],
],
],
[
'start_date' => $current_period_end,
'items' => [
[
'price' => $downgraded_price_id,
],
]
],
],
]

您始终可以检查订阅对象以查看是否有事件计划,然后检索计划以利用 future 的任何降级。这种方法的优点是它可以应用于任何降级和/或计费周期变化。使用答案中前面描述的多计划方法,一个订阅只能包含具有相同计费周期的项目。

关于stripe-payments - Stripe : downgrade a user at "period end",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16820212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com