diff --git a/server/src/internal/customers/handlers/handleBillingPortal/createBillingPortalSession.ts b/server/src/internal/customers/handlers/handleBillingPortal/createBillingPortalSession.ts index 373611023..cbe0dc716 100644 --- a/server/src/internal/customers/handlers/handleBillingPortal/createBillingPortalSession.ts +++ b/server/src/internal/customers/handlers/handleBillingPortal/createBillingPortalSession.ts @@ -43,6 +43,7 @@ export const createBillingPortalSession = async ({ } // 1. Try to create billing portal session + try { return await stripeCli.billingPortal.sessions.create({ customer: stripeCustomerId, diff --git a/server/src/internal/customers/handlers/handleBillingPortal/handleCreateBillingPortal.ts b/server/src/internal/customers/handlers/handleBillingPortal/handleCreateBillingPortal.ts index 645bb1fd1..0f84ef022 100644 --- a/server/src/internal/customers/handlers/handleBillingPortal/handleCreateBillingPortal.ts +++ b/server/src/internal/customers/handlers/handleBillingPortal/handleCreateBillingPortal.ts @@ -19,7 +19,8 @@ export const handleCreateBillingPortal = createRoute({ const { db, org, env } = ctx; const { return_url: returnUrl } = c.req.valid("query"); const { customer_id: customerId } = c.req.param(); - const { configuration_id: configurationId } = c.req.valid("json") ?? {}; + const { configuration_id: configurationId, return_url: returnUrl2 } = + c.req.valid("json") ?? {}; const customer = await CusService.get({ db, @@ -35,7 +36,7 @@ export const handleCreateBillingPortal = createRoute({ const session = await createBillingPortalSession({ ctx, customer, - returnUrl, + returnUrl: returnUrl2 || returnUrl, configurationId, }); diff --git a/shared/api/customers/customerOpModels.ts b/shared/api/customers/customerOpModels.ts index 98535bcfb..cc5909ba4 100644 --- a/shared/api/customers/customerOpModels.ts +++ b/shared/api/customers/customerOpModels.ts @@ -159,6 +159,10 @@ export const GetBillingPortalBodySchema = z description: "Stripe billing portal configuration ID. Create configurations in your Stripe dashboard.", }), + return_url: z.string().optional().meta({ + description: + "URL to redirect to when back button is clicked in the billing portal", + }), }) .optional();