How to remove the old plan when upgrading to a new plan in MemberStack? Answered

Post author
John Carlo

Hi, Ducan

I’m glad to see you here!

Recently, I’ve been developing a feature to manage users’ plans on the website, and I’ve encountered an issue. When trying to change the current plan using this code, the original plan is not removed.

Please first review the following code.

      const params = {
priceId: this.priceId,
successUrl: ${window.location.origin}/pricing/#mode=subscribe&result=success,
cancelUrl: ${window.location.origin}/pricing/#mode=subscribe&result=cancel,
autoRedirect: false,
...(this.intent === 'update' && this.currentPriceId && {
metadataForCheckout: { 'data-ms-price:update': this.currentPriceId },
}),
};
const checkout = await memberstack.purchasePlansWithCheckout(params);

As a result, after running this code, the user ends up having two subscribed plans in Stripe.

How can I fix this issue?

Comments

1 comment

  • Comment author
    A J

    Hey John Carlo,

    In case those are 2 different plans, you can setup Plan logic and set the logic to cancel a paid plan if another paid plan is purchased accordingly.

    So, you can have the checkout done via code and the removal part can be handled by Plan Logic in Memberstack dashboard.

    Hope this helps.

    0

Please sign in to leave a comment.