Repository navigation
feat(trials): add per-plan configurable trial periods with conversion (#1722) - #1839
Merged
github-actions[bot] merged 3 commits intoOct 19, 2026
Conversation
…Smartdevs17#1722) Trials were hardcoded to 14 days globally. This PR makes trial length and auto-conversion configurable per subscription plan. Changes to backend/subscription/domain/trialManagementService.ts: - Add PlanTrialConfig interface (planId, trialDurationDays, autoConvertOnExpiry) - Add DEFAULT_TRIAL_DURATION_DAYS = 14 constant - Add planTrialConfigs Map to TrialManagementService - Add registerPlanTrialConfig() — register/replace a plan's trial policy; validates trialDurationDays is a positive finite number - Add getPlanTrialConfig() / listPlanTrialConfigs() accessors - Update startTrial() duration resolution order: 1. explicit durationDays param (call-site override) 2. registered PlanTrialConfig for the planId 3. DEFAULT_TRIAL_DURATION_DAYS (14) global fallback - Update processExpirations() to auto-convert instead of expiring when the plan's autoConvertOnExpiry is true; returns { converted, expired } so callers can act on each group; records trial_converted + payment_completed events on auto-convert Add backend/migrations/006_plan_trial_configs.sql: - plan_trial_configs table (plan_id FK, trial_duration_days CHECK > 0, auto_convert_on_expiry, description, timestamps) - auto-update trigger for updated_at - @down rollback section Update backend/subscription/__tests__/trialManagementService.test.ts: - Fix existing processExpirations test to destructure { expired, converted } - Add 18 new tests covering: registerPlanTrialConfig / getPlanTrialConfig (6 tests) startTrial per-plan duration resolution (4 tests) processExpirations auto-convert on expiry (8 tests) Tests: 36 passed, 36 total (18 existing + 18 new) Closes Smartdevs17#1722
|
@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
Resolves #1722. Trial length was hardcoded to 14 days for every plan. This PR makes it fully configurable per plan and adds automatic trial-to-paid conversion at expiry.
Changes
backend/subscription/domain/trialManagementService.tsNew:
PlanTrialConfiginterfaceNew methods on
TrialManagementServiceregisterPlanTrialConfig(config)— register or replace a plan's trial policy; validatestrialDurationDays > 0getPlanTrialConfig(planId)— retrieve config; returnsundefinedif not registeredlistPlanTrialConfigs()— enumerate all registered configsUpdated:
startTrial()— duration resolution order:durationDaysparam (call-site override)PlanTrialConfig.trialDurationDaysfor the planDEFAULT_TRIAL_DURATION_DAYS(14) — global fallback, preserves all existing behaviourUpdated:
processExpirations()— now returns{ converted: TrialRecord[], expired: TrialRecord[] }:autoConvertOnExpiry: true→ setsstatus = 'converted',conversionTrigger = 'automatic_time_based', emitstrial_converted+payment_completedeventsstatus = 'expired', emitstrial_expired(previous behaviour)endDateand already-terminal trials are skippedbackend/migrations/006_plan_trial_configs.sqlplan_trial_configstable withplan_idFK,trial_duration_days CHECK (> 0),auto_convert_on_expiry,description, timestampsupdated_at@downrollback sectionbackend/subscription/__tests__/trialManagementService.test.tsprocessExpirationstest to destructure{ expired, converted }Acceptance criteria
registerPlanTrialConfig+PlanTrialConfig.trialDurationDays)processExpirationsauto-converts whenautoConvertOnExpiry: true)Test output