Merge branch 'devops-staging' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend
This commit is contained in:
commit
dcb85e0ef7
|
@ -10,6 +10,9 @@ export class Transactions extends BaseModel {
|
||||||
@Column()
|
@Column()
|
||||||
amount: number;
|
amount: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
balance_remaining: number;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
status: statusTransaction;
|
status: statusTransaction;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
import { Controller, Get, HttpStatus, Logger, Req } from '@nestjs/common';
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
Logger,
|
||||||
|
Req,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { TransactionService } from './transaction.service';
|
import { TransactionService } from './transaction.service';
|
||||||
import { FastifyRequest } from 'fastify';
|
import { FastifyRequest } from 'fastify';
|
||||||
import { Public } from '../auth/public.decorator';
|
import { Public } from '../auth/public.decorator';
|
||||||
|
import { EntityNotFoundError } from 'typeorm';
|
||||||
|
|
||||||
@Controller({
|
@Controller({
|
||||||
path: 'ppob_callback',
|
path: 'ppob_callback',
|
||||||
|
@ -20,15 +28,14 @@ export class PpobCallbackController {
|
||||||
if (response['statuscode'] == 2) {
|
if (response['statuscode'] == 2) {
|
||||||
//TODO: UPDATE GAGAL
|
//TODO: UPDATE GAGAL
|
||||||
await this.transactionService.checkCallbackOrderFailed(
|
await this.transactionService.checkCallbackOrderFailed(
|
||||||
response['clientid'],
|
response['clientid'],
|
||||||
response,
|
response,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//TODO: UPDATE BERHASIL
|
//TODO: UPDATE BERHASIL
|
||||||
await this.transactionService.checkCallbackOrderSuccess(
|
await this.transactionService.checkCallbackOrderSuccess(
|
||||||
response['clientid'],
|
response['clientid'],
|
||||||
response,
|
response,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,75 +43,92 @@ export class PpobCallbackController {
|
||||||
@Public()
|
@Public()
|
||||||
@Get('/metro')
|
@Get('/metro')
|
||||||
async getMetro(@Req() request: FastifyRequest) {
|
async getMetro(@Req() request: FastifyRequest) {
|
||||||
const response = request.query;
|
try {
|
||||||
|
const response = request.query;
|
||||||
|
|
||||||
if (response['message'].toLowerCase().includes('cek tagihan')) {
|
if (response['message'].toLowerCase().includes('cek tagihan')) {
|
||||||
if (response['status'] != 20) {
|
if (response['status'] != 20) {
|
||||||
//TODO: UPDATE GAGAL
|
//TODO: UPDATE GAGAL
|
||||||
await this.transactionService.updateBill(
|
await this.transactionService.updateBill(
|
||||||
response['refid'],
|
response['refid'],
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
response['message'],
|
response['message'],
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const splitMessage = response['message'].split('"');
|
const splitMessage = response['message'].split('"');
|
||||||
//TODO: UPDATE BERHASIL
|
|
||||||
await this.transactionService.updateBill(
|
//TODO: UPDATE BERHASIL
|
||||||
|
await this.transactionService.updateBill(
|
||||||
response['refid'],
|
response['refid'],
|
||||||
Number(splitMessage[21].replace(/^\D+/g, '')),
|
Number(splitMessage[21].replace(/^\D+/g, '')),
|
||||||
Number(splitMessage[17].replace(/^\D+/g, '')),
|
Number(splitMessage[17].replace(/^\D+/g, '')),
|
||||||
true,
|
true,
|
||||||
response['message'],
|
response['message'],
|
||||||
);
|
);
|
||||||
//
|
//
|
||||||
} else {
|
|
||||||
console.log('statusapani', response['status']);
|
|
||||||
console.log('statusapani2', response.toString());
|
|
||||||
if (response['status'].toString() != '20') {
|
|
||||||
console.log("masukkesiniga", "msk")
|
|
||||||
//TODO: UPDATE GAGAL
|
|
||||||
const updateTransaction =
|
|
||||||
await this.transactionService.callbackOrderFailed(
|
|
||||||
response['refid'],
|
|
||||||
response,
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
updateTransaction,
|
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
|
||||||
message: 'failed to proccess',
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
|
console.log('statusapani', response['status']);
|
||||||
|
console.log('statusapani2', response.toString());
|
||||||
|
|
||||||
//TODO: UPDATE BERHASIL
|
if (response['status'].toString() != '20') {
|
||||||
const updateTransaction =
|
//TODO: UPDATE GAGAL
|
||||||
await this.transactionService.callbackOrderSuccess(
|
const updateTransaction =
|
||||||
response['refid'],
|
await this.transactionService.callbackOrderFailed(
|
||||||
response,
|
response['refid'],
|
||||||
);
|
response,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
updateTransaction,
|
updateTransaction,
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
message: 'success',
|
message: 'failed to proccess',
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//TODO: UPDATE BERHASIL
|
||||||
|
const updateTransaction =
|
||||||
|
await this.transactionService.callbackOrderSuccess(
|
||||||
|
response['refid'],
|
||||||
|
response,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
updateTransaction,
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.log({
|
||||||
|
requestQuery: request.query,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
error: 'Error callback',
|
||||||
|
message: e
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.logger.log({
|
|
||||||
requestQuery: request.query,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
statusCode: HttpStatus.OK,
|
|
||||||
message: 'success',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { UsersModule } from 'src/users/users.module';
|
||||||
import { ConfigurableModule } from '../configurable/configurable.module';
|
import { ConfigurableModule } from '../configurable/configurable.module';
|
||||||
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';
|
||||||
|
import {ProductHistoryPrice} from "../product/entities/product-history-price.entity";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -21,6 +22,7 @@ import { CallbackPartner } from './entities/callback-partner.entity';
|
||||||
Transactions,
|
Transactions,
|
||||||
CheckBillHistory,
|
CheckBillHistory,
|
||||||
CallbackPartner,
|
CallbackPartner,
|
||||||
|
ProductHistoryPrice,
|
||||||
]),
|
]),
|
||||||
ProductModule,
|
ProductModule,
|
||||||
ConfigurableModule,
|
ConfigurableModule,
|
||||||
|
|
|
@ -35,6 +35,8 @@ export class TransactionService {
|
||||||
private transactionRepository: Repository<Transactions>,
|
private transactionRepository: Repository<Transactions>,
|
||||||
@InjectRepository(TransactionJournal)
|
@InjectRepository(TransactionJournal)
|
||||||
private transactionJournalRepository: Repository<TransactionJournal>,
|
private transactionJournalRepository: Repository<TransactionJournal>,
|
||||||
|
@InjectRepository(ProductHistoryPrice)
|
||||||
|
private productPriceRepository: Repository<ProductHistoryPrice>,
|
||||||
@InjectRepository(COA)
|
@InjectRepository(COA)
|
||||||
private coaRepository: Repository<COA>,
|
private coaRepository: Repository<COA>,
|
||||||
@InjectRepository(CheckBillHistory)
|
@InjectRepository(CheckBillHistory)
|
||||||
|
@ -627,6 +629,7 @@ export class TransactionService {
|
||||||
transactionData.partner_trx_id = orderTransactionDto.trx_id;
|
transactionData.partner_trx_id = orderTransactionDto.trx_id;
|
||||||
transactionData.supplier_trx_id = trxId;
|
transactionData.supplier_trx_id = trxId;
|
||||||
transactionData.check_bill = orderTransactionDto.bill_trx_id;
|
transactionData.check_bill = orderTransactionDto.bill_trx_id;
|
||||||
|
transactionData.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory;
|
||||||
|
|
||||||
if (!hitSupplier.success) {
|
if (!hitSupplier.success) {
|
||||||
transactionData.status = statusTransaction.FAILED;
|
transactionData.status = statusTransaction.FAILED;
|
||||||
|
@ -1201,6 +1204,12 @@ export class TransactionService {
|
||||||
relations: ['product_price'],
|
relations: ['product_price'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const dataProductHistoryPrice = await this.productPriceRepository.findOne({
|
||||||
|
where: {
|
||||||
|
id: dataTransaction.product_price.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// const dataMsg = callback.msg;
|
// const dataMsg = callback.msg;
|
||||||
// const failedReason = dataMsg.split('.');
|
// const failedReason = dataMsg.split('.');
|
||||||
|
|
||||||
|
@ -1222,10 +1231,13 @@ export class TransactionService {
|
||||||
dataTransaction.callback_json = callback;
|
dataTransaction.callback_json = callback;
|
||||||
dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal`;
|
dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal`;
|
||||||
|
|
||||||
|
console.log("inipricetable", dataTransaction.product_price.price)
|
||||||
|
console.log("inipricecallback", callback['price'])
|
||||||
if(callback['message']) {
|
if(callback['message']) {
|
||||||
if (callback['message'].includes('METRO')) {
|
if (callback['message'].includes('METRO')) {
|
||||||
if (callback['price'] != dataTransaction.product_price.price) {
|
if (callback['price'] != dataTransaction.product_price.price) {
|
||||||
dataTransaction.product_price.price = callback['price']
|
console.log("mskupdt", "msk")
|
||||||
|
dataTransaction.product_price.price = parseInt(callback['price'])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1236,6 +1248,11 @@ export class TransactionService {
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
dataTransaction.status = statusTransaction.FAILED;
|
||||||
|
dataTransaction.callback_json = callback;
|
||||||
|
dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal`;
|
||||||
|
dataTransaction.balance_remaining = coaAccount.amount + product_price.mark_up_price + product_price.price;
|
||||||
|
|
||||||
const coaInventory = await this.coaService.findByName(
|
const coaInventory = await this.coaService.findByName(
|
||||||
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
||||||
);
|
);
|
||||||
|
@ -1251,6 +1268,7 @@ export class TransactionService {
|
||||||
try {
|
try {
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
await manager.save(dataTransaction);
|
await manager.save(dataTransaction);
|
||||||
|
await manager.save(dataProductHistoryPrice);
|
||||||
|
|
||||||
await this.accountingTransaction({
|
await this.accountingTransaction({
|
||||||
createTransaction: false,
|
createTransaction: false,
|
||||||
|
@ -1304,6 +1322,12 @@ export class TransactionService {
|
||||||
relations: ['product_price'],
|
relations: ['product_price'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const dataProductHistoryPrice = await this.productPriceRepository.findOne({
|
||||||
|
where: {
|
||||||
|
id: dataTransaction.product_price.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
dataTransaction.status = statusTransaction.SUCCESS;
|
dataTransaction.status = statusTransaction.SUCCESS;
|
||||||
if(callback['sn']){
|
if(callback['sn']){
|
||||||
dataTransaction.seri_number = callback['sn'];
|
dataTransaction.seri_number = callback['sn'];
|
||||||
|
@ -1318,7 +1342,7 @@ export class TransactionService {
|
||||||
if(callback['message']) {
|
if(callback['message']) {
|
||||||
if (callback['message'].includes('METRO')) {
|
if (callback['message'].includes('METRO')) {
|
||||||
if (callback['price'] != dataTransaction.product_price.price) {
|
if (callback['price'] != dataTransaction.product_price.price) {
|
||||||
dataTransaction.product_price.price = callback['price']
|
dataProductHistoryPrice.price = parseInt(callback['price'])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1342,6 +1366,8 @@ export class TransactionService {
|
||||||
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// dataTransaction.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory;
|
||||||
|
|
||||||
if (userData.partner == null) {
|
if (userData.partner == null) {
|
||||||
//GET SALES
|
//GET SALES
|
||||||
supervisorData = await this.calculateCommission(
|
supervisorData = await this.calculateCommission(
|
||||||
|
@ -1368,6 +1394,7 @@ export class TransactionService {
|
||||||
try {
|
try {
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
await manager.save(dataTransaction);
|
await manager.save(dataTransaction);
|
||||||
|
await manager.save(dataProductHistoryPrice)
|
||||||
|
|
||||||
await this.accountingTransaction({
|
await this.accountingTransaction({
|
||||||
createTransaction: false,
|
createTransaction: false,
|
||||||
|
@ -1461,14 +1488,26 @@ export class TransactionService {
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!partnerData.callback_url) {
|
||||||
|
this.logger.error(`Call to partner failed, reason: no callback url`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const url = `${partnerData.callback_url}?status=${status}&memberID=${partnerData.code}&trxid=${trxId}&harga=${harga}&product=${productCode}&dest=${destination}&seriNumber=${seriNumber}&message=${message}&saldo=${coaAccount.amount}`;
|
const url = `${partnerData.callback_url}?status=${status}&memberID=${partnerData.code}&trxid=${trxId}&harga=${harga}&product=${productCode}&dest=${destination}&seriNumber=${seriNumber}&message=${message}&saldo=${coaAccount.amount}`;
|
||||||
const result = await this.callbackPartnerRepository.insert({
|
const result = await this.callbackPartnerRepository.insert({
|
||||||
partner_trx_id: partnerId,
|
partner_trx_id: partnerId,
|
||||||
trx_id: trxId,
|
trx_id: trxId,
|
||||||
url: url,
|
url: url,
|
||||||
});
|
});
|
||||||
const res = await axios.get(url);
|
|
||||||
return res;
|
try {
|
||||||
|
const res = await axios.get(url);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.error(`Call to partner failed, reason: ${e.message}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async rollbackJurnal(trxId: string[]) {
|
async rollbackJurnal(trxId: string[]) {
|
||||||
|
@ -1625,7 +1664,8 @@ export class TransactionService {
|
||||||
.leftJoin('product.supplier', 'supplier')
|
.leftJoin('product.supplier', 'supplier')
|
||||||
.addSelect('transaction.amount', 'price')
|
.addSelect('transaction.amount', 'price')
|
||||||
.addSelect('transaction.destination')
|
.addSelect('transaction.destination')
|
||||||
.addSelect('transaction.seri_number', 'seri_number')
|
.addSelect('transaction.balance_remaining', 'balance_remaining')
|
||||||
|
.addSelect('transaction.seri_number', 'seri_number')
|
||||||
.addSelect('transaction.supplier_trx_id', 'transaction_code')
|
.addSelect('transaction.supplier_trx_id', 'transaction_code')
|
||||||
.addSelect('transaction.status', 'status')
|
.addSelect('transaction.status', 'status')
|
||||||
.addSelect('transaction.partner_trx_id', 'partner_transaction_code')
|
.addSelect('transaction.partner_trx_id', 'partner_transaction_code')
|
||||||
|
@ -1633,6 +1673,7 @@ export class TransactionService {
|
||||||
.addSelect('userData.name', 'buyer')
|
.addSelect('userData.name', 'buyer')
|
||||||
.addSelect('product.name', 'name')
|
.addSelect('product.name', 'name')
|
||||||
.addSelect('product_price.price', 'product_price')
|
.addSelect('product_price.price', 'product_price')
|
||||||
|
.addSelect('product_price.mark_up_price', 'mark_up_price')
|
||||||
.addSelect('product.name', 'supplier_name')
|
.addSelect('product.name', 'supplier_name')
|
||||||
.addSelect('supplier.name', 'supplier_name')
|
.addSelect('supplier.name', 'supplier_name')
|
||||||
.orderBy('transaction.created_at', 'DESC');
|
.orderBy('transaction.created_at', 'DESC');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user