[PR #7104] [MERGED] fix(stripe): prevent duplicate subscription creation when a subscription already exists #32680

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7104
Author: @bytaesu
Created: 1/3/2026
Status: Merged
Merged: 1/3/2026
Merged by: @himself65

Base: canaryHead: 2026-01-03/fix/prevent-duplicate-subscription-creation


📝 Commits (1)

  • c607d5e fix(stripe): prevent duplicate subscription creation when metadata.subscriptionId exists

📊 Changes

2 files changed (+145 additions, -8 deletions)

View changed files

📝 packages/stripe/src/hooks.ts (+5 -7)
📝 packages/stripe/src/stripe.test.ts (+140 -1)

📄 Description

Recently, customer.subscription.created event handler was added to handle subscription assignments from the Stripe dashboard, but the existing subscription check logic in that handler was weak. This PR fixes this issue.


Summary by cubic

Prevent duplicate subscription creation in the Stripe customer.subscription.created webhook by checking metadata.subscriptionId before creating a new record. Ensures a single subscription per user and closes #7099.

  • Bug Fixes
    • Update onSubscriptionCreated to look up by metadata.subscriptionId first, fallback to stripeSubscriptionId.
    • Add test verifying the webhook skips creating a duplicate when metadata.subscriptionId is present.

Written for commit c607d5ef6b. 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/7104 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 1/3/2026 **Status:** ✅ Merged **Merged:** 1/3/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `2026-01-03/fix/prevent-duplicate-subscription-creation` --- ### 📝 Commits (1) - [`c607d5e`](https://github.com/better-auth/better-auth/commit/c607d5ef6bee6f3bd18942fd5c0ea5728aed4f2f) fix(stripe): prevent duplicate subscription creation when metadata.subscriptionId exists ### 📊 Changes **2 files changed** (+145 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/hooks.ts` (+5 -7) 📝 `packages/stripe/src/stripe.test.ts` (+140 -1) </details> ### 📄 Description Recently, `customer.subscription.created` event handler was added to handle subscription assignments from the Stripe dashboard, but the existing subscription check logic in that handler was weak. This PR fixes this issue. - Closes https://github.com/better-auth/better-auth/issues/7099 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevent duplicate subscription creation in the Stripe customer.subscription.created webhook by checking metadata.subscriptionId before creating a new record. Ensures a single subscription per user and closes #7099. - **Bug Fixes** - Update onSubscriptionCreated to look up by metadata.subscriptionId first, fallback to stripeSubscriptionId. - Add test verifying the webhook skips creating a duplicate when metadata.subscriptionId is present. <sup>Written for commit c607d5ef6bee6f3bd18942fd5c0ea5728aed4f2f. 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:26:10 -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#32680