-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:
parent
7aee976de6
commit
1fcc7ca8ad
|
@ -19,31 +19,17 @@ export class PpobCallbackController {
|
||||||
|
|
||||||
if (response['statuscode'] == 2) {
|
if (response['statuscode'] == 2) {
|
||||||
//TODO: UPDATE GAGAL
|
//TODO: UPDATE GAGAL
|
||||||
const updateTransaction =
|
await this.transactionService.callbackOrderFailed(
|
||||||
await this.transactionService.callbackOrderFailed(
|
|
||||||
response['clientid'],
|
response['clientid'],
|
||||||
response,
|
response,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
|
||||||
updateTransaction,
|
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
|
||||||
message: 'failed to proccess',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: UPDATE BERHASIL
|
//TODO: UPDATE BERHASIL
|
||||||
const updateTransaction =
|
await this.transactionService.callbackOrderSuccess(
|
||||||
await this.transactionService.callbackOrderSuccess(
|
|
||||||
response['clientid'],
|
response['clientid'],
|
||||||
response,
|
response,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
|
||||||
updateTransaction,
|
|
||||||
statusCode: HttpStatus.OK,
|
|
||||||
message: 'success',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public()
|
@Public()
|
||||||
|
|
|
@ -1064,6 +1064,17 @@ export class TransactionService {
|
||||||
relations: ['product_price'],
|
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 dataMsg = callback.msg;
|
||||||
const failedReason = dataMsg.split('.');
|
const failedReason = dataMsg.split('.');
|
||||||
|
|
||||||
|
@ -1074,29 +1085,29 @@ export class TransactionService {
|
||||||
const userData = await this.userService.findExist(dataTransaction.user);
|
const userData = await this.userService.findExist(dataTransaction.user);
|
||||||
|
|
||||||
const product_price = await this.productHistoryPriceService.findById(
|
const product_price = await this.productHistoryPriceService.findById(
|
||||||
dataTransaction.product_price.id,
|
dataTransaction.product_price.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
const product = await this.productService.findOneById(
|
const product = await this.productService.findOneById(
|
||||||
product_price.product.id,
|
product_price.product.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
//GET COA
|
//GET COA
|
||||||
const coaAccount = await this.coaService.findByUser(
|
const coaAccount = await this.coaService.findByUser(
|
||||||
userData.id,
|
userData.id,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
);
|
);
|
||||||
|
|
||||||
const coaInventory = await this.coaService.findByName(
|
const coaInventory = await this.coaService.findByName(
|
||||||
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const coaCostOfSales = await this.coaService.findByName(
|
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(
|
const coaSales = await this.coaService.findByName(
|
||||||
`${coaType[coaType.SALES]}-SYSTEM`,
|
`${coaType[coaType.SALES]}-SYSTEM`,
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1135,16 +1146,23 @@ export class TransactionService {
|
||||||
if (userData.partner) {
|
if (userData.partner) {
|
||||||
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`;
|
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`;
|
||||||
this.callbackToPartner(
|
this.callbackToPartner(
|
||||||
userData.id,
|
userData.id,
|
||||||
message,
|
message,
|
||||||
dataTransaction.partner_trx_id,
|
dataTransaction.partner_trx_id,
|
||||||
dataTransaction.amount,
|
dataTransaction.amount,
|
||||||
product.code,
|
product.code,
|
||||||
dataTransaction.destination,
|
dataTransaction.destination,
|
||||||
'-',
|
'-',
|
||||||
'gagal',
|
'gagal',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
|
message: 'failed to proccess',
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async callbackOrderSuccess(supplier_trx_id: string, callback: any) {
|
async callbackOrderSuccess(supplier_trx_id: string, callback: any) {
|
||||||
|
@ -1155,6 +1173,19 @@ export class TransactionService {
|
||||||
relations: ['product_price'],
|
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.status = statusTransaction.SUCCESS;
|
||||||
dataTransaction.seri_number = callback['sn'];
|
dataTransaction.seri_number = callback['sn'];
|
||||||
dataTransaction.callback_json = callback;
|
dataTransaction.callback_json = callback;
|
||||||
|
@ -1164,33 +1195,33 @@ export class TransactionService {
|
||||||
let supervisorData = [];
|
let supervisorData = [];
|
||||||
|
|
||||||
const product_price = await this.productHistoryPriceService.findById(
|
const product_price = await this.productHistoryPriceService.findById(
|
||||||
dataTransaction.product_price.id,
|
dataTransaction.product_price.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
const product = await this.productService.findOneById(
|
const product = await this.productService.findOneById(
|
||||||
product_price.product.id,
|
product_price.product.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let profit = product_price.mark_up_price;
|
let profit = product_price.mark_up_price;
|
||||||
|
|
||||||
//GET COA
|
//GET COA
|
||||||
const coaExpense = await this.coaService.findByName(
|
const coaExpense = await this.coaService.findByName(
|
||||||
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
||||||
);
|
);
|
||||||
if (userData.partner != null) {
|
if (userData.partner != null) {
|
||||||
//GET SALES
|
//GET SALES
|
||||||
supervisorData = await this.calculateCommission(
|
supervisorData = await this.calculateCommission(
|
||||||
supervisorData,
|
supervisorData,
|
||||||
profit,
|
profit,
|
||||||
userData,
|
userData,
|
||||||
);
|
);
|
||||||
profit = supervisorData
|
profit = supervisorData
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
return item.credit;
|
return item.credit;
|
||||||
})
|
})
|
||||||
.reduce((prev, curr) => {
|
.reduce((prev, curr) => {
|
||||||
return prev + curr;
|
return prev + curr;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
supervisorData = supervisorData.concat([
|
supervisorData = supervisorData.concat([
|
||||||
{
|
{
|
||||||
|
@ -1219,16 +1250,21 @@ export class TransactionService {
|
||||||
if (userData.partner) {
|
if (userData.partner) {
|
||||||
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
|
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
|
||||||
this.callbackToPartner(
|
this.callbackToPartner(
|
||||||
userData.id,
|
userData.id,
|
||||||
message,
|
message,
|
||||||
dataTransaction.partner_trx_id,
|
dataTransaction.partner_trx_id,
|
||||||
dataTransaction.amount,
|
dataTransaction.amount,
|
||||||
product.code,
|
product.code,
|
||||||
dataTransaction.destination,
|
dataTransaction.destination,
|
||||||
dataTransaction.seri_number,
|
dataTransaction.seri_number,
|
||||||
'berhasil',
|
'berhasil',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async callbackToPartner(
|
async callbackToPartner(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user