fixing: ppob
This commit is contained in:
@@ -27,6 +27,8 @@ 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';
|
||||
|
||||
@Injectable()
|
||||
export class TransactionService {
|
||||
@@ -39,6 +41,8 @@ export class TransactionService {
|
||||
private transactionJournalRepository: Repository<TransactionJournal>,
|
||||
@InjectRepository(COA)
|
||||
private coaRepository: Repository<COA>,
|
||||
@InjectRepository(CheckBillHistory)
|
||||
private checkBillHistoryRepository: Repository<CheckBillHistory>,
|
||||
private coaService: CoaService,
|
||||
private productService: ProductService,
|
||||
private productHistoryPriceService: ProductHistoryPriceService,
|
||||
@@ -477,6 +481,8 @@ export class TransactionService {
|
||||
`${coaType[coaType.SALES]}-SYSTEM`,
|
||||
);
|
||||
|
||||
|
||||
|
||||
if (coaAccount.amount < product_price.mark_up_price + product_price.price) {
|
||||
throw new HttpException(
|
||||
{
|
||||
@@ -814,21 +820,52 @@ export class TransactionService {
|
||||
})
|
||||
.join('');
|
||||
|
||||
let hitSupplier = await doTransaction(
|
||||
'CEK' + orderTransactionDto.productCode.slice(3),
|
||||
orderTransactionDto.destination,
|
||||
trxId,
|
||||
supplier,
|
||||
);
|
||||
let status;
|
||||
|
||||
// let hitSupplier = await doTransaction(
|
||||
// 'CEKXL1',
|
||||
// orderTransactionDto.destination,
|
||||
// trxId,
|
||||
// supplier,
|
||||
// );
|
||||
try {
|
||||
let hitSupplier = await doTransaction(
|
||||
'CEK' + orderTransactionDto.productCode.slice(3),
|
||||
orderTransactionDto.destination,
|
||||
trxId,
|
||||
supplier,
|
||||
);
|
||||
const parsingResponse = hitSupplier.split(' ');
|
||||
hitSupplier = {
|
||||
success: hitSupplier.include('diproses'),
|
||||
msg: hitSupplier,
|
||||
};
|
||||
|
||||
return hitSupplier;
|
||||
if (!hitSupplier.success) {
|
||||
status = statusTransaction[statusTransaction.FAILED];
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
error: hitSupplier.msg,
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
} else {
|
||||
status = statusTransaction[statusTransaction.SUCCESS];
|
||||
|
||||
await this.checkBillHistoryRepository.insert({
|
||||
trx_id: trxId,
|
||||
user: userData.id,
|
||||
callback_json: JSON.stringify(hitSupplier),
|
||||
destination: orderTransactionDto.destination,
|
||||
product_code: orderTransactionDto.productCode,
|
||||
partner_trx_id: orderTransactionDto.trx_id,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
return {
|
||||
trx_id: trxId,
|
||||
client_trx_id: orderTransactionDto.trx_id,
|
||||
product: orderTransactionDto.productCode,
|
||||
status: status,
|
||||
};
|
||||
}
|
||||
|
||||
async createDepositReturn(currentUser, depositReturnDto: DepositReturnDto) {
|
||||
@@ -1060,6 +1097,20 @@ export class TransactionService {
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
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',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async callbackOrderSuccess(supplier_trx_id: string, callback: any) {
|
||||
@@ -1131,6 +1182,36 @@ export class TransactionService {
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
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',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async callbackToPartner(
|
||||
partnerId: string,
|
||||
message: string,
|
||||
trxId: string,
|
||||
harga: number,
|
||||
productCode: string,
|
||||
destination: string,
|
||||
seriNumber: string,
|
||||
status: string,
|
||||
) {
|
||||
const partnerData = await this.userService.findPartner(partnerId);
|
||||
const res = await axios.get(
|
||||
`${partnerData.callback_url}?status=${status}&memberID=${partnerData.code}&trxid=${trxId}&harga=${harga}&product=${productCode}&dest=${destination}&seriNumber=${seriNumber}&message=${message}`,
|
||||
);
|
||||
}
|
||||
|
||||
async withdrawBenefit(user) {
|
||||
|
||||
Reference in New Issue
Block a user