fixing: check bill
This commit is contained in:
parent
9ee5b65dfc
commit
f449299bbf
|
@ -51,32 +51,25 @@ export class PpobCallbackController {
|
||||||
async getMetro(@Req() request: FastifyRequest) {
|
async getMetro(@Req() request: FastifyRequest) {
|
||||||
const response = request.query;
|
const response = request.query;
|
||||||
|
|
||||||
console.log(typeof response['message'], "INI DIA")
|
|
||||||
|
|
||||||
if (response['message'].includes('CEK TAGIHAN')) {
|
if (response['message'].includes('CEK TAGIHAN')) {
|
||||||
|
|
||||||
if (response['status'] != 20) {
|
if (response['status'] != 20) {
|
||||||
//TODO: UPDATE GAGAL
|
//TODO: UPDATE GAGAL
|
||||||
const updateTransaction =
|
await this.transactionService.updateBill(
|
||||||
await this.transactionService.callbackOrderFailed(
|
response['refid'],
|
||||||
response['refid'],
|
null,
|
||||||
response,
|
null,
|
||||||
);
|
false,
|
||||||
|
);
|
||||||
return {
|
|
||||||
updateTransaction,
|
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
|
||||||
message: 'failed to proccess',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const splitMessage = response['message'].split('","');
|
const splitMessage = response['message'].split('","');
|
||||||
console.log("masuk sini")
|
|
||||||
//TODO: UPDATE BERHASIL
|
//TODO: UPDATE BERHASIL
|
||||||
await this.transactionService.updateBill(
|
await this.transactionService.updateBill(
|
||||||
response['refid'],
|
response['refid'],
|
||||||
splitMessage[3].replace(/^\D+/g, ''),
|
splitMessage[3].replace(/^\D+/g, ''),
|
||||||
splitMessage[4].replace(/^\D+/g, ''),
|
splitMessage[4].replace(/^\D+/g, ''),
|
||||||
|
true
|
||||||
);
|
);
|
||||||
//
|
//
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1781,7 +1781,14 @@ export class TransactionService {
|
||||||
return transaction;
|
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(
|
await this.checkBillHistoryRepository.update(
|
||||||
{
|
{
|
||||||
trx_id: trxId,
|
trx_id: trxId,
|
||||||
|
@ -1791,5 +1798,45 @@ export class TransactionService {
|
||||||
admin_price: admin,
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user