[PR #8064] [MERGED] feat(stripe): add scheduleAtPeriodEnd option to defer plan changes #7720

Closed
opened 2026-03-13 13:47:07 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: canaryHead: 2026-02-19/feat/schedule-upgrade-at-period-end


📝 Commits (4)

  • 842eeae feat(stripe): add scheduleAtPeriodEnd option to defer plan changes
  • 713ea83 test: update mock
  • 21cc144 fix: cleanup schedule only when exists, add error handling
  • e98865d Merge branch 'canary' into 2026-02-19/feat/schedule-upgrade-at-period-end

📊 Changes

4 files changed (+560 additions, -5 deletions)

View changed files

📝 docs/content/docs/plugins/stripe.mdx (+29 -0)
📝 packages/stripe/src/routes.ts (+126 -5)
📝 packages/stripe/test/seat-based-billing.test.ts (+6 -0)
📝 packages/stripe/test/stripe.test.ts (+399 -0)

📄 Description

Summary by cubic

Adds scheduleAtPeriodEnd to Stripe subscription upgrades to defer plan changes until the current billing period ends. Uses Subscription Schedules for no proration and no redirects, safely handles existing schedules, and updates the DB via webhook when the change takes effect.

  • New Features

    • Added scheduleAtPeriodEnd (boolean, default false) to upgradeSubscription.
    • When true: create a two-phase Subscription Schedule; no proration; server-side apply; subscription updates on customer.subscription.updated.
    • Releases any active plugin-created schedule before a new schedule or immediate change; checks only when a schedule is attached; external schedules are left untouched.
    • Immediate upgrades remain unchanged (Billing Portal or direct API when seat price changes).
    • Updated docs and tests covering deferred changes, safe schedule release, and non-plugin schedules.
  • Bug Fixes

    • Added error handling for schedule create/update; return BAD_REQUEST with Stripe error details; guard when a schedule has no phases.
    • Avoid unnecessary API calls by listing schedules only when the subscription has one attached.

Written for commit e98865df01. 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/8064 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 2/19/2026 **Status:** ✅ Merged **Merged:** 2/19/2026 **Merged by:** [@bytaesu](https://github.com/bytaesu) **Base:** `canary` ← **Head:** `2026-02-19/feat/schedule-upgrade-at-period-end` --- ### 📝 Commits (4) - [`842eeae`](https://github.com/better-auth/better-auth/commit/842eeae037bd9faf85386bc81295e348606adc82) feat(stripe): add scheduleAtPeriodEnd option to defer plan changes - [`713ea83`](https://github.com/better-auth/better-auth/commit/713ea83b36d88af6977cf1cba8f1b2b6a4a7b21b) test: update mock - [`21cc144`](https://github.com/better-auth/better-auth/commit/21cc14425598dfb6fdc84bdced1485255e6e14a3) fix: cleanup schedule only when exists, add error handling - [`e98865d`](https://github.com/better-auth/better-auth/commit/e98865df01c7ff61cae886133d49678d6087a5a3) Merge branch 'canary' into 2026-02-19/feat/schedule-upgrade-at-period-end ### 📊 Changes **4 files changed** (+560 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/stripe.mdx` (+29 -0) 📝 `packages/stripe/src/routes.ts` (+126 -5) 📝 `packages/stripe/test/seat-based-billing.test.ts` (+6 -0) 📝 `packages/stripe/test/stripe.test.ts` (+399 -0) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds scheduleAtPeriodEnd to Stripe subscription upgrades to defer plan changes until the current billing period ends. Uses Subscription Schedules for no proration and no redirects, safely handles existing schedules, and updates the DB via webhook when the change takes effect. - **New Features** - Added scheduleAtPeriodEnd (boolean, default false) to upgradeSubscription. - When true: create a two-phase Subscription Schedule; no proration; server-side apply; subscription updates on customer.subscription.updated. - Releases any active plugin-created schedule before a new schedule or immediate change; checks only when a schedule is attached; external schedules are left untouched. - Immediate upgrades remain unchanged (Billing Portal or direct API when seat price changes). - Updated docs and tests covering deferred changes, safe schedule release, and non-plugin schedules. - **Bug Fixes** - Added error handling for schedule create/update; return BAD_REQUEST with Stripe error details; guard when a schedule has no phases. - Avoid unnecessary API calls by listing schedules only when the subscription has one attached. <sup>Written for commit e98865df01c7ff61cae886133d49678d6087a5a3. 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-03-13 13:47:07 -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#7720