Gadget DevelopersGD
Gadget Developers4mo ago
3 replies
Darcy

Subscribing to development plans with Mantle

I know this is partly a Mantle thing, but I suspect my issue is that I'm not handling this scenario in a way that is compatible with what Gadget is expected. I've worked with the Gadget AI a bit but didn't get it resolved.

When someone subscribes to a Development plan through Mantle, it does not return a confirmationURL property, so I've been trying to either use open() or location.reload() to handle the scenario. With the later, sometimes it works and sometimes I get my unauthenticated page.

I suspect this is some kind of race condition with something happening in the backend that the frontend is not ready, or maybe I'm really missing what is happening.

Here's a sample of my code, would love some help to put me in the right direction:

if (subscription.error) {
  console.error('❌ [SUBSCRIPTION ERROR]: Unable to subscribe to plan', subscription.error);
  shopify.toast.show('There was an error with your subscription.', { isError: true });
} else if (!subscription.confirmationUrl) {
  shopify.toast.show('Successfully subscribed to development plan!');
  setTimeout(() => location.reload(), 1000);
} else {
  shopify.toast.show('Successfully subscribed to your plan!');
  open(subscription.confirmationUrl, '_top');
}

What am I doing wrong?
Was this page helpful?