diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index eb7f9d8..0a38f3f 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -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 { diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 3bfbaf3..38687de 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -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; + } + } } }