From 5df41e37a0b5b89551c32c9504c9558c1a0b05f2 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 24 Nov 2023 10:18:06 -0300 Subject: [PATCH] fix: Stripe webhook event mismatch (#12522) --- .env.example | 1 + apps/web/pages/api/integrations/subscriptions/webhook.ts | 6 +++--- packages/types/environment.d.ts | 1 + turbo.json | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 6d71f204ea..64a1bfcf77 100644 --- a/.env.example +++ b/.env.example @@ -155,6 +155,7 @@ NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE= STRIPE_TEAM_MONTHLY_PRICE_ID= STRIPE_ORG_MONTHLY_PRICE_ID= STRIPE_WEBHOOK_SECRET= +STRIPE_WEBHOOK_SECRET_APPS= STRIPE_PRIVATE_KEY= STRIPE_CLIENT_ID= PAYMENT_FEE_FIXED= diff --git a/apps/web/pages/api/integrations/subscriptions/webhook.ts b/apps/web/pages/api/integrations/subscriptions/webhook.ts index 63f4cba477..c1bb8b3790 100644 --- a/apps/web/pages/api/integrations/subscriptions/webhook.ts +++ b/apps/web/pages/api/integrations/subscriptions/webhook.ts @@ -83,13 +83,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) throw new HttpCode({ statusCode: 400, message: "Missing stripe-signature" }); } - if (!process.env.STRIPE_WEBHOOK_SECRET) { - throw new HttpCode({ statusCode: 500, message: "Missing process.env.STRIPE_WEBHOOK_SECRET" }); + if (!process.env.STRIPE_WEBHOOK_SECRET_APPS) { + throw new HttpCode({ statusCode: 500, message: "Missing process.env.STRIPE_WEBHOOK_SECRET_APPS" }); } const requestBuffer = await buffer(req); const payload = requestBuffer.toString(); - const event = stripe.webhooks.constructEvent(payload, sig, process.env.STRIPE_WEBHOOK_SECRET); + const event = stripe.webhooks.constructEvent(payload, sig, process.env.STRIPE_WEBHOOK_SECRET_APPS); const handler = webhookHandlers[event.type]; if (handler) { diff --git a/packages/types/environment.d.ts b/packages/types/environment.d.ts index 006be0478d..caee882791 100644 --- a/packages/types/environment.d.ts +++ b/packages/types/environment.d.ts @@ -27,6 +27,7 @@ declare namespace NodeJS { readonly STRIPE_PRIVATE_KEY: string | undefined; readonly STRIPE_CLIENT_ID: string | undefined; readonly STRIPE_WEBHOOK_SECRET: string | undefined; + readonly STRIPE_WEBHOOK_SECRET_APPS: string | undefined; readonly PAYMENT_FEE_PERCENTAGE: number | undefined; readonly PAYMENT_FEE_FIXED: number | undefined; readonly NEXT_PUBLIC_INTERCOM_APP_ID: string | undefined; diff --git a/turbo.json b/turbo.json index 0d7226a8ec..4344ae0f25 100644 --- a/turbo.json +++ b/turbo.json @@ -312,6 +312,7 @@ "STRIPE_PRODUCT_ID_SCALE", "STRIPE_PRODUCT_ID_STARTER", "STRIPE_WEBHOOK_SECRET", + "STRIPE_WEBHOOK_SECRET_APPS", "TANDEM_BASE_URL", "TANDEM_CLIENT_ID", "TANDEM_CLIENT_SECRET",