202 lines
5.2 KiB
TypeScript
202 lines
5.2 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
HttpException,
|
|
HttpStatus,
|
|
Logger, Post,
|
|
Req,
|
|
} from '@nestjs/common';
|
|
import { TransactionService } from './transaction.service';
|
|
import { FastifyRequest } from 'fastify';
|
|
import { Public } from '../auth/public.decorator';
|
|
import { EntityNotFoundError } from 'typeorm';
|
|
|
|
@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
|
|
await this.transactionService.checkCallbackOrderFailed(
|
|
response['clientid'],
|
|
response,
|
|
);
|
|
} else {
|
|
//TODO: UPDATE BERHASIL
|
|
await this.transactionService.checkCallbackOrderSuccess(
|
|
response['clientid'],
|
|
response,
|
|
);
|
|
}
|
|
}
|
|
|
|
@Public()
|
|
@Get('/metro')
|
|
async getMetro(@Req() request: FastifyRequest) {
|
|
try {
|
|
const response = request.query;
|
|
|
|
if (response['message'].toLowerCase().includes('cek')) {
|
|
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 {
|
|
console.log('statusapani', response['status']);
|
|
console.log('statusapani2', response.toString());
|
|
|
|
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',
|
|
};
|
|
} else {
|
|
|
|
//TODO: UPDATE BERHASIL
|
|
const updateTransaction =
|
|
await this.transactionService.callbackOrderSuccess(
|
|
response['refid'],
|
|
response,
|
|
);
|
|
|
|
return {
|
|
updateTransaction,
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
}
|
|
|
|
this.logger.log({
|
|
requestQuery: request.query,
|
|
});
|
|
|
|
return {
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
} catch (e) {
|
|
if (e instanceof EntityNotFoundError) {
|
|
throw new HttpException(
|
|
{
|
|
statusCode: HttpStatus.NOT_FOUND,
|
|
error: 'Error callback',
|
|
message: e
|
|
},
|
|
HttpStatus.NOT_FOUND,
|
|
);
|
|
} else {
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Public()
|
|
@Post('/hemat')
|
|
async getHemat(@Req() request: FastifyRequest) {
|
|
const response = request.body;
|
|
console.log('responsehemat', response);
|
|
console.log('responsehemat2', request.body);
|
|
if (response['msg'] != 'Transaksi Sukses') {
|
|
console.log('masukgagalhemat', 'msk')
|
|
//TODO: UPDATE GAGAL
|
|
await this.transactionService.checkCallbackOrderFailed(
|
|
response['data']['idtransaction'],
|
|
response,
|
|
);
|
|
} else {
|
|
console.log('masuksukseshemat', 'msk')
|
|
//TODO: UPDATE BERHASIL
|
|
await this.transactionService.checkCallbackOrderSuccess(
|
|
response['data']['idtransaction'],
|
|
response,
|
|
);
|
|
}
|
|
}
|
|
|
|
@Public()
|
|
@Post('/digiflazz')
|
|
async getDigiflazz(@Req() request: FastifyRequest) {
|
|
const response = request.body;
|
|
console.log('responsedigiflazz', response);
|
|
if (response['data']['message'] != 'Transaksi Sukses') {
|
|
//TODO: UPDATE GAGAL
|
|
await this.transactionService.checkCallbackOrderFailed(
|
|
response['data']['ref_id'],
|
|
response['data'],
|
|
);
|
|
} else {
|
|
//TODO: UPDATE BERHASIL
|
|
await this.transactionService.checkCallbackOrderSuccess(
|
|
response['data']['ref_id'],
|
|
response['data'],
|
|
);
|
|
}
|
|
}
|
|
|
|
@Public()
|
|
@Post('/vocagame')
|
|
async getVoca(@Req() request: FastifyRequest) {
|
|
const response = request.body;
|
|
console.log('responsevocagame', response);
|
|
if (response['status'] != 'Success') {
|
|
//TODO: UPDATE GAGAL
|
|
if (response['status'] != 'Processing') {
|
|
await this.transactionService.checkCallbackOrderFailed(
|
|
response['reference'],
|
|
response,
|
|
);
|
|
}
|
|
} else {
|
|
//TODO: UPDATE BERHASIL
|
|
if (response['status'] != 'Processing') {
|
|
await this.transactionService.checkCallbackOrderSuccess(
|
|
response['reference'],
|
|
response,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|