From b66b296292ed3ec8e9af999b647a18fcdf6e3e4c Mon Sep 17 00:00:00 2001 From: Muhammad Fadli Date: Mon, 30 Oct 2023 13:41:46 +0700 Subject: [PATCH] fix : - fix error metro --- src/transaction/ppob_callback.controller.ts | 74 ++++++++++++--------- src/transaction/transaction.service.ts | 1 - 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index 81d6c76..f77be39 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -43,18 +43,18 @@ export class PpobCallbackController { @Public() @Get('/metro') async getMetro(@Req() request: FastifyRequest) { - // try { + try { const response = request.query; - console.log('responsemetro', response['status']) - if (response['message'].toLowerCase().includes('cek')) { + + 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'], + response['refid'], + null, + null, + false, + response['message'], ); return { @@ -67,11 +67,11 @@ export class PpobCallbackController { //TODO: UPDATE BERHASIL await this.transactionService.updateBill( - response['refid'], - Number(splitMessage[21].replace(/^\D+/g, '')), - Number(splitMessage[17].replace(/^\D+/g, '')), - true, - response['message'], + response['refid'], + Number(splitMessage[21].replace(/^\D+/g, '')), + Number(splitMessage[17].replace(/^\D+/g, '')), + true, + response['message'], ); // } else { @@ -79,22 +79,32 @@ export class PpobCallbackController { console.log('statusapani2', response.toString()); if (response['status'].toString() != '20') { - console.log('responsemetro1', response['status']) - console.log('metrogagalmessage', response['message']) //TODO: UPDATE GAGAL - await this.transactionService.checkCallbackOrderFailed( + const updateTransaction = + await this.transactionService.callbackOrderFailed( response['refid'], response, ); - + return { + updateTransaction, + statusCode: HttpStatus.BAD_REQUEST, + message: 'failed to proccess', + }; } else { + //TODO: UPDATE BERHASIL - await this.transactionService.checkCallbackOrderSuccess( + const updateTransaction = + await this.transactionService.callbackOrderSuccess( response['refid'], response, ); + return { + updateTransaction, + statusCode: HttpStatus.OK, + message: 'success', + }; } } @@ -106,20 +116,20 @@ export class PpobCallbackController { 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; - // } - // } + } 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() diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 2fb6a63..eeb01e2 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -1502,7 +1502,6 @@ export class TransactionService { if (callback['message'].includes('METRO')) { const response = callback['message']; const responseBaru = response.split('.'); - console.log('masukmsgmetrofail', responseBaru[2]) dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal. ${responseBaru[2]}`; if (callback['price'] != dataTransaction.product_price.price) { dataTransaction.product_price.price = parseInt(callback['price']);