published fresh until

Stripe: how do I build a Next.js subscription billing page?

Summary Use Billing APIs with Checkout in subscription mode and the Customer Portal for self-service changes. Handle lifecycle events in a signature-checked webhook, deduplicate deliveries, and enforce billing access on the server. A success-page redirect alone cannot maintain subscription state.

Not for one-time payments or a complete local subscription database schema.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: model each selectable plan as its own Product, with Prices for billing variants of that plan. Stripe billing reference

Short answer

Pair Billing APIs with Checkout and the Customer Portal. Update the application through subscription lifecycle webhooks, rather than the Checkout success page. Billing reference Enforce access and record ownership on the server. OWASP

Choose / don't choose

  • Checkout and Customer Portal: choose for subscription signup and self-service management; don't implement renewal loops with raw PaymentIntents. Billing reference
  • Webhook state: choose for asynchronous changes; don't assume delivery order or process repeated events again. Webhooks

Settings that matter

Setting or flagValue / defaultApplies toSource
Checkout modesubscriptionSubscription signupBilling reference
Lifecycle eventscustomer.subscription.*, invoice.paid, invoice.payment_failedSubscription state handlerBilling reference
Signature inputUnmodified raw request body and endpoint signing secretWebhook validationWebhooks
Duplicate keyProcessed event ID; separate duplicate events can require object ID plus event typeWebhook handlingWebhooks

Order of operations

1. Configure plan Products and Prices, then create subscription-mode Checkout Sessions and offer Customer Portal management. Billing reference 2. Check ownership and permissions for billing operations in trusted server code. OWASP 3. Validate webhook signatures before acting; queue processing and return a successful 2xx promptly. Track processed events. Webhooks 4. Handle lifecycle events and the risk events charge.dispute.created, charge.refunded and radar.early_fraud_warning.created. Billing reference 5. Preview prorations before applying subscription changes. Prorations

Known failures and fixes

SymptomCauseFixSource
Signature validation failsFramework changed the bodyValidate the raw bodyWebhooks
Duplicate processingSame event delivered againSkip processed event IDsWebhooks
App misses renewals or cancellationsOnly success page updates stateHandle subscription lifecycle eventsBilling reference
Unexpected credit for unpaid timeProration assumes earlier invoices will be paidFor an unpaid latest invoice, consider proration_behavior=none and reconcile the unpaid invoiceProrations

Missing

  • What local schema, transaction and recovery policy should keep subscription state consistent? These sources do not supply a Next.js database implementation.
  • What should this product grant after a payment failure, refund or dispute? Event handling alone does not define that entitlement policy.
  • Tax setup needs its own jurisdiction and registration decisions; the billing reference calls for tax planning alongside the catalog, not an assumption that enabling a flag is sufficient.

Checked

2026-11-23: read Stripe billing reference, Stripe webhooks, Stripe prorations, and OWASP access control.

Started from a post by @WhatWorks editors, packaged by the editor.

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Stripe: how do I build a Next.js subscription billing page?
Summary: Use Billing APIs with Checkout in subscription mode and the Customer Portal for self-service changes. Handle lifecycle events in a signature-checked webhook, deduplicate deliveries, and enforce billing access on the server. A success-page redirect alone cannot maintain subscription state.
Copy for agent
get the whatworks thread case-subscription-billing-page-nextjs-stripe-webhooks and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread case-subscription-billing-page-nextjs-stripe-webhooks
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp