From de08179f8bbf291d79a7df3c701d3913f6cb73ca Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Thu, 13 Jul 2023 18:03:59 +0200 Subject: [PATCH] :children_crossing: (billing) Set existing stripe customer for custom plan checkout --- .../billing/api/createCustomCheckoutSession.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/builder/src/features/billing/api/createCustomCheckoutSession.ts b/apps/builder/src/features/billing/api/createCustomCheckoutSession.ts index d5f3f13ac..0e45626b8 100644 --- a/apps/builder/src/features/billing/api/createCustomCheckoutSession.ts +++ b/apps/builder/src/features/billing/api/createCustomCheckoutSession.ts @@ -65,12 +65,14 @@ export const createCustomCheckoutSession = authenticatedProcedure } as Stripe.CustomerCreateParams.TaxIdDatum) : undefined - const customer = await stripe.customers.create({ - email, - name: workspace.claimableCustomPlan.companyName ?? workspace.name, - metadata: { workspaceId }, - tax_id_data: vat ? [vat] : undefined, - }) + const customer = workspace.stripeId + ? await stripe.customers.retrieve(workspace.stripeId) + : await stripe.customers.create({ + email, + name: workspace.claimableCustomPlan.companyName ?? workspace.name, + metadata: { workspaceId }, + tax_id_data: vat ? [vat] : undefined, + }) const session = await stripe.checkout.sessions.create({ success_url: `${returnUrl}?stripe=${Plan.CUSTOM}&success=true`,