-add condition for ppob_callback can't hit 2 times if the transaction is already success or failed (only pending)

This commit is contained in:
Fadli 2022-06-29 18:10:05 +07:00
parent 7aee976de6
commit 1fcc7ca8ad
2 changed files with 73 additions and 51 deletions

View File

@ -19,31 +19,17 @@ export class PpobCallbackController {
if (response['statuscode'] == 2) {
//TODO: UPDATE GAGAL
const updateTransaction =
await this.transactionService.callbackOrderFailed(
await this.transactionService.callbackOrderFailed(
response['clientid'],
response,
);
return {
updateTransaction,
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to proccess',
};
}
//TODO: UPDATE BERHASIL
const updateTransaction =
await this.transactionService.callbackOrderSuccess(
await this.transactionService.callbackOrderSuccess(
response['clientid'],
response,
);
return {
updateTransaction,
statusCode: HttpStatus.OK,
message: 'success',
};
}
@Public()

View File

@ -1064,6 +1064,17 @@ export class TransactionService {
relations: ['product_price'],
});
if (dataTransaction.status == statusTransaction.FAILED) {
return {
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to update, the transaction already failed',
};
} else if (dataTransaction.status == statusTransaction.SUCCESS) {
return {
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to update, the transaction already success',
};
} else {
const dataMsg = callback.msg;
const failedReason = dataMsg.split('.');
@ -1074,29 +1085,29 @@ export class TransactionService {
const userData = await this.userService.findExist(dataTransaction.user);
const product_price = await this.productHistoryPriceService.findById(
dataTransaction.product_price.id,
dataTransaction.product_price.id,
);
const product = await this.productService.findOneById(
product_price.product.id,
product_price.product.id,
);
//GET COA
const coaAccount = await this.coaService.findByUser(
userData.id,
coaType.WALLET,
userData.id,
coaType.WALLET,
);
const coaInventory = await this.coaService.findByName(
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
);
const coaCostOfSales = await this.coaService.findByName(
`${coaType[coaType.COST_OF_SALES]}-${product.supplier.code}`,
`${coaType[coaType.COST_OF_SALES]}-${product.supplier.code}`,
);
const coaSales = await this.coaService.findByName(
`${coaType[coaType.SALES]}-SYSTEM`,
`${coaType[coaType.SALES]}-SYSTEM`,
);
try {
@ -1135,16 +1146,23 @@ export class TransactionService {
if (userData.partner) {
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`;
this.callbackToPartner(
userData.id,
message,
dataTransaction.partner_trx_id,
dataTransaction.amount,
product.code,
dataTransaction.destination,
'-',
'gagal',
userData.id,
message,
dataTransaction.partner_trx_id,
dataTransaction.amount,
product.code,
dataTransaction.destination,
'-',
'gagal',
);
}
return {
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to proccess',
};
}
}
async callbackOrderSuccess(supplier_trx_id: string, callback: any) {
@ -1155,6 +1173,19 @@ export class TransactionService {
relations: ['product_price'],
});
if (dataTransaction.status == statusTransaction.FAILED) {
return {
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to update, the transaction already failed',
};
} else if (dataTransaction.status == statusTransaction.SUCCESS) {
return {
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to update, the transaction already success',
};
} else {
dataTransaction.status = statusTransaction.SUCCESS;
dataTransaction.seri_number = callback['sn'];
dataTransaction.callback_json = callback;
@ -1164,33 +1195,33 @@ export class TransactionService {
let supervisorData = [];
const product_price = await this.productHistoryPriceService.findById(
dataTransaction.product_price.id,
dataTransaction.product_price.id,
);
const product = await this.productService.findOneById(
product_price.product.id,
product_price.product.id,
);
let profit = product_price.mark_up_price;
//GET COA
const coaExpense = await this.coaService.findByName(
`${coaType[coaType.EXPENSE]}-SYSTEM`,
`${coaType[coaType.EXPENSE]}-SYSTEM`,
);
if (userData.partner != null) {
//GET SALES
supervisorData = await this.calculateCommission(
supervisorData,
profit,
userData,
supervisorData,
profit,
userData,
);
profit = supervisorData
.map((item) => {
return item.credit;
})
.reduce((prev, curr) => {
return prev + curr;
}, 0);
.map((item) => {
return item.credit;
})
.reduce((prev, curr) => {
return prev + curr;
}, 0);
supervisorData = supervisorData.concat([
{
@ -1219,16 +1250,21 @@ export class TransactionService {
if (userData.partner) {
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
this.callbackToPartner(
userData.id,
message,
dataTransaction.partner_trx_id,
dataTransaction.amount,
product.code,
dataTransaction.destination,
dataTransaction.seri_number,
'berhasil',
userData.id,
message,
dataTransaction.partner_trx_id,
dataTransaction.amount,
product.code,
dataTransaction.destination,
dataTransaction.seri_number,
'berhasil',
);
}
return {
statusCode: HttpStatus.OK,
message: 'success',
};
}
}
async callbackToPartner(