feat: add subscription API endpoints and grace period job - M3 (refs #55)

API Endpoints (all authenticated):
- GET /api/subscriptions - current subscription status
- POST /api/subscriptions/checkout - create Stripe subscription
- POST /api/subscriptions/cancel - schedule cancellation at period end
- POST /api/subscriptions/reactivate - cancel pending cancellation
- PUT /api/subscriptions/payment-method - update payment method
- GET /api/subscriptions/invoices - billing history

Grace Period Job:
- Daily cron at 2:30 AM to check expired grace periods
- Downgrades to free tier when 30-day grace period expires
- Syncs tier to user_profiles.subscription_tier

Email Templates:
- payment_failed_immediate (first failure)
- payment_failed_7day (7 days before grace ends)
- payment_failed_1day (1 day before grace ends)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Eric Gullickson
2026-01-18 16:16:58 -06:00
parent 7a0c09b83f
commit e7461a4836
8 changed files with 744 additions and 1 deletions

View File

@@ -599,6 +599,25 @@ export class SubscriptionsService {
return 'free';
}
/**
* Get invoices for a user's subscription
*/
async getInvoices(userId: string): Promise<any[]> {
try {
const subscription = await this.repository.findByUserId(userId);
if (!subscription?.stripeCustomerId) {
return [];
}
return this.stripeClient.listInvoices(subscription.stripeCustomerId);
} catch (error: any) {
logger.error('Failed to get invoices', {
userId,
error: error.message,
});
throw error;
}
}
/**
* Map subscription entity to response DTO
*/