Skip to content

fix: 🐛 a bug where upgrade webhooks weren't being sent#863

Merged
johnyeocx merged 1 commit intomainfrom
fix/webhook-upgrades-not-sending
Mar 3, 2026
Merged

fix: 🐛 a bug where upgrade webhooks weren't being sent#863
johnyeocx merged 1 commit intomainfrom
fix/webhook-upgrades-not-sending

Conversation

@SirTenzin
Copy link
Member

@SirTenzin SirTenzin commented Mar 2, 2026

Summary by cubic

Fixes missing customer.products.updated webhooks for upgrades completed via Stripe Checkout (metadata v2 path). Free → Pro upgrades now reliably trigger the webhook.

  • Bug Fixes
    • Queue products-updated webhook in handleCheckoutSessionMetadataV2 by calling billingPlanToSendProductsUpdated with the updated plan and billing context (mirrors executeBillingPlan).
    • Added integration tests for v1 and v2 attach flows that complete a real Checkout and assert the webhook is received for Free → Pro upgrades.

Written for commit cfc4097. Summary will update on new commits.

Greptile Summary

Fixed a bug where customer.products.updated webhooks weren't being sent after checkout session completion in the V2 metadata handler. The fix adds a call to billingPlanToSendProductsUpdated after executing the Autumn billing plan, mirroring the pattern already established in executeBillingPlan.

Key Changes

Bug fixes:

  • Added missing webhook queuing in handleCheckoutSessionMetadataV2 after checkout completion (lines 66-71)
  • Ensures webhooks fire correctly for free-to-pro upgrades via Stripe Checkout

Improvements:

  • Added comprehensive integration tests for both V1 and V2 APIs that verify webhooks are sent correctly during checkout-based upgrades
  • Tests use Svix Play for webhook verification and browser automation for end-to-end Stripe Checkout flow

The implementation correctly follows the established pattern from executeBillingPlan.ts, queuing webhooks after the billing plan is executed but before cleanup operations.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is a focused single-line addition that follows an established pattern from executeBillingPlan. The implementation uses correct types (StripeWebhookContext extends AutumnContext), passes the right parameters, and is placed in the correct sequence (after billing plan execution, before cleanup). Two comprehensive integration tests verify the fix works end-to-end for both V1 and V2 APIs, including webhook delivery verification via Svix Play.
  • No files require special attention

Important Files Changed

Filename Overview
server/src/external/stripe/webhookHandlers/handleStripeCheckoutSessionCompleted/tasks/handleCheckoutSessionMetadataV2/handleCheckoutSessionMetadataV2.ts Added missing call to queue customer.products.updated webhook after checkout completion, mirroring the pattern in executeBillingPlan
server/tests/integration/billing/autumn-webhooks/free-to-pro-upgrade-v1-webhook.test.ts Added integration test verifying free-to-pro upgrade webhooks fire correctly via Stripe Checkout using V1 API
server/tests/integration/billing/autumn-webhooks/free-to-pro-upgrade-v2-webhook.test.ts Added integration test verifying free-to-pro upgrade webhooks fire correctly via Stripe Checkout using V2 API

Last reviewed commit: cfc4097

@vercel
Copy link

vercel bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
autumn-vite Building Building Preview, Comment Mar 2, 2026 3:51pm

Request Review

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Confidence score: 3/5

  • Test gap could allow a regression to slip: server/tests/integration/billing/autumn-webhooks/free-to-pro-upgrade-v2-webhook.test.ts doesn’t assert scenario === "new", so the intended behavior isn’t fully verified.
  • Some risk remains because the most severe issue is a concrete missing assertion in a high‑confidence test, which could mask user‑impacting webhook changes.
  • Pay close attention to server/tests/integration/billing/autumn-webhooks/free-to-pro-upgrade-v2-webhook.test.ts - missing scenario assertion may let incorrect upgrade flows pass.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="server/tests/integration/billing/autumn-webhooks/free-to-pro-upgrade-v2-webhook.test.ts">

<violation number="1" location="server/tests/integration/billing/autumn-webhooks/free-to-pro-upgrade-v2-webhook.test.ts:147">
P1: The upgrade webhook check does not assert `scenario === "new"`, so this test can pass with an incorrect scenario and miss the regression it is intended to catch.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

predicate: (payload) =>
payload.type === "customer.products.updated" &&
payload.data?.customer?.id === customerId &&
payload.data?.updated_product?.id === pro.id,
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The upgrade webhook check does not assert scenario === "new", so this test can pass with an incorrect scenario and miss the regression it is intended to catch.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At server/tests/integration/billing/autumn-webhooks/free-to-pro-upgrade-v2-webhook.test.ts, line 147:

<comment>The upgrade webhook check does not assert `scenario === "new"`, so this test can pass with an incorrect scenario and miss the regression it is intended to catch.</comment>

<file context>
@@ -0,0 +1,165 @@
+				predicate: (payload) =>
+					payload.type === "customer.products.updated" &&
+					payload.data?.customer?.id === customerId &&
+					payload.data?.updated_product?.id === pro.id,
+				timeoutMs: 20000,
+			},
</file context>
Fix with Cubic

@johnyeocx johnyeocx merged commit b944872 into main Mar 3, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants