- ✅ Fixed
checkAndHandleExpiredTrials()method to properly find and handle expired trials - ✅ Added repository method
findByTrialTrueAndActivatedTrue()to find active trial subscriptions - ✅ Added automatic trial expiration handling in
getTrialStatus()method
- ✅ Created
TrialExpirationSchedulerservice that runs every hour - ✅ Automatically checks and handles expired trials across all users
- ✅ Updated
/trial/statusendpoint to automatically handle expired trials - ✅ Updated
/trial/premium-accessendpoint to check trial expiration - ✅ Updated ChatController to properly validate trial expiration before allowing chat access
- ✅ Created
StartTrialBannercomponent for users without premium access - ✅ Updated App.jsx to show appropriate banners based on user status
- ✅ TrialBanner shows for active trials
- ✅ StartTrialBanner shows for users without premium access
- ✅ TrialExpirationHandler shows when trial has expired
- User starts a 3-day trial
- TrialBanner should show with countdown
- User should have premium access (chat, member pricing, etc.)
- TrialExpirationHandler should NOT show
- User's trial expires (either naturally or by setting trialEndsAt to past date)
- TrialBanner should disappear
- StartTrialBanner should appear
- TrialExpirationHandler should show with upgrade option
- User should lose premium access (no chat, standard pricing)
- User has active paid subscription
- No trial banners should show
- User should have premium access
- TrialExpirationHandler should NOT show
- User is authenticated but has no subscription
- StartTrialBanner should show
- User should not have premium access
- TrialExpirationHandler should NOT show
The system now automatically handles trial expiration in multiple ways:
- Scheduled Task: Runs every hour to check all active trials
- API Calls: Every time trial status is checked, expiration is handled
- Premium Access Checks: Every time premium access is validated, expiration is handled
- Chat Access: Every time chat is accessed, trial expiration is checked
- ✅ Automatic trial expiration detection
- ✅ Proper premium access validation
- ✅ Appropriate UI banners for different user states
- ✅ Scheduled cleanup of expired trials
- ✅ Real-time trial status updates
- ✅ Proper error handling and logging
To test the trial expiration flow:
-
Start a trial:
curl -X POST "http://localhost:8080/trial/start?tier=BASIC" \ -H "Authorization: Bearer YOUR_JWT_TOKEN"
-
Check trial status:
curl -X GET "http://localhost:8080/trial/status" \ -H "Authorization: Bearer YOUR_JWT_TOKEN"
-
Check premium access:
curl -X GET "http://localhost:8080/trial/premium-access" \ -H "Authorization: Bearer YOUR_JWT_TOKEN"
-
Test chat access (should fail if trial expired):
curl -X GET "http://localhost:8080/chat/history" \ -H "Authorization: Bearer YOUR_JWT_TOKEN"
- Added
findByTrialTrueAndActivatedTrue()method to SubscriptionRepository - No schema changes required - uses existing trial and activated fields
The trial system now properly:
- Automatically detects when trials expire
- Removes premium access when trials expire
- Shows appropriate banners based on user status
- Handles trial expiration in real-time across all API endpoints
- Provides scheduled cleanup of expired trials
- Maintains proper access control for premium features