Skip to content

Commit

Permalink
Handle statuses of Stripe event checkout.session.completed (#2361)
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph authored Nov 3, 2023
1 parent da94998 commit c415c6f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions front/pages/api/stripe/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down

0 comments on commit c415c6f

Please sign in to comment.