Using stripe with a diferent backend

Hey guys, I'm using the Stripe plugin, but the successUrl and cancelUrl are redirecting to my backend instead of my frontend. How can I change that behavior? I'm using fastify with prisma and nextjs
1 Reply
__maxom__
__maxom__2mo ago
Put the full URL of the frontend in the success and cancel url. Example on the front end:
const redirectURL =
window.location.origin +
location.pathname +
(location.searchStr ? `?${location.searchStr}` : "");

await authClient.subscription.upgrade({
plan: plan,
referenceId: activeOrganization.id,
successUrl: redirectURL,
cancelUrl: redirectURL,
fetchOptions: {
onSuccess: () => {
// Handle successful upgrade, e.g., show a success message or redirect
console.log("Upgrade successful");
},
onError: (error) => {
// Handle error during upgrade
console.error("Upgrade failed", error);
},
},
});
const redirectURL =
window.location.origin +
location.pathname +
(location.searchStr ? `?${location.searchStr}` : "");

await authClient.subscription.upgrade({
plan: plan,
referenceId: activeOrganization.id,
successUrl: redirectURL,
cancelUrl: redirectURL,
fetchOptions: {
onSuccess: () => {
// Handle successful upgrade, e.g., show a success message or redirect
console.log("Upgrade successful");
},
onError: (error) => {
// Handle error during upgrade
console.error("Upgrade failed", error);
},
},
});

Did you find this page helpful?