Fix billing portal for users without stripeCustomerId (#1936)

This commit is contained in:
alannnc 2022-02-23 15:51:10 -07:00 committed by GitHub
parent 3d2fd28214
commit f8aa274b07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,7 +46,23 @@ export async function getStripeCustomerId(user: UserType): Promise<string | null
});
if (customersResponse.data[0]?.id) {
customerId = customersResponse.data[0].id;
} else {
/* Creating customer on Stripe and saving it on prisma */
const customer = await stripe.customers.create({ email: user.email });
customerId = customer.id;
}
await prisma.user.update({
where: {
email: user.email,
},
data: {
metadata: {
...(user.metadata as Prisma.JsonObject),
stripeCustomerId: customerId,
},
},
});
}
return customerId;