42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { PaymentsService } from './payments.service';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import { Public } from '../auth/decorators/public.decorator';
|
|
import { User } from '@coursecraft/database';
|
|
|
|
@ApiTags('subscriptions')
|
|
@Controller('subscriptions')
|
|
export class PaymentsController {
|
|
constructor(private paymentsService: PaymentsService) {}
|
|
|
|
@Get('plans')
|
|
@Public()
|
|
@ApiOperation({ summary: 'Get available subscription plans' })
|
|
async getPlans() {
|
|
return this.paymentsService.getPlans();
|
|
}
|
|
|
|
@Post('checkout')
|
|
@ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Create Stripe checkout session' })
|
|
async createCheckoutSession(
|
|
@CurrentUser() user: User,
|
|
@Body('tier') tier: 'PREMIUM' | 'PRO'
|
|
) {
|
|
return this.paymentsService.createCheckoutSession(user.id, tier);
|
|
}
|
|
|
|
@Post('portal')
|
|
@ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Create Stripe customer portal session' })
|
|
async createPortalSession(@CurrentUser() user: User) {
|
|
return this.paymentsService.createPortalSession(user.id);
|
|
}
|
|
}
|