Emmanuel Dufitumukiza
Emmanuel Dufitumukiza

Reputation: 61

Nextjs 13 apis - stripe api, How to upgrade stripe subscription plan after knowing that user paid or not

Currently I have the following solution to upgrade subscription in stripe using nextjs api, but the problem is it's updating the priceId of current subscriptions regardless of whether the user paid or not.

const updatedSubscription = await stripe.subscriptions.update(
  userInfo?.stripeSubscriptionId || "", {
    items: [{
        id: currentSubscription.items.data[0].id,
        price: newPlanId
    }],
  }
);

How can I upgrade the subscription plan only after user paid?

Upvotes: 1

Views: 341

Answers (1)

Lucky2501
Lucky2501

Reputation: 1704

Stripe has a feature for this, called pending update:
https://stripe.com/docs/billing/subscriptions/pending-updates

This would revert the Subscription to the items prior to your update if the customer doesn't pay the Invoice that gets generated from it.

This is however specifically intended for updates that trigger an Invoice right away. Not sure if that's your case from the information you shared.

Upvotes: 1

Related Questions