[PR #6924] [MERGED] feat(stripe): handle customer.subscription.created webhook event #23870

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6924
Author: @bytaesu
Created: 12/21/2025
Status: Merged
Merged: 12/30/2025
Merged by: @bytaesu

Base: canaryHead: 2025-12-22/feat/stripe-sub-created-hook


📝 Commits (10+)

  • 5ad5eec feat: handle customer.subscription.created webhook event
  • 4364e7c test: add tests for customer.subscription.created webhook
  • ed80ade docs: add customer.subscription.created content
  • b00b303 docs: add missing subscription options
  • 2488a37 fix(stripe): logger from context
  • 005f9e6 Merge branch 'canary' into 2025-12-22/feat/stripe-sub-created-hook
  • 70e8130 Update packages/stripe/src/types.ts
  • 682dc7f test: clean up logger testing
  • 8aab427 test: clean up imports
  • 059d310 docs(stripe): update option section to use table

📊 Changes

6 files changed (+574 additions, -49 deletions)

View changed files

📝 docs/content/docs/plugins/stripe.mdx (+49 -40)
📝 packages/stripe/src/hooks.ts (+123 -7)
📝 packages/stripe/src/middleware.ts (+1 -2)
📝 packages/stripe/src/routes.ts (+5 -0)
📝 packages/stripe/src/stripe.test.ts (+384 -0)
📝 packages/stripe/src/types.ts (+12 -0)

📄 Description

This PR changes:

  • Handles customer.subscription.created webhook to sync subscriptions created outside the checkout flow (e.g. Stripe Dashboard or API)
  • Updated Stripe plugin to use logger from context instead of global

To-do

  • Verify behavior in the real app setup

Summary by cubic

Add support for the Stripe customer.subscription.created webhook to sync subscriptions created outside checkout with our database and prevent broken subscription states.

  • New Features

    • Handle customer.subscription.created in the webhook route.
    • Create subscription records for users matched by stripeCustomerId; map plan via priceId/lookup_key; set seats, period, and trial dates.
    • Add subscription.onSubscriptionCreated callback and document it; docs updated to include the event and getCheckoutSessionParams.
  • Bug Fixes

    • Skip creation if the subscription already exists; guard when user or plan is missing; use request-scoped logging.
    • Add tests for success, duplicate, missing user, and missing plan scenarios.

Written for commit cf7243d249. 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/6924 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 12/21/2025 **Status:** ✅ Merged **Merged:** 12/30/2025 **Merged by:** [@bytaesu](https://github.com/bytaesu) **Base:** `canary` ← **Head:** `2025-12-22/feat/stripe-sub-created-hook` --- ### 📝 Commits (10+) - [`5ad5eec`](https://github.com/better-auth/better-auth/commit/5ad5eec456bce95e1e1076335c9cb4fdae611132) feat: handle customer.subscription.created webhook event - [`4364e7c`](https://github.com/better-auth/better-auth/commit/4364e7c357cf5a235a03b67a673d0c819cb456aa) test: add tests for customer.subscription.created webhook - [`ed80ade`](https://github.com/better-auth/better-auth/commit/ed80adec1281fe1d43b7bb634b06c070a233237b) docs: add customer.subscription.created content - [`b00b303`](https://github.com/better-auth/better-auth/commit/b00b3032e68ce7bd20121c90ea9643f2be048d05) docs: add missing subscription options - [`2488a37`](https://github.com/better-auth/better-auth/commit/2488a37d716e39ef74f7d3215de5ef577d646c23) fix(stripe): logger from context - [`005f9e6`](https://github.com/better-auth/better-auth/commit/005f9e638512826c06c29a0f6423d2006f55a2e8) Merge branch 'canary' into 2025-12-22/feat/stripe-sub-created-hook - [`70e8130`](https://github.com/better-auth/better-auth/commit/70e8130b45168ac26a075f0d1772cb8ff6f23011) Update packages/stripe/src/types.ts - [`682dc7f`](https://github.com/better-auth/better-auth/commit/682dc7f8f1887f8c74a01a058c2312128856366a) test: clean up logger testing - [`8aab427`](https://github.com/better-auth/better-auth/commit/8aab4275db211c2a68c708b87d20be6b14969325) test: clean up imports - [`059d310`](https://github.com/better-auth/better-auth/commit/059d310f53339cd17efc9a17c6265f537e556c1f) docs(stripe): update option section to use table ### 📊 Changes **6 files changed** (+574 additions, -49 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/stripe.mdx` (+49 -40) 📝 `packages/stripe/src/hooks.ts` (+123 -7) 📝 `packages/stripe/src/middleware.ts` (+1 -2) 📝 `packages/stripe/src/routes.ts` (+5 -0) 📝 `packages/stripe/src/stripe.test.ts` (+384 -0) 📝 `packages/stripe/src/types.ts` (+12 -0) </details> ### 📄 Description This PR changes: - Handles `customer.subscription.created` webhook to sync subscriptions created outside the checkout flow (e.g. Stripe Dashboard or API) - Updated Stripe plugin to use `logger` from context instead of global ### To-do - [x] Verify behavior in the real app setup <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add support for the Stripe customer.subscription.created webhook to sync subscriptions created outside checkout with our database and prevent broken subscription states. - **New Features** - Handle customer.subscription.created in the webhook route. - Create subscription records for users matched by stripeCustomerId; map plan via priceId/lookup_key; set seats, period, and trial dates. - Add subscription.onSubscriptionCreated callback and document it; docs updated to include the event and getCheckoutSessionParams. - **Bug Fixes** - Skip creation if the subscription already exists; guard when user or plan is missing; use request-scoped logging. - Add tests for success, duplicate, missing user, and missing plan scenarios. <sup>Written for commit cf7243d24925a373c90d6aeab6227a5a269d1d37. 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:01:58 -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#23870