From f68b65fe5f732d48b9715fdb2a079a8fe94b564a Mon Sep 17 00:00:00 2001 From: Mythie Date: Wed, 25 Oct 2023 13:13:57 +1100 Subject: [PATCH] fix: update customer handling for checkouts --- .../settings/billing/create-checkout.action.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/web/src/app/(dashboard)/settings/billing/create-checkout.action.ts b/apps/web/src/app/(dashboard)/settings/billing/create-checkout.action.ts index f556133f0..2f07c37dd 100644 --- a/apps/web/src/app/(dashboard)/settings/billing/create-checkout.action.ts +++ b/apps/web/src/app/(dashboard)/settings/billing/create-checkout.action.ts @@ -1,5 +1,6 @@ 'use server'; +import { createCustomer } from '@documenso/ee/server-only/stripe/create-customer'; import { getCheckoutSession } from '@documenso/ee/server-only/stripe/get-checkout-session'; import { getStripeCustomerByEmail, @@ -7,7 +8,7 @@ import { } from '@documenso/ee/server-only/stripe/get-customer'; import { getPortalSession } from '@documenso/ee/server-only/stripe/get-portal-session'; import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-server-session'; -import { Stripe, stripe } from '@documenso/lib/server-only/stripe'; +import { Stripe } from '@documenso/lib/server-only/stripe'; import { getSubscriptionByUserId } from '@documenso/lib/server-only/subscription/get-subscription-by-user-id'; export type CreateCheckoutOptions = { @@ -42,13 +43,11 @@ export const createCheckout = async ({ priceId }: CreateCheckoutOptions) => { // Create a Stripe customer if it does not exist for the current user. if (!stripeCustomer) { - stripeCustomer = await stripe.customers.create({ - name: user.name ?? undefined, - email: user.email, - metadata: { - userId: user.id, - }, + await createCustomer({ + user, }); + + stripeCustomer = await getStripeCustomerByEmail(user.email); } return getCheckoutSession({