ppob-backend/src/transaction/ppob_callback.controller.ts
2021-12-30 06:47:35 +07:00

45 lines
1.1 KiB
TypeScript

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,
);
} else {
//TODO: UPDATE BERHASIL
const updateTransaction =
await this.transactionService.callbackOrderSuccess(
response['clientid'],
response,
);
}
this.logger.log({
requestQuery: request.query,
});
return {
statusCode: HttpStatus.OK,
message: 'success',
};
}
}