[PR #6961] [MERGED] feat(stripe): flexible subscription cancellation and termination management #32593

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6961
Author: @bytaesu
Created: 12/23/2025
Status: Merged
Merged: 12/26/2025
Merged by: @himself65

Base: canaryHead: 2025-12-24/feat/stripe-subscription-status


📝 Commits (10+)

  • 54ea989 feat(stripe): add cancelAt, canceledAt and endedAt fields
  • 0b54dfb add utils to manage subscription status easily
  • e323dc1 update to use new fields and utils
  • 6958ed0 test: add test cases for subscription cancellation and termination
  • e58cff6 fix: missing imports, broken syntax and some condition check
  • cd80514 docs(stripe): add new fields and explanation for cancellation
  • e648e52 Merge branch 'canary' into 2025-12-24/feat/stripe-subscription-status
  • 8474f23 Merge branch 'canary' into 2025-12-24/feat/stripe-subscription-status
  • 84e6a7b fix: correct stripe api error message handling
  • b65088d Merge branch 'canary' into 2025-12-24/feat/stripe-subscription-status

📊 Changes

7 files changed (+909 additions, -92 deletions)

View changed files

📝 docs/content/docs/plugins/stripe.mdx (+42 -2)
📝 packages/stripe/src/hooks.ts (+43 -10)
📝 packages/stripe/src/routes.ts (+89 -78)
📝 packages/stripe/src/schema.ts (+12 -0)
📝 packages/stripe/src/stripe.test.ts (+680 -0)
📝 packages/stripe/src/types.ts (+18 -1)
📝 packages/stripe/src/utils.ts (+25 -1)

📄 Description

This PR improves https://github.com/better-auth/better-auth/pull/5487, which was implemented by @GautamBytes


This PR includes the following changes:

  • Add cancelAt, canceledAt, and endedAt fields
  • Add internal utilities for subscription status management
  • Improve handling of subscription cancellation in hooks and routes
  • Add tests related to cancellation and termination
  • Update Stripe plugin docs content

Note

I tested the schema changes with active and canceled subscribers on the existing schema and confirmed it’s not a breaking change.

  • The new logic still checks cancelAtPeriodEnd
  • All added fields are nullable

This means the existing cancellation state logic based on cancelAtPeriodEnd continues to work, with additional fields added for more accurate management. The fields are synchronized more precisely when webhook events are received.

Closes https://github.com/better-auth/better-auth/issues/5388
Closes https://github.com/better-auth/better-auth/issues/5535
Closes https://github.com/better-auth/better-auth/issues/5780

To-do

  • Test with actual app
  • Update documentation

Summary by cubic

Adds flexible subscription cancellation and termination handling in the Stripe plugin, with precise tracking for scheduled cancels and immediate ends. Introduces new fields and utilities to keep state in sync across webhooks and API routes.

  • New Features

    • Add cancelAt, canceledAt, and endedAt to Subscription for accurate state tracking.
    • Use helpers (isActiveOrTrialing, isPendingCancel, isStripePendingCancel) to standardize status checks.
    • Sync cancellation fields in checkout, update, and delete webhooks and route callbacks, with a fallback for missed Stripe events.
    • Restore flow clears either cancel_at or cancel_at_period_end based on the current Stripe subscription state.
    • Add comprehensive tests for webhook scenarios, restore behavior, and fallback sync; update Stripe plugin docs.
  • Migration

    • Breaking: database schema adds cancelAt, canceledAt, endedAt.
    • Run migrations and ensure adapter mappings include the new fields.

Written for commit b65088d6bb. Summary will update automatically 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/6961 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 12/23/2025 **Status:** ✅ Merged **Merged:** 12/26/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `2025-12-24/feat/stripe-subscription-status` --- ### 📝 Commits (10+) - [`54ea989`](https://github.com/better-auth/better-auth/commit/54ea9894d02f7e1d1800260dcbcc564536d9f6b1) feat(stripe): add cancelAt, canceledAt and endedAt fields - [`0b54dfb`](https://github.com/better-auth/better-auth/commit/0b54dfbd890871c4b34839d656223dc43b14bcb2) add utils to manage subscription status easily - [`e323dc1`](https://github.com/better-auth/better-auth/commit/e323dc143b83027d1e4dc819bbcda3215c8d85c2) update to use new fields and utils - [`6958ed0`](https://github.com/better-auth/better-auth/commit/6958ed0ee5ac4c78afc5cc4f7a4b1bc613766b06) test: add test cases for subscription cancellation and termination - [`e58cff6`](https://github.com/better-auth/better-auth/commit/e58cff6b27bcc708b6ddbf1c9e948fbe8a3059b4) fix: missing imports, broken syntax and some condition check - [`cd80514`](https://github.com/better-auth/better-auth/commit/cd805144d15818dd1cdb7b9fd9458a998413019d) docs(stripe): add new fields and explanation for cancellation - [`e648e52`](https://github.com/better-auth/better-auth/commit/e648e52177b88ce15057cd12a9feff7f3529fa41) Merge branch 'canary' into 2025-12-24/feat/stripe-subscription-status - [`8474f23`](https://github.com/better-auth/better-auth/commit/8474f2356ba2ff779b71c722dfaf2439b901cba1) Merge branch 'canary' into 2025-12-24/feat/stripe-subscription-status - [`84e6a7b`](https://github.com/better-auth/better-auth/commit/84e6a7bad6fb498f0bbe8e556ac76e937ee3e125) fix: correct stripe api error message handling - [`b65088d`](https://github.com/better-auth/better-auth/commit/b65088d6bb543dad7f24b9396ee2ffc0845e87c6) Merge branch 'canary' into 2025-12-24/feat/stripe-subscription-status ### 📊 Changes **7 files changed** (+909 additions, -92 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/stripe.mdx` (+42 -2) 📝 `packages/stripe/src/hooks.ts` (+43 -10) 📝 `packages/stripe/src/routes.ts` (+89 -78) 📝 `packages/stripe/src/schema.ts` (+12 -0) 📝 `packages/stripe/src/stripe.test.ts` (+680 -0) 📝 `packages/stripe/src/types.ts` (+18 -1) 📝 `packages/stripe/src/utils.ts` (+25 -1) </details> ### 📄 Description > This PR improves https://github.com/better-auth/better-auth/pull/5487, which was implemented by @GautamBytes --- This PR includes the following changes: - Add `cancelAt`, `canceledAt`, and `endedAt` fields - Add internal utilities for subscription status management - Improve handling of subscription cancellation in hooks and routes - Add tests related to cancellation and termination - Update Stripe plugin docs content > [!NOTE] > I tested the schema changes with active and canceled subscribers on the existing schema and confirmed it’s not a breaking change. > > - The new logic still checks `cancelAtPeriodEnd` > - All added fields are nullable > > This means the existing cancellation state logic based on cancelAtPeriodEnd continues to work, with additional fields added for more accurate management. The fields are synchronized more precisely when webhook events are received. Closes https://github.com/better-auth/better-auth/issues/5388 Closes https://github.com/better-auth/better-auth/issues/5535 Closes https://github.com/better-auth/better-auth/issues/5780 ### To-do - [x] Test with actual app - [x] Update documentation <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds flexible subscription cancellation and termination handling in the Stripe plugin, with precise tracking for scheduled cancels and immediate ends. Introduces new fields and utilities to keep state in sync across webhooks and API routes. - **New Features** - Add cancelAt, canceledAt, and endedAt to Subscription for accurate state tracking. - Use helpers (isActiveOrTrialing, isPendingCancel, isStripePendingCancel) to standardize status checks. - Sync cancellation fields in checkout, update, and delete webhooks and route callbacks, with a fallback for missed Stripe events. - Restore flow clears either cancel_at or cancel_at_period_end based on the current Stripe subscription state. - Add comprehensive tests for webhook scenarios, restore behavior, and fallback sync; update Stripe plugin docs. - **Migration** - Breaking: database schema adds cancelAt, canceledAt, endedAt. - Run migrations and ensure adapter mappings include the new fields. <sup>Written for commit b65088d6bb543dad7f24b9396ee2ffc0845e87c6. Summary will update automatically 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:22:06 -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#32593