mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
fix: update webhook handler
This commit is contained in:
@ -52,7 +52,31 @@ export const stripeWebhookHandler = async (
|
|||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
const session = event.data.object as Stripe.Checkout.Session;
|
const session = event.data.object as Stripe.Checkout.Session;
|
||||||
|
|
||||||
const userId = Number(session.client_reference_id);
|
const customerId =
|
||||||
|
typeof session.customer === 'string' ? session.customer : session.customer?.id;
|
||||||
|
|
||||||
|
let userId = Number(session.client_reference_id);
|
||||||
|
|
||||||
|
if (!userId && customerId) {
|
||||||
|
const result = await prisma.subscription.findFirst({
|
||||||
|
select: {
|
||||||
|
userId: true,
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
customerId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result?.userId) {
|
||||||
|
return res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: 'User not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
userId = result.userId;
|
||||||
|
}
|
||||||
|
|
||||||
const subscriptionId =
|
const subscriptionId =
|
||||||
typeof session.subscription === 'string'
|
typeof session.subscription === 'string'
|
||||||
? session.subscription
|
? session.subscription
|
||||||
|
|||||||
Reference in New Issue
Block a user