From c415c6f691a44f14ecbb727b567700efb8f25249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daphn=C3=A9=20Popin?= Date: Fri, 3 Nov 2023 13:06:06 +0100 Subject: [PATCH] Handle statuses of Stripe event checkout.session.completed (#2361) --- front/pages/api/stripe/webhook.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/front/pages/api/stripe/webhook.ts b/front/pages/api/stripe/webhook.ts index cfac3bf7f218..fa0fa7d5784e 100644 --- a/front/pages/api/stripe/webhook.ts +++ b/front/pages/api/stripe/webhook.ts @@ -89,6 +89,33 @@ async function handler( const stripeSubscriptionId = session.subscription; const planCode = session?.metadata?.planCode || null; + if (session.status === "open" || session.status === "expired") { + // Open: The checkout session is still in progress. Payment processing has not started. + // Expired: The checkout session has expired (e.g., because of lack of payment). + logger.info( + { + workspaceId, + stripeCustomerId, + stripeSubscriptionId, + planCode, + }, + `[Stripe Webhook] Received checkout.session.completed with status "${session.status}". Ignoring event.` + ); + return; + } + if (session.status !== "complete") { + logger.error( + { + workspaceId, + stripeCustomerId, + stripeSubscriptionId, + planCode, + }, + `[Stripe Webhook] Received checkout.session.completed with unkown status "${session.status}". Ignoring event.` + ); + return; + } + try { if ( workspaceId === null ||