Spaces:
Sleeping
Sleeping
File size: 1,667 Bytes
b0798af | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import { Controller, Get, Post, Body, UseGuards, Req } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { SubscriptionService } from './subscription.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
@ApiTags('Subscriptions & Payments')
@Controller()
export class SubscriptionController {
constructor(private readonly subService: SubscriptionService) {}
@Get('plans')
@ApiOperation({
summary:
'List available plans (Free, Premium Individual, Duo, Family, Student)',
})
getPlans() {
return this.subService.getPlans();
}
@Get('me/subscription')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get current subscription tier & renewal date' })
getSubscription(@Req() req: any) {
return this.subService.getSubscription(req.user.userId);
}
@Post('me/subscription/checkout-session')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Create Stripe Checkout session for upgrade' })
createCheckoutSession(@Req() req: any, @Body() body: { plan_id: string }) {
return this.subService.createCheckoutSession(req.user.userId, body.plan_id);
}
@Post('me/subscription/cancel')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Cancel subscription at period end' })
cancelSubscription(@Req() req: any) {
return this.subService.cancelSubscription(req.user.userId);
}
@Post('webhooks/stripe')
@ApiOperation({
summary: 'Stripe webhook receiver for invoice & payment events',
})
handleWebhook(@Body() body: any) {
return this.subService.handleStripeWebhook(body);
}
}
|