diff --git a/compose.yaml b/compose.yaml index b8874a0..2b7436e 100644 --- a/compose.yaml +++ b/compose.yaml @@ -15,6 +15,7 @@ services: - CLERK_PUBLISHABLE_KEY=pk_test_aW4tY2hpbXAtOTcuY2xlcmsuYWNjb3VudHMuZGV2JA - CLERK_SECRET_KEY=sk_test_sA5lsb1GHwUNXWQCp5ev70QkaoF5EmdAHNWiCGwZF6 - CORS_ORIGIN=https://epess.org,https://admin.epess.org,https://center.epess.org,http://localhost:3000,http://localhost:3069,http://localhost:3001 + - LISTEN_HOST=0.0.0.0 - LISTEN_PORT=3069 - SWAGGER_PATH=/swagger - API_PATH=/v1 @@ -22,6 +23,10 @@ services: - MINIO_BUCKET_NAME=epess - MINIO_ACCESS_KEY=71dNgJtzkelXtG3R6IVt - MINIO_SECRET_KEY=53LmFiDCZxvflJIOsVF9cf0aqkIjNU2oOWtLzGsf + - PAYOS_CLIENT_ID=5c582d1a-cb4e-4d97-bb3b-210b5a24a43b + - PAYOS_API_KEY=00d6d279-4bee-45d2-802e-d4c764d149a4 + - PAYOS_CHECKSUM_KEY=e4456d229676bec941340b07a745f4713b06e8ed981721bacf9389ddf2e527a5 + - PAYOS_WEBHOOK_URL=https://api.epess.org/v1/payos/webhook labels: - 'traefik.enable=true' - 'traefik.http.routers.api.rule=Host(`api.epess.org`)' @@ -30,6 +35,7 @@ services: - 'traefik.http.services.api.loadbalancer.server.port=3069' networks: - epess-net + restart: always networks: epess-net: driver: bridge diff --git a/src/Payos/payos.controller.ts b/src/Payos/payos.controller.ts new file mode 100644 index 0000000..f853082 --- /dev/null +++ b/src/Payos/payos.controller.ts @@ -0,0 +1,35 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Param, + Body, + Headers, +} from '@nestjs/common'; +import { PayosService } from './payos.service'; +import { ApiTags, ApiOperation } from '@nestjs/swagger'; + +@ApiTags('Payos') +@Controller('payos') +export class PayosController { + constructor(private readonly payosService: PayosService) {} + + // webhook + @Post('webhook') + @ApiOperation({ summary: 'Webhook for Payos' }) + async webhook( + @Body() body: any, + @Headers('x-payos-signature') signature: string, + ) { + return this.payosService.webhook(body, signature); + } + + // ping webhook + @Get('webhook') + @ApiOperation({ summary: 'Ping webhook' }) + async ping() { + return this.payosService.ping(); + } +} diff --git a/src/Payos/payos.module.ts b/src/Payos/payos.module.ts new file mode 100644 index 0000000..7ae76fc --- /dev/null +++ b/src/Payos/payos.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { PayosService } from './payos.service'; +import { PayosController } from './payos.controller'; + +@Module({ + providers: [PayosService], + controllers: [PayosController], + exports: [PayosService], +}) +export class PayosModule {} diff --git a/src/Payos/payos.service.ts b/src/Payos/payos.service.ts new file mode 100644 index 0000000..1ad7235 --- /dev/null +++ b/src/Payos/payos.service.ts @@ -0,0 +1,28 @@ +import { Injectable, Logger } from '@nestjs/common'; +import { PrismaService } from '../Prisma/prisma.service'; + +@Injectable() +export class PayosService { + constructor(private readonly prisma: PrismaService) {} + + async ping() { + return 'pong'; + } + + async webhook(body: any, signature: string) { + Logger.log('Webhook received', body); + return body; + } + + async createPaymentURL(body: any) { + return body; + } + + async cancelPaymentURL(body: any) { + return body; + } + + async refundPayment(body: any) { + return body; + } +} diff --git a/src/Restful/restful.module.ts b/src/Restful/restful.module.ts index 8b57599..48a96a3 100644 --- a/src/Restful/restful.module.ts +++ b/src/Restful/restful.module.ts @@ -2,9 +2,10 @@ import { Module } from '@nestjs/common'; import { RestfulController } from './restful.controller'; import { RestfulService } from './restful.service'; import { ClerkModule } from '../Clerk/clerk.module'; +import { PayosModule } from '../Payos/payos.module'; @Module({ - imports: [ClerkModule], + imports: [ClerkModule, PayosModule], controllers: [RestfulController], providers: [RestfulService], }) diff --git a/src/main.ts b/src/main.ts index d1950e1..e104a37 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js'; +import { Logger } from '@nestjs/common'; async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -52,8 +53,10 @@ async function bootstrap() { maxFiles: 10, }), ); - + const host = process.env.LISTEN_HOST ?? '0.0.0.0'; const port = process.env.LISTEN_PORT ?? 3000; // Default to 3000 if LISTEN_PORT is not set - await app.listen(port); + await app.listen(port, host, () => { + Logger.log(`Server is running on http://${host}:${port}`, 'Bootstrap'); + }); } bootstrap();