Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(billing): handle canceled subscriptions in webhook handler (LFE-7643) (#10376)

Michael Fröhlich174d2e43abe8
diff --git a/web/src/ee/features/billing/server/stripeWebhookHandler.ts b/web/src/ee/features/billing/server/stripeWebhookHandler.ts
index afcdcb38aa..15990815af 100644
--- a/web/src/ee/features/billing/server/stripeWebhookHandler.ts
+++ b/web/src/ee/features/billing/server/stripeWebhookHandler.ts
@@ -325,6 +325,19 @@ async function ensureMetadataIsSetOnStripeSubscription(
cloudRegion: currentEnvironment,
};
+ // Check if subscription is in terminal state (canceled or ended)
+ // Stripe does not allow metadata updates on canceled subscriptions
+ if (subscription.status === "canceled" || subscription.ended_at) {
+ logger.info(
+ `[Stripe Webhook] (${currentEnvironment}) Skipping metadata update for ended subscription ${subscription.id}, using org lookup result`,
+ );
+ // Return synthetic subscription with metadata from org lookup
+ return {
+ ...subscription,
+ metadata: metadata,
+ } as Stripe.Subscription;
+ }
+
await stripeClient.subscriptions.update(subscription.id, {
metadata: metadata,
});