Fix billing portal for users without stripeCustomerId (#1936)
This commit is contained in:
parent
3d2fd28214
commit
f8aa274b07
1 changed files with 16 additions and 0 deletions
|
@ -46,7 +46,23 @@ export async function getStripeCustomerId(user: UserType): Promise<string | null
|
||||||
});
|
});
|
||||||
if (customersResponse.data[0]?.id) {
|
if (customersResponse.data[0]?.id) {
|
||||||
customerId = 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;
|
return customerId;
|
||||||
|
|
Loading…
Reference in a new issue