Repository navigation
feat(subscriptions): add pause/resume with per-plan windows - #1847
Merged
github-actions[bot] merged 1 commit intoOct 19, 2026
Merged
github-actions[bot] merged 1 commit into
github-actions[bot] merged 1 commit into
Conversation
…s17#1723) Implements the subscription pause and resume feature described in issue Smartdevs17#1723. Closes Smartdevs17#1723. Changes ------- backend/migrations/005_subscription_pause_columns.sql - New migration: adds is_paused, paused_at, pause_duration_days, paused_until, billing_adjustment_amount, pause_reason, pause_note columns to the subscriptions table. - Partial index idx_subscriptions_paused_until for the auto-resume cron job; idx_subscriptions_active_billing to exclude paused rows from billing queries. backend/subscription/domain/pauseBilling.ts - PauseWindowRegistry: per-plan configurable min/max pause duration and yearly cap (acceptance criterion: "Pause window configurable"). - pauseWindowRegistry singleton exported for use by the controller and the store. - Pure helpers: calculatePauseCredit, calculateResumeCredit, validatePauseRequest, buildPauseBillingAdjustment, daysFromNow, daysBetween, isResumeDue, getPeriodDays. backend/subscription/domain/pauseStateStore.ts - resume() now computes nextBillingDate by shifting forward by the actual number of paused days so paused time never counts against the billing period (acceptance criterion: "Time does not count against period" and "Billing resumes correctly"). backend/subscription/controller/pauseController.ts - PauseRequestBody gains optional planId field. - pauseSubscription() passes planId through to PauseStateStore.pause() so per-plan PauseWindowRegistry limits are enforced at the API layer. backend/subscription/domain/index.ts - Re-exports all pause/resume symbols (PauseWindowRegistry, pauseWindowRegistry, PauseStateStore, pauseStateStore, billing helpers and types) for clean imports across the backend. backend/subscription/domain/__tests__/pauseWindowRegistry.test.ts (new) - PauseWindowRegistry: register, replace, remove, clear, list, getWindow. - Validation rejects bad minDays / maxDays / maxPausesPerYear. - validatePauseRequest honours per-plan limits. - PauseStateStore respects registered per-plan windows. - resume() shifts nextBillingDate on both full and early resume. backend/subscription/controller/__tests__/pauseController.test.ts (new) - planId wiring: per-plan window enforced end-to-end through the controller, falls back to global defaults when absent or unregistered. - nextBillingDate returned in resume response and stored in history. - previewPause does not mutate state. - getPauseState 404s when no history exists; returns active: null after resume.
|
@Clement-coder Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the subscription pause and resume feature.
Closes #1723
Acceptance criteria
PauseWindowRegistrylets any plan register its ownminDays,maxDays, andmaxPausesPerYear. Falls back to globalDEFAULT_PAUSE_LIMITSwhen no window is registered. The newplanIdfield on the pause API request wires per-plan limits all the way through the controller.PauseStateStore.resume()now computesnextBillingDateby shifting it forward by the actual number of paused days, so frozen time never counts against the billing period. The frontendsubscriptionStoreapplies the same shift.charge_subscription_guardedcallscheck_and_resume_internalbefore assertingActivestatus, blocking charges on paused subscriptions. ThenextBillingDateshift prevents an immediate charge on resume.Files changed
backend/migrations/005_subscription_pause_columns.sqlis_paused,paused_at,pause_duration_days,paused_until,billing_adjustment_amount,pause_reason,pause_notecolumns + partial indexesbackend/subscription/domain/pauseBilling.tsPauseWindowRegistryclass,pauseWindowRegistrysingleton, pure billing helpersbackend/subscription/domain/pauseStateStore.tsresume()now setsnextBillingDateshifted by actual pause daysbackend/subscription/controller/pauseController.tsPauseRequestBodygainsplanId; passed through to storebackend/subscription/domain/index.tsbackend/subscription/domain/__tests__/pauseWindowRegistry.test.tsnextBillingDateshiftbackend/subscription/controller/__tests__/pauseController.test.tsplanIdwiring, resume response, preview idempotency, error pathsTest results