fixing: check bill

This commit is contained in:
ilham 2022-05-17 12:52:02 +07:00
parent 9ee5b65dfc
commit f449299bbf
2 changed files with 56 additions and 16 deletions

View File

@ -51,32 +51,25 @@ export class PpobCallbackController {
async getMetro(@Req() request: FastifyRequest) {
const response = request.query;
console.log(typeof response['message'], "INI DIA")
if (response['message'].includes('CEK TAGIHAN')) {
if (response['status'] != 20) {
//TODO: UPDATE GAGAL
const updateTransaction =
await this.transactionService.callbackOrderFailed(
response['refid'],
response,
);
return {
updateTransaction,
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to proccess',
};
await this.transactionService.updateBill(
response['refid'],
null,
null,
false,
);
}
const splitMessage = response['message'].split('","');
console.log("masuk sini")
//TODO: UPDATE BERHASIL
await this.transactionService.updateBill(
response['refid'],
splitMessage[3].replace(/^\D+/g, ''),
splitMessage[4].replace(/^\D+/g, ''),
true
);
//
} else {

View File

@ -1781,7 +1781,14 @@ export class TransactionService {
return transaction;
}
async updateBill(trxId: string, amount: number, admin: number) {
async updateBill(
trxId: string,
amount: number,
admin: number,
status: boolean,
) {
const billData = await this.findOneBillById(trxId);
await this.checkBillHistoryRepository.update(
{
trx_id: trxId,
@ -1791,5 +1798,45 @@ export class TransactionService {
admin_price: admin,
},
);
const userData = await this.userService.findExist(billData.user);
if (userData.partner) {
const message = status
? `Bill dari ${billData.destination} adalah ${amount}.`
: '';
const statusResponse = status ? 'berhasil' : 'gagal';
this.callbackToPartner(
userData.id,
message,
billData.partner_trx_id,
amount,
billData.product_code,
billData.destination,
'-',
statusResponse,
);
}
}
async findOneBillById(trxId: string) {
try {
return await this.checkBillHistoryRepository.findOneOrFail({
where:{
trx_id: trxId,
},
});
} catch (e) {
if (e instanceof EntityNotFoundError) {
throw new HttpException(
{
statusCode: HttpStatus.NOT_FOUND,
error: 'Bill not found',
},
HttpStatus.NOT_FOUND,
);
} else {
throw e;
}
}
}
}