File size: 1,154 Bytes
f4866cb
6b95a9f
f4866cb
 
 
494e1c4
f4866cb
 
 
 
 
 
 
494e1c4
d18f023
f4866cb
 
 
 
d18f023
f4866cb
 
494e1c4
f4866cb
 
 
 
 
 
6b95a9f
 
 
2865a3f
6b95a9f
2865a3f
 
 
6b95a9f
f4866cb
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
// payment.controller.ts
import { Controller, Post, Body, Req, Res, Get } from '@nestjs/common';
import { PaymentService } from './payment.service.js';
import { Request, Response } from 'express';
import { Public } from '../modules/authentication/authentication.decorator.js';
import { CreatePaymentUrlDto } from './dto/create-payment-url.dto.js';

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

  @Public()
  @Post('create_payment_url')
  async createPaymentUrl(@Req() req: Request, @Body() body: CreatePaymentUrlDto) {

    const ipAddr =
      req.headers['x-forwarded-for'] ||
      req.socket.remoteAddress ||
      req.socket?.remoteAddress;

    return await this.paymentService.createPaymentUrl(
      body.amount,
      body.orderId,
      body.orderDescription,
      body.orderType,
      body.language,
      ipAddr as string,
    );
  }

  @Public()
  @Get('vnpay_ipn')
  async vnpayIpn(@Req() req: Request, @Body() body: any){
    const reqQuery = req.query;
    const res = await this.paymentService.vnpayIpn(reqQuery)
    console.log(res);
    return res;
  }
}