-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) {
|
||||
//TODO: UPDATE GAGAL
|
||||
await this.transactionService.callbackOrderFailed(
|
||||
response['clientid'],
|
||||
response,
|
||||
);
|
||||
await this.transactionService.checkCallbackOrderFailed(
|
||||
response['clientid'],
|
||||
response,
|
||||
);
|
||||
}
|
||||
|
||||
//TODO: UPDATE BERHASIL
|
||||
await this.transactionService.callbackOrderSuccess(
|
||||
response['clientid'],
|
||||
response,
|
||||
);
|
||||
await this.transactionService.checkCallbackOrderSuccess(
|
||||
response['clientid'],
|
||||
response,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Public()
|
||||
|
@ -41,11 +42,11 @@ export class PpobCallbackController {
|
|||
if (response['status'] != 20) {
|
||||
//TODO: UPDATE GAGAL
|
||||
await this.transactionService.updateBill(
|
||||
response['refid'],
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
response['message'],
|
||||
response['refid'],
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
response['message'],
|
||||
);
|
||||
|
||||
return {
|
||||
|
@ -57,21 +58,21 @@ export class PpobCallbackController {
|
|||
const splitMessage = response['message'].split('"');
|
||||
//TODO: UPDATE BERHASIL
|
||||
await this.transactionService.updateBill(
|
||||
response['refid'],
|
||||
Number(splitMessage[21].replace(/^\D+/g, '')),
|
||||
Number(splitMessage[17].replace(/^\D+/g, '')),
|
||||
true,
|
||||
response['message'],
|
||||
response['refid'],
|
||||
Number(splitMessage[21].replace(/^\D+/g, '')),
|
||||
Number(splitMessage[17].replace(/^\D+/g, '')),
|
||||
true,
|
||||
response['message'],
|
||||
);
|
||||
//
|
||||
} else {
|
||||
if (response['status'].toString() != '20') {
|
||||
//TODO: UPDATE GAGAL
|
||||
const updateTransaction =
|
||||
await this.transactionService.callbackOrderFailed(
|
||||
response['refid'],
|
||||
response,
|
||||
);
|
||||
await this.transactionService.callbackOrderFailed(
|
||||
response['refid'],
|
||||
response,
|
||||
);
|
||||
|
||||
return {
|
||||
updateTransaction,
|
||||
|
@ -82,10 +83,10 @@ export class PpobCallbackController {
|
|||
|
||||
//TODO: UPDATE BERHASIL
|
||||
const updateTransaction =
|
||||
await this.transactionService.callbackOrderSuccess(
|
||||
response['refid'],
|
||||
response,
|
||||
);
|
||||
await this.transactionService.callbackOrderSuccess(
|
||||
response['refid'],
|
||||
response,
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log({
|
||||
|
|
|
@ -1,35 +1,30 @@
|
|||
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
|
||||
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
||||
import { OrderTransactionDto } from './dto/order-transaction.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Transactions } from './entities/transactions.entity';
|
||||
import { Between, Connection, EntityNotFoundError, In, Repository } from 'typeorm';
|
||||
import { COA } from './entities/coa.entity';
|
||||
import { TransactionJournal } from './entities/transaction-journal.entity';
|
||||
import { CoaService } from './coa.service';
|
||||
import {HttpException, HttpStatus, Injectable, Logger} from '@nestjs/common';
|
||||
import {DistributeTransactionDto} from './dto/distribute-transaction.dto';
|
||||
import {OrderTransactionDto} from './dto/order-transaction.dto';
|
||||
import {InjectRepository} from '@nestjs/typeorm';
|
||||
import {Transactions} from './entities/transactions.entity';
|
||||
import {Between, Connection, EntityNotFoundError, In, Repository} from 'typeorm';
|
||||
import {COA} from './entities/coa.entity';
|
||||
import {TransactionJournal} from './entities/transaction-journal.entity';
|
||||
import {CoaService} from './coa.service';
|
||||
import * as uuid from 'uuid';
|
||||
import { uniq } from 'lodash';
|
||||
import { Decimal } from 'decimal.js';
|
||||
import {
|
||||
balanceType,
|
||||
coaType,
|
||||
statusTransaction,
|
||||
typeTransaction,
|
||||
} from '../helper/enum-list';
|
||||
import { ProductService } from '../product/product.service';
|
||||
import { CreateJournalDto } from './dto/create-journal.dto';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
import { AddSaldoSupplier } from './dto/add-saldo-supplier.dto';
|
||||
import { SupplierService } from '../users/supplier/supplier.service';
|
||||
import { ProductHistoryPriceService } from '../product/history-price/history-price.service';
|
||||
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 {uniq} from 'lodash';
|
||||
import {Decimal} from 'decimal.js';
|
||||
import {balanceType, coaType, statusTransaction, typeTransaction,} from '../helper/enum-list';
|
||||
import {ProductService} from '../product/product.service';
|
||||
import {CreateJournalDto} from './dto/create-journal.dto';
|
||||
import {UsersService} from 'src/users/users.service';
|
||||
import {AddSaldoSupplier} from './dto/add-saldo-supplier.dto';
|
||||
import {SupplierService} from '../users/supplier/supplier.service';
|
||||
import {ProductHistoryPriceService} from '../product/history-price/history-price.service';
|
||||
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 { CheckBillHistory } from './entities/check-bill-history.entity';
|
||||
import { CallbackPartner } from './entities/callback-partner.entity';
|
||||
import {CheckBillHistory} from './entities/check-bill-history.entity';
|
||||
import {CallbackPartner} from './entities/callback-partner.entity';
|
||||
|
||||
@Injectable()
|
||||
export class TransactionService {
|
||||
|
@ -1059,6 +1054,109 @@ export class TransactionService {
|
|||
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) {
|
||||
const dataTransaction = await this.transactionRepository.findOne({
|
||||
where: {
|
||||
|
|
Loading…
Reference in New Issue
Block a user