Stripe Products - Changing plan is not removing the old plan

911 views Asked by At

I recently switched to the latest stripe API where plans have moved into products. Everything is working fine, but changing plans retains the old plan too which was not happening previously.

If I subscribe user to Plan A, then change the plan to Plan B, now instead of showing one plan for the user it is showing two plans.

So if I try to switch to Plan A, it throws an error:

Stripe.StripeException: Cannot add multiple subscription items with the same plan:

Following is my code, which was working fine before the upgrade:

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);
    }
1

There are 1 answers

0
koopajah On BEST ANSWER

Your call here is adding a new item/plan though and not replacing the existing one.

To replace one plan by another you need to also pass the current subscription item's id in Id along with the new plan id for this to work.