我最近切换到了最新的stripe API,其中计划已转移到产品中。一切都很顺利,但改变计划也保留了以前没有的旧计划。
如果我向用户订阅计划A,那么将计划更改为计划B,现在不是为用户显示一个计划,而是显示两个计划。
因此,如果我尝试切换到计划A,它会抛出一个错误:
Stripe.StripeException: Cannot add multiple subscription items with the same plan:
以下是我的代码,在升级之前运行良好:
public async Task SetPlan(string subscriptionId, string plan)
{
var subscriptionService = new StripeSubscriptionService();
var items = new List<StripeSubscriptionItemUpdateOption>()
{
new StripeSubscriptionItemUpdateOption() { PlanId = plan }
};
var subscriptionOptions = new StripeSubscriptionUpdateOptions()
{
CancelAtPeriodEnd = false,
Prorate = true,
Items = items
};
await subscriptionService.UpdateAsync(subscriptionId, subscriptionOptions);
}