From f8a4f81991889875a9f887addfba6c33b2a33be0 Mon Sep 17 00:00:00 2001 From: Alex Johansson Date: Tue, 28 Sep 2021 20:48:45 +0100 Subject: [PATCH] fix stripe `customer.subscription.deleted`-webhook (#811) --- ee/pages/api/integrations/stripepayment/webhook.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ee/pages/api/integrations/stripepayment/webhook.ts b/ee/pages/api/integrations/stripepayment/webhook.ts index 8940c12263..df8cc5cadc 100644 --- a/ee/pages/api/integrations/stripepayment/webhook.ts +++ b/ee/pages/api/integrations/stripepayment/webhook.ts @@ -102,13 +102,13 @@ type WebhookHandler = (event: Stripe.Event) => Promise; const webhookHandlers: Record = { "payment_intent.succeeded": handlePaymentSuccess, "customer.subscription.deleted": async (event) => { - const data = event.data as Stripe.Subscription; + const object = event.data.object as Stripe.Subscription; - const customerId = typeof data.customer === "string" ? data.customer : data.customer.id; + const customerId = typeof object.customer === "string" ? object.customer : object.customer.id; const customer = (await stripe.customers.retrieve(customerId)) as Stripe.Customer; if (typeof customer.email !== "string") { - throw new Error(`Couldn't find customer email for ${data.customer}`); + throw new Error(`Couldn't find customer email for ${customerId}`); } await prisma.user.update({