-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()
|
||||||
|
|
|
@ -1,35 +1,30 @@
|
||||||
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
|
import {HttpException, HttpStatus, Injectable, Logger} from '@nestjs/common';
|
||||||
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
import {DistributeTransactionDto} from './dto/distribute-transaction.dto';
|
||||||
import { OrderTransactionDto } from './dto/order-transaction.dto';
|
import {OrderTransactionDto} from './dto/order-transaction.dto';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import {InjectRepository} from '@nestjs/typeorm';
|
||||||
import { Transactions } from './entities/transactions.entity';
|
import {Transactions} from './entities/transactions.entity';
|
||||||
import { Between, Connection, EntityNotFoundError, In, Repository } from 'typeorm';
|
import {Between, Connection, EntityNotFoundError, In, Repository} from 'typeorm';
|
||||||
import { COA } from './entities/coa.entity';
|
import {COA} from './entities/coa.entity';
|
||||||
import { TransactionJournal } from './entities/transaction-journal.entity';
|
import {TransactionJournal} from './entities/transaction-journal.entity';
|
||||||
import { CoaService } from './coa.service';
|
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,
|
import {ProductService} from '../product/product.service';
|
||||||
coaType,
|
import {CreateJournalDto} from './dto/create-journal.dto';
|
||||||
statusTransaction,
|
import {UsersService} from 'src/users/users.service';
|
||||||
typeTransaction,
|
import {AddSaldoSupplier} from './dto/add-saldo-supplier.dto';
|
||||||
} from '../helper/enum-list';
|
import {SupplierService} from '../users/supplier/supplier.service';
|
||||||
import { ProductService } from '../product/product.service';
|
import {ProductHistoryPriceService} from '../product/history-price/history-price.service';
|
||||||
import { CreateJournalDto } from './dto/create-journal.dto';
|
import {CommissionService} from '../configurable/commission.service';
|
||||||
import { UsersService } from 'src/users/users.service';
|
import {DepositReturnDto} from './dto/deposit_return.dto';
|
||||||
import { AddSaldoSupplier } from './dto/add-saldo-supplier.dto';
|
import {UserDetail} from '../users/entities/user_detail.entity';
|
||||||
import { SupplierService } from '../users/supplier/supplier.service';
|
import {doTransaction} from '../helper/irs-api';
|
||||||
import { ProductHistoryPriceService } from '../product/history-price/history-price.service';
|
import {ProductHistoryPrice} from '../product/entities/product-history-price.entity';
|
||||||
import { CommissionService } from '../configurable/commission.service';
|
|
||||||
import { DepositReturnDto } from './dto/deposit_return.dto';
|
|
||||||
import { UserDetail } from '../users/entities/user_detail.entity';
|
|
||||||
import { doTransaction } from '../helper/irs-api';
|
|
||||||
import { ProductHistoryPrice } from '../product/entities/product-history-price.entity';
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { CheckBillHistory } from './entities/check-bill-history.entity';
|
import {CheckBillHistory} from './entities/check-bill-history.entity';
|
||||||
import { CallbackPartner } from './entities/callback-partner.entity';
|
import {CallbackPartner} from './entities/callback-partner.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionService {
|
export class TransactionService {
|
||||||
|
@ -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