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');
}
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?
3 Replies
Chocci_Milk
Chocci_Milk2w ago
Hello, This doesn't sound like a race condition or something wrong with Gadget. The Mantle hook is the one that takes care of all the requests and getting you the confirtmation URL. I would recommend reaching out to them to see what might be wrong. Have you also double checked your implementation? I would recommend taking a look at Mantle's Gadget use case tutorial
Darcy
DarcyOP2w ago
I'll reach out to them. My implementation is nearly a clone of their documentation with these conditional checks due to the errors I was seeing.
Gizmo
Gizmo2w ago
Do you like this answer? ​

Did you find this page helpful?