project init
This commit is contained in:
41
apps/api/src/payments/payments.controller.ts
Normal file
41
apps/api/src/payments/payments.controller.ts
Normal file
@ -0,0 +1,41 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user