[PR #7116] [CLOSED] feat(stripe): add support for multiple product subscriptions per user #23987

Closed
opened 2026-04-15 22:06:30 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7116
Author: @hasdfa
Created: 1/4/2026
Status: Closed

Base: canaryHead: feat/stripe-multi-product-subscriptions


📝 Commits (1)

  • 7f2b862 feat(stripe): add support for multiple product subscriptions per user

📊 Changes

8 files changed (+1499 additions, -39 deletions)

View changed files

📝 docs/content/docs/plugins/stripe.mdx (+129 -20)
📝 packages/stripe/CHANGELOG.md (+33 -0)
📝 packages/stripe/src/error-codes.ts (+4 -0)
📝 packages/stripe/src/hooks.ts (+36 -7)
📝 packages/stripe/src/routes.ts (+95 -12)
📝 packages/stripe/src/schema.ts (+4 -0)
📝 packages/stripe/src/stripe.test.ts (+1184 -0)
📝 packages/stripe/src/utils.ts (+14 -0)

📄 Description

Summary

  • Added support for multiple product subscriptions per user/reference
  • Users can now subscribe to multiple products simultaneously (e.g., "Pro Plan" + "AI Addon" + "Storage Addon")
  • Plans in the same group upgrade each other, plans in different groups create separate subscriptions

New Features

  • Added groupId field to subscription schema for grouping subscriptions by product line
  • Added groupId parameter to cancel and restore endpoints for disambiguation
  • Added groupId filter to list subscriptions endpoint
  • Improved webhook handling for multi-subscription scenarios
  • Added groupsMatch utility for null-safe group comparison

Usage

// Define plans with groups
plans: [
  { name: "pro", priceId: "price_xxx", group: "main" },
  { name: "ai-addon", priceId: "price_yyy", group: "ai" },
]

// Subscribe to multiple products
await client.subscription.upgrade({ plan: "pro" });      // main group
await client.subscription.upgrade({ plan: "ai-addon" }); // ai group (separate subscription)

// Cancel specific subscription
await client.subscription.cancel({ groupId: "ai", returnUrl: "/" });

Breaking Changes

None. Fully backwards compatible - existing subscriptions without groupId continue to work as before.

Test plan

  • Added 16 comprehensive tests for group subscriptions
  • All 64 tests in stripe.test.ts pass
  • Tested basic group subscription creation
  • Tested multi-product subscriptions in different groups
  • Tested upgrade within same group
  • Tested cancel/restore with multiple subscriptions
  • Tested webhook handling with groups
  • Tested edge cases and backwards compatibility

Summary by cubic

Add multi-product subscriptions to the Stripe plugin using plan groups, so users can subscribe to a main plan plus add-ons at the same time. Updates APIs, webhooks, and docs, and remains fully backward compatible.

  • New Features

    • Added groupId to the subscription schema; plans in the same group upgrade each other, different groups create separate subscriptions.
    • Added groupId to cancel and restore endpoints; required when a user has multiple active subscriptions.
    • Added groupId filter to list subscriptions.
    • Webhooks now persist groupId from metadata and match the correct subscription in multi-sub scenarios.
    • New utility groupsMatch for null-safe group comparison and new error codes for disambiguation.
    • Documentation updated for multi-product setup and management.
  • Migration

    • No breaking changes; existing subscriptions without groupId continue to work.
    • To enable multiple products, add group to plans.
    • When multiple subscriptions exist, pass groupId or subscriptionId to cancel/restore.

Written for commit 7f2b862afa. 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/7116 **Author:** [@hasdfa](https://github.com/hasdfa) **Created:** 1/4/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/stripe-multi-product-subscriptions` --- ### 📝 Commits (1) - [`7f2b862`](https://github.com/better-auth/better-auth/commit/7f2b862afafb4c89be3f7c89569ad3829b624b37) feat(stripe): add support for multiple product subscriptions per user ### 📊 Changes **8 files changed** (+1499 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/stripe.mdx` (+129 -20) 📝 `packages/stripe/CHANGELOG.md` (+33 -0) 📝 `packages/stripe/src/error-codes.ts` (+4 -0) 📝 `packages/stripe/src/hooks.ts` (+36 -7) 📝 `packages/stripe/src/routes.ts` (+95 -12) 📝 `packages/stripe/src/schema.ts` (+4 -0) 📝 `packages/stripe/src/stripe.test.ts` (+1184 -0) 📝 `packages/stripe/src/utils.ts` (+14 -0) </details> ### 📄 Description ## Summary - Added support for multiple product subscriptions per user/reference - Users can now subscribe to multiple products simultaneously (e.g., "Pro Plan" + "AI Addon" + "Storage Addon") - Plans in the same `group` upgrade each other, plans in different groups create separate subscriptions ## New Features - Added `groupId` field to subscription schema for grouping subscriptions by product line - Added `groupId` parameter to cancel and restore endpoints for disambiguation - Added `groupId` filter to list subscriptions endpoint - Improved webhook handling for multi-subscription scenarios - Added `groupsMatch` utility for null-safe group comparison ## Usage ```ts // Define plans with groups plans: [ { name: "pro", priceId: "price_xxx", group: "main" }, { name: "ai-addon", priceId: "price_yyy", group: "ai" }, ] // Subscribe to multiple products await client.subscription.upgrade({ plan: "pro" }); // main group await client.subscription.upgrade({ plan: "ai-addon" }); // ai group (separate subscription) // Cancel specific subscription await client.subscription.cancel({ groupId: "ai", returnUrl: "/" }); ``` ## Breaking Changes None. Fully backwards compatible - existing subscriptions without `groupId` continue to work as before. ## Test plan - [x] Added 16 comprehensive tests for group subscriptions - [x] All 64 tests in stripe.test.ts pass - [x] Tested basic group subscription creation - [x] Tested multi-product subscriptions in different groups - [x] Tested upgrade within same group - [x] Tested cancel/restore with multiple subscriptions - [x] Tested webhook handling with groups - [x] Tested edge cases and backwards compatibility <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add multi-product subscriptions to the Stripe plugin using plan groups, so users can subscribe to a main plan plus add-ons at the same time. Updates APIs, webhooks, and docs, and remains fully backward compatible. - **New Features** - Added groupId to the subscription schema; plans in the same group upgrade each other, different groups create separate subscriptions. - Added groupId to cancel and restore endpoints; required when a user has multiple active subscriptions. - Added groupId filter to list subscriptions. - Webhooks now persist groupId from metadata and match the correct subscription in multi-sub scenarios. - New utility groupsMatch for null-safe group comparison and new error codes for disambiguation. - Documentation updated for multi-product setup and management. - **Migration** - No breaking changes; existing subscriptions without groupId continue to work. - To enable multiple products, add group to plans. - When multiple subscriptions exist, pass groupId or subscriptionId to cancel/restore. <sup>Written for commit 7f2b862afafb4c89be3f7c89569ad3829b624b37. 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-15 22:06:30 -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#23987