[英]Stripe Subscription update the plan immediately with full amount
I'm looking to update the customer's subscription, and the new plan price will be deducted immediately.我正在寻找更新客户的订阅,新的计划价格将立即扣除。
Consider the following scenario:考虑以下场景:
User is on Plan A($15 per month) and wants to update to Plan B($25 per month) in the middle of the month.用户正在使用计划 A(每月 15 美元)并希望在月中更新到计划 B(每月 25 美元)。
I want the user to charge $25 right away rather than prorate - I don't want the difference will be charged to the customer.我希望用户立即收取 25 美元而不是按比例收取 - 我不希望向客户收取差额。
I also try with proration_behavior='always_invoice' However, it is charge $10.我也尝试使用proration_behavior='always_invoice'但是,收费 10 美元。 I need $25 charged right away.
我需要立即收取 25 美元。
subscription = Stripe::Subscription.retrieve('sub_49ty4767H20z6a')
Stripe::Subscription.update(
subscription.id,
{
cancel_at_period_end: false,
proration_behavior: 'none',
items: [
{
id: subscription.items.data[0].id,
price: 'price_1LcBtVHhBkzUOaGo0gvFmaMS'
}
]
}
)
You can achieve it with proration_behavior
and billing_cycle_anchor
.您可以使用
proration_behavior
和billing_cycle_anchor
来实现它。
You only need to pass these two properties while updating your subscription details using stripe API.在使用条带 API 更新订阅详细信息时,您只需要传递这两个属性。
subscription = Stripe::Subscription.retrieve('sub_49ty4767H20z6a')
Stripe::Subscription.update(
subscription.id,
{
cancel_at_period_end: false,
proration_behavior: 'none',
billing_cycle_anchor: 'now',
items: [
{
id: subscription.items.data[0].id,
price: 'price_1LcBtVHhBkzUOaGo0gvFmaMS'
}
]
}
)
I see you're looking to update a subscription without any prorations and to immediately charge for the upgraded price.我看到您希望在不按比例分配的情况下更新订阅并立即收取升级后的价格。 The way to achieve this would be by specifically passing proration_behavior: 'none' and billing_cycle_anchor: 'now'.
实现这一点的方法是专门传递 proration_behavior : 'none' 和billing_cycle_anchor: 'now'。 Your code will look something like this:
您的代码将如下所示:
Stripe::Subscription.update(
subscription.id,
{
cancel_at_period_end: false,
billing_cycle_anchor: ‘now’,
proration_behavior: ‘none’,
items: [
{
id: subscription.items.data[0].id,
price: 'price_xxxxxxx'
}
]
}
)
Please note that this changes the billing cycle of the subscription and to learn more about billing_cycle_anchor please visit here .请注意,这会更改订阅的计费周期,要了解有关 billing_cycle_anchor 的更多信息,请访问此处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.