Skip to content

Commit

Permalink
⏪ Revert checkout session update existing customer
Browse files Browse the repository at this point in the history
An email should not be tied to a Stripe customer

Closes #1615
  • Loading branch information
baptisteArno committed Jul 2, 2024
1 parent 1d74bce commit 8f741ea
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions ee/packages/billing/api/createCheckoutSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,14 @@ export const createCheckoutSession = async ({
},
})

const existingCustomer = await stripe.customers.list({
email,
})

if (
existingCustomer.data.length > 0 &&
user.email !== existingCustomer.data.at(0)?.email
)
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'Make sure to log in with the same email as the one provided',
})

const customerData = {
const customer = await stripe.customers.create({
email,
name: company,
metadata: { workspaceId },
tax_id_data: vat
? [vat as Stripe.CustomerCreateParams.TaxIdDatum]
: undefined,
}
const customer =
existingCustomer.data.length > 0
? await stripe.customers.update(existingCustomer.data[0].id, customerData)
: await stripe.customers.create(customerData)
})

const checkoutUrl = await createCheckoutSessionUrl(stripe)({
customerId: customer.id,
Expand Down

0 comments on commit 8f741ea

Please sign in to comment.