File size: 926 Bytes
73746a8
 
 
 
 
 
 
 
 
 
 
 
8268e91
 
 
 
73746a8
 
 
 
 
8268e91
 
 
 
 
 
 
73746a8
 
8268e91
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
import { Controller, Post, Body, UseGuards, Request } from '@nestjs/common';
import { PaymentService } from './payment.service';
import { PreparePaymentDto } from './dto/prepare-payment.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';

@Controller('api/payment')
export class PaymentController {
  constructor(private readonly paymentService: PaymentService) {}

  @UseGuards(JwtAuthGuard)
  @Post('prepare')
  async prepare(@Request() req, @Body() preparePaymentDto: PreparePaymentDto) {
    const data = await this.paymentService.prepare(
      req.user.userId,
      preparePaymentDto,
    );
    return { success: true, data };
  }

  // Webhook for testing
  @Post('callback')
  async callback(
    @Body() body: { paymentNo: string; status: 'SUCCESS' | 'FAILED' },
  ) {
    const data = await this.paymentService.handleCallback(
      body.paymentNo,
      body.status,
    );
    return data;
  }
}