import { Controller, Get, HttpStatus, Logger, Req } from '@nestjs/common'; import { TransactionService } from './transaction.service'; import { FastifyRequest } from 'fastify'; import { Public } from '../auth/public.decorator'; @Controller({ path: 'ppob_callback', version: '1', }) export class PpobCallbackController { private readonly logger = new Logger(PpobCallbackController.name); constructor(private readonly transactionService: TransactionService) {} @Public() @Get() async get(@Req() request: FastifyRequest) { const response = request.query; if (response['statuscode'] == 2) { //TODO: UPDATE GAGAL const updateTransaction = await this.transactionService.callbackOrderFailed( response['clientid'], response, ); return { updateTransaction, statusCode: HttpStatus.BAD_REQUEST, message: 'failed to proccess', }; } //TODO: UPDATE BERHASIL const updateTransaction = await this.transactionService.callbackOrderSuccess( response['clientid'], response, ); return { updateTransaction, statusCode: HttpStatus.OK, message: 'success', }; } @Public() @Get('/metro') async getMetro(@Req() request: FastifyRequest) { const response = request.query; if (response['message'].toLowerCase().includes('cek tagihan')) { if (response['status'] != 20) { //TODO: UPDATE GAGAL await this.transactionService.updateBill( response['refid'], null, null, false, response['message'], ); return { statusCode: HttpStatus.OK, message: 'success', }; } const splitMessage = response['message'].split('"'); //TODO: UPDATE BERHASIL await this.transactionService.updateBill( response['refid'], Number(splitMessage[21].replace(/^\D+/g, '')), Number(splitMessage[17].replace(/^\D+/g, '')), true, response['message'], ); // } else { if (response['status'].toString() != '20') { //TODO: UPDATE GAGAL const updateTransaction = await this.transactionService.callbackOrderFailed( response['refid'], response, ); return { updateTransaction, statusCode: HttpStatus.BAD_REQUEST, message: 'failed to proccess', }; } //TODO: UPDATE BERHASIL const updateTransaction = await this.transactionService.callbackOrderSuccess( response['refid'], response, ); } this.logger.log({ requestQuery: request.query, }); return { statusCode: HttpStatus.OK, message: 'success', }; } }