[PR #7930] [MERGED] feat(stripe): add seat-based billing and usage-based billing #33232

Closed
opened 2026-04-17 23:53:16 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7930
Author: @bytaesu
Created: 2/11/2026
Status: Merged
Merged: 2/11/2026
Merged by: @himself65

Base: canaryHead: 2026-02-12/feat/stripe-seat-and-metered-billing


📝 Commits (8)

  • c069d0c feat(stripe): add seat-based billing and usage-based billing
  • 8797cfe Merge branch 'canary' into 2026-02-12/feat/stripe-seat-and-metered-billing
  • 761d0bc chore: clearer log message
  • 6f80ab8 fix: use datetime
  • 501f2c7 fix: handle plans resolution failure in seat pricing validation
  • 201033e test: remove setTimeout
  • 30e62bc fix: stripe default quantity as fallback
  • 0cdf572 fix: auto-pagination for meters

📊 Changes

10 files changed (+2143 additions, -99 deletions)

View changed files

📝 packages/stripe/src/client.ts (+2 -1)
📝 packages/stripe/src/error-codes.ts (+2 -0)
📝 packages/stripe/src/hooks.ts (+43 -30)
📝 packages/stripe/src/index.ts (+143 -1)
📝 packages/stripe/src/routes.ts (+335 -49)
📝 packages/stripe/src/types.ts (+34 -0)
📝 packages/stripe/src/utils.ts (+114 -18)
packages/stripe/test/metered-billing.test.ts (+424 -0)
packages/stripe/test/seat-based-billing.test.ts (+839 -0)
packages/stripe/test/utils.test.ts (+207 -0)

📄 Description

Note

https://docs.stripe.com/products-prices/pricing-models
https://docs.stripe.com/billing/subscriptions/usage-based


Summary by cubic

Adds seat-based billing with automatic seat sync to Stripe and usage-based metering endpoints. Improves checkout, upgrade, and webhook handling for multi-item subscriptions, with safer quantity resolution and better meter discovery.

  • New Features

    • Seat-based billing
      • Add seatPriceId to plans; seats auto-sync on member add/remove/accept with proration; only active/trialing subs are synced.
      • Robust plan item matching across checkout/success/webhooks; seat quantity resolves from seat item or plan item with Stripe default quantity fallback; persists seat counts.
      • Upgrade swaps base and seat items when seat prices change; improved logging when no plan-matching item is found.
    • Usage-based billing
      • Configure meters with eventName; endpoints:
        • POST /subscription/usage/ingest to send meter events.
        • GET /subscription/usage to fetch usage summaries (user/org, hour/day grouping, pagination).
      • Validates event names; caches Stripe Meter IDs for 5 minutes with auto-pagination; clear errors for unknown meters or missing meter IDs; accepts ISO datetime for timestamps and query window.
  • Migration

    • Enable organization plugin to use seatPriceId; set graduated pricing in Stripe for included seats.
    • Add subscription.meters with Stripe meter event names.
    • If seatPriceId is set without organization enabled, init logs an error.

Written for commit 0cdf57213e. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7930 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 2/11/2026 **Status:** ✅ Merged **Merged:** 2/11/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `2026-02-12/feat/stripe-seat-and-metered-billing` --- ### 📝 Commits (8) - [`c069d0c`](https://github.com/better-auth/better-auth/commit/c069d0c6e2c56c436b10031da68f712aea91d2f2) feat(stripe): add seat-based billing and usage-based billing - [`8797cfe`](https://github.com/better-auth/better-auth/commit/8797cfe1d9dbea5b5ade77bf22352212c72359cf) Merge branch 'canary' into 2026-02-12/feat/stripe-seat-and-metered-billing - [`761d0bc`](https://github.com/better-auth/better-auth/commit/761d0bce4cbf831ebfd31a8b5290c022a76b2b0f) chore: clearer log message - [`6f80ab8`](https://github.com/better-auth/better-auth/commit/6f80ab8fde91e090425185bf9f9b3c86e55e0c81) fix: use datetime - [`501f2c7`](https://github.com/better-auth/better-auth/commit/501f2c7e753e975dab8a6e1afa579a90e4d1f71d) fix: handle plans resolution failure in seat pricing validation - [`201033e`](https://github.com/better-auth/better-auth/commit/201033e1dbd31cdd8406edca43400c09eb525de4) test: remove setTimeout - [`30e62bc`](https://github.com/better-auth/better-auth/commit/30e62bc557d7740ad5ec089047d68e88561c97f8) fix: stripe default quantity as fallback - [`0cdf572`](https://github.com/better-auth/better-auth/commit/0cdf57213e7608fe6d3f9101d76edc54fff8177d) fix: auto-pagination for meters ### 📊 Changes **10 files changed** (+2143 additions, -99 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/client.ts` (+2 -1) 📝 `packages/stripe/src/error-codes.ts` (+2 -0) 📝 `packages/stripe/src/hooks.ts` (+43 -30) 📝 `packages/stripe/src/index.ts` (+143 -1) 📝 `packages/stripe/src/routes.ts` (+335 -49) 📝 `packages/stripe/src/types.ts` (+34 -0) 📝 `packages/stripe/src/utils.ts` (+114 -18) ➕ `packages/stripe/test/metered-billing.test.ts` (+424 -0) ➕ `packages/stripe/test/seat-based-billing.test.ts` (+839 -0) ➕ `packages/stripe/test/utils.test.ts` (+207 -0) </details> ### 📄 Description > [!NOTE] > https://docs.stripe.com/products-prices/pricing-models > https://docs.stripe.com/billing/subscriptions/usage-based <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds seat-based billing with automatic seat sync to Stripe and usage-based metering endpoints. Improves checkout, upgrade, and webhook handling for multi-item subscriptions, with safer quantity resolution and better meter discovery. - **New Features** - Seat-based billing - Add seatPriceId to plans; seats auto-sync on member add/remove/accept with proration; only active/trialing subs are synced. - Robust plan item matching across checkout/success/webhooks; seat quantity resolves from seat item or plan item with Stripe default quantity fallback; persists seat counts. - Upgrade swaps base and seat items when seat prices change; improved logging when no plan-matching item is found. - Usage-based billing - Configure meters with eventName; endpoints: - POST /subscription/usage/ingest to send meter events. - GET /subscription/usage to fetch usage summaries (user/org, hour/day grouping, pagination). - Validates event names; caches Stripe Meter IDs for 5 minutes with auto-pagination; clear errors for unknown meters or missing meter IDs; accepts ISO datetime for timestamps and query window. - **Migration** - Enable organization plugin to use seatPriceId; set graduated pricing in Stripe for included seats. - Add subscription.meters with Stripe meter event names. - If seatPriceId is set without organization enabled, init logs an error. <sup>Written for commit 0cdf57213e7608fe6d3f9101d76edc54fff8177d. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 23:53:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#33232