-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
5c50d1d53a
commit
7fe73c0dc4
|
@ -19,17 +19,18 @@ export class PpobCallbackController {
|
||||||
|
|
||||||
if (response['statuscode'] == 2) {
|
if (response['statuscode'] == 2) {
|
||||||
//TODO: UPDATE GAGAL
|
//TODO: UPDATE GAGAL
|
||||||
await this.transactionService.callbackOrderFailed(
|
await this.transactionService.checkCallbackOrderFailed(
|
||||||
response['clientid'],
|
response['clientid'],
|
||||||
response,
|
response,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: UPDATE BERHASIL
|
//TODO: UPDATE BERHASIL
|
||||||
await this.transactionService.callbackOrderSuccess(
|
await this.transactionService.checkCallbackOrderSuccess(
|
||||||
response['clientid'],
|
response['clientid'],
|
||||||
response,
|
response,
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public()
|
@Public()
|
||||||
|
|
|
@ -10,12 +10,7 @@ import { CoaService } from './coa.service';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import {uniq} from 'lodash';
|
import {uniq} from 'lodash';
|
||||||
import {Decimal} from 'decimal.js';
|
import {Decimal} from 'decimal.js';
|
||||||
import {
|
import {balanceType, coaType, statusTransaction, typeTransaction,} from '../helper/enum-list';
|
||||||
balanceType,
|
|
||||||
coaType,
|
|
||||||
statusTransaction,
|
|
||||||
typeTransaction,
|
|
||||||
} from '../helper/enum-list';
|
|
||||||
import {ProductService} from '../product/product.service';
|
import {ProductService} from '../product/product.service';
|
||||||
import {CreateJournalDto} from './dto/create-journal.dto';
|
import {CreateJournalDto} from './dto/create-journal.dto';
|
||||||
import {UsersService} from 'src/users/users.service';
|
import {UsersService} from 'src/users/users.service';
|
||||||
|
@ -1059,6 +1054,109 @@ export class TransactionService {
|
||||||
return transactionData;
|
return transactionData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkCallbackOrderFailed(supplier_trx_id: string, callback: any) {
|
||||||
|
|
||||||
|
const transactionData = await this.findDataTransactionBySupplierTrxId(
|
||||||
|
supplier_trx_id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (transactionData.status == statusTransaction.FAILED) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
|
error: 'failed to update, the transaction already failed',
|
||||||
|
},
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
} else if (transactionData.status == statusTransaction.SUCCESS) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
|
error: 'failed to update, the transaction already success',
|
||||||
|
},
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const updateTransaction =
|
||||||
|
await this.callbackOrderFailed(
|
||||||
|
supplier_trx_id,
|
||||||
|
callback,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
updateTransaction,
|
||||||
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
|
message: 'failed to proccess',
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkCallbackOrderSuccess(supplier_trx_id: string, callback: any) {
|
||||||
|
|
||||||
|
const transactionData = await this.findDataTransactionBySupplierTrxId(
|
||||||
|
supplier_trx_id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (transactionData.status == statusTransaction.FAILED) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
|
error: 'failed to update, the transaction already failed',
|
||||||
|
},
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
} else if (transactionData.status == statusTransaction.SUCCESS) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
|
error: 'failed to update, the transaction already success',
|
||||||
|
},
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const updateTransaction =
|
||||||
|
await this.callbackOrderSuccess(
|
||||||
|
supplier_trx_id,
|
||||||
|
callback,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
updateTransaction,
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async findDataTransactionBySupplierTrxId(supplier_trx_id: string) {
|
||||||
|
try {
|
||||||
|
return await this.transactionRepository.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
supplier_trx_id: supplier_trx_id,
|
||||||
|
},
|
||||||
|
relations: ['product_price'],
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
error: 'data not found',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async callbackOrderFailed(supplier_trx_id: string, callback: any) {
|
async callbackOrderFailed(supplier_trx_id: string, callback: any) {
|
||||||
const dataTransaction = await this.transactionRepository.findOne({
|
const dataTransaction = await this.transactionRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user