Merge branch 'master' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into devops-production
This commit is contained in:
commit
05c8ee100e
|
@ -1,5 +1,6 @@
|
|||
import axios from 'axios';
|
||||
import {HttpException, HttpStatus, NotFoundException} from "@nestjs/common";
|
||||
import {createHmac} from "crypto";
|
||||
|
||||
const irs_url = 'http://h2h.elangpixiu.com/api/h2h';
|
||||
const irs_id = 'PT0005';
|
||||
|
@ -15,6 +16,8 @@ export const doTransaction = async (
|
|||
authorization,
|
||||
typePaid,
|
||||
billTrxId,
|
||||
productVocaSubCategoryId,
|
||||
productPrice
|
||||
) => {
|
||||
try {
|
||||
if (supplier.code == 'IRS') {
|
||||
|
@ -29,6 +32,69 @@ export const doTransaction = async (
|
|||
);
|
||||
|
||||
return res.data;
|
||||
} else if (supplier.code == 'Vocagame') {
|
||||
const merchantId = supplier.irs_id;
|
||||
const reference = idtrx
|
||||
const endpoint = `/transaction/${reference}`;
|
||||
const secretKey = supplier.irs_pass;
|
||||
const signature = createHmac('sha256', secretKey)
|
||||
.update(merchantId + endpoint)
|
||||
.digest('hex');
|
||||
|
||||
const options = {
|
||||
headers: {'Content-Type': 'application/json',
|
||||
'X-Merchant': `${merchantId}`},
|
||||
};
|
||||
|
||||
const mergedDestination = destination;
|
||||
const regex = /\(([^)]+)\)/;
|
||||
const match = regex.exec(mergedDestination);
|
||||
|
||||
let productDestination = ""
|
||||
let productRegion = ""
|
||||
if (match) {
|
||||
var productSplit = destination.split('(')
|
||||
productDestination = productSplit[0]
|
||||
const insideBrackets = match[1];
|
||||
productRegion = insideBrackets // This will print inside brackets
|
||||
} else {
|
||||
productDestination = destination
|
||||
}
|
||||
|
||||
const data =
|
||||
{
|
||||
productId: productVocaSubCategoryId, // Sub Kategori ID
|
||||
productItemId: productCode, // Product Code
|
||||
data: { // Get object from user input within endpoint /products/detail
|
||||
userId: productDestination,
|
||||
zoneId: productRegion // Optional
|
||||
},
|
||||
price: productPrice, // Price equals from items
|
||||
reference: reference, // Your reference I
|
||||
callbackUrl: "https://api.wndsolutions.id/v1/ppob_callback/vocagame" // Set your endpoint callback
|
||||
}
|
||||
|
||||
const res = await axios.post(
|
||||
`${supplier.url}/v1/core/transaction?signature=${signature}`,
|
||||
data,
|
||||
options,
|
||||
);
|
||||
|
||||
var responseVoca = res.data.data;
|
||||
console.log('iniresponsevoca', responseVoca)
|
||||
if (responseVoca != null) {
|
||||
const endpointDetail = `/transaction/${responseVoca.invoiceId}/detail`;
|
||||
const signatureDetail = createHmac('sha256', secretKey)
|
||||
.update(merchantId + endpointDetail)
|
||||
.digest('hex');
|
||||
const resDetail = await axios.get(
|
||||
`${supplier.url}/v1/core/transaction/${responseVoca.invoiceId}/detail?signature=${signatureDetail}`,
|
||||
options,
|
||||
);
|
||||
|
||||
return resDetail.data
|
||||
}
|
||||
|
||||
} else if (supplier.code == 'Digiflazz') {
|
||||
if (typePaid == 'INQUIRY') {
|
||||
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
||||
|
|
|
@ -16,6 +16,11 @@ export class ProductSubCategories extends BaseModel {
|
|||
})
|
||||
code: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
code_voca: string;
|
||||
|
||||
@ManyToOne(() => ProductCategories, (categories) => categories.sub_categories)
|
||||
category: ProductCategories;
|
||||
|
||||
|
|
|
@ -32,6 +32,6 @@ import {ProductHistoryStatusService} from "./history-status/history-status.servi
|
|||
ProductHistoryPriceService,
|
||||
ProductHistoryStatusService,
|
||||
],
|
||||
exports: [ProductService, ProductHistoryPriceService, ProductHistoryStatusService],
|
||||
exports: [ProductService, ProductHistoryPriceService, ProductHistoryStatusService, ProductSubCategoriesService],
|
||||
})
|
||||
export class ProductModule {}
|
||||
|
|
|
@ -174,4 +174,32 @@ export class PpobCallbackController {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('/vocagame')
|
||||
async getVoca(@Req() request: FastifyRequest) {
|
||||
const response = request.body;
|
||||
console.log('responsevocagame', response);
|
||||
if (response['status'] != 'Success') {
|
||||
//TODO: UPDATE GAGAL
|
||||
console.log('responsevocagame1', response['status'])
|
||||
if (response['status'] != 'Processing') {
|
||||
console.log('responsevocagame2', response['status'])
|
||||
await this.transactionService.checkCallbackOrderFailed(
|
||||
response['reference'],
|
||||
response,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
//TODO: UPDATE BERHASIL
|
||||
console.log('responsevocagame3', response['status'])
|
||||
if (response['status'] != 'Processing') {
|
||||
console.log('responsevocagame4', response['status'])
|
||||
await this.transactionService.checkCallbackOrderSuccess(
|
||||
response['reference'],
|
||||
response,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,14 +90,25 @@ export class TransactionController {
|
|||
@Body() orderTransactionDto: OrderTransactionDto,
|
||||
@Request() req,
|
||||
) {
|
||||
return {
|
||||
data: await this.transactionService.orderTransactionProd(
|
||||
orderTransactionDto,
|
||||
req.user,
|
||||
),
|
||||
statusCode: HttpStatus.CREATED,
|
||||
message: 'success',
|
||||
};
|
||||
if (req.get('host').includes('ppob-backend.k3s.bangun-kreatif.com')) {
|
||||
return {
|
||||
data: await this.transactionService.orderTransaction(
|
||||
orderTransactionDto,
|
||||
req.user,
|
||||
),
|
||||
statusCode: HttpStatus.CREATED,
|
||||
message: 'success',
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
data: await this.transactionService.orderTransactionProd(
|
||||
orderTransactionDto,
|
||||
req.user,
|
||||
),
|
||||
statusCode: HttpStatus.CREATED,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Post('order-bill-prod')
|
||||
|
|
|
@ -15,6 +15,7 @@ import { CallbackPartner } from './entities/callback-partner.entity';
|
|||
import { ProductHistoryPrice } from '../product/entities/product-history-price.entity';
|
||||
import { ProductHistoryStatus } from '../product/entities/product-history-status.entity';
|
||||
import { ExcelController } from './excel.controller';
|
||||
import {ProductSubCategories} from "../product/entities/product-sub-category.entity";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -26,6 +27,7 @@ import { ExcelController } from './excel.controller';
|
|||
CallbackPartner,
|
||||
ProductHistoryPrice,
|
||||
ProductHistoryStatus,
|
||||
ProductSubCategories
|
||||
]),
|
||||
ProductModule,
|
||||
ConfigurableModule,
|
||||
|
|
|
@ -47,6 +47,7 @@ import { doAuthorizeHemat } from '../helper/sihemat-authorization';
|
|||
import { ProductHistoryStatusService } from '../product/history-status/history-status.service';
|
||||
import { Workbook } from 'exceljs';
|
||||
import moment from "moment";
|
||||
import {ProductSubCategoriesService} from "../product/product-sub-categories.service";
|
||||
|
||||
@Injectable()
|
||||
export class TransactionService {
|
||||
|
@ -67,6 +68,7 @@ export class TransactionService {
|
|||
private callbackPartnerRepository: Repository<CallbackPartner>,
|
||||
private coaService: CoaService,
|
||||
private productService: ProductService,
|
||||
private productSubcategoriesService: ProductSubCategoriesService,
|
||||
private productHistoryPriceService: ProductHistoryPriceService,
|
||||
private productHistoryStatusService: ProductHistoryStatusService,
|
||||
private userService: UsersService,
|
||||
|
@ -531,6 +533,10 @@ export class TransactionService {
|
|||
orderTransactionDto.productId,
|
||||
);
|
||||
|
||||
const productSubcategories = await this.productSubcategoriesService.findOne(
|
||||
product.sub_categories_id
|
||||
);
|
||||
|
||||
const supplier = await this.supplierService.findByCode(
|
||||
product.supplier.code,
|
||||
);
|
||||
|
@ -628,7 +634,7 @@ export class TransactionService {
|
|||
if (supplier.code == 'Hemat') {
|
||||
hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier);
|
||||
}
|
||||
|
||||
console.log('inicodesubcategory', productSubcategories.code)
|
||||
let hitSupplier = supplier.code == 'Hemat' ?
|
||||
await doTransaction(
|
||||
orderTransactionDto.productCode,
|
||||
|
@ -637,7 +643,9 @@ export class TransactionService {
|
|||
supplier,
|
||||
hitLoginHemat.data,
|
||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||
orderTransactionDto.bill_trx_id
|
||||
orderTransactionDto.bill_trx_id,
|
||||
productSubcategories.code_voca,
|
||||
product_price.price
|
||||
) : await doTransaction(
|
||||
orderTransactionDto.productCode,
|
||||
orderTransactionDto.destination,
|
||||
|
@ -645,7 +653,9 @@ export class TransactionService {
|
|||
supplier,
|
||||
"",
|
||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||
orderTransactionDto.bill_trx_id
|
||||
orderTransactionDto.bill_trx_id,
|
||||
productSubcategories.code_voca,
|
||||
product_price.price
|
||||
);
|
||||
|
||||
// let hitSupplier;
|
||||
|
@ -672,6 +682,16 @@ export class TransactionService {
|
|||
if (orderTransactionDto.bill_trx_id !== null) {
|
||||
hitSupplier.harga = product_price.price;
|
||||
}
|
||||
} else if (supplier.code == 'Vocagame') {
|
||||
const newHitSupplier = {
|
||||
status: hitSupplier.data.status,
|
||||
success: hitSupplier.data.status.includes('Success') || hitSupplier.data.status.includes('Processing') || hitSupplier.data.status.includes('Pending'),
|
||||
harga: hitSupplier.data.totalAmount,
|
||||
msg: hitSupplier.message,
|
||||
sn: hitSupplier.data.sn,
|
||||
};
|
||||
|
||||
hitSupplier = newHitSupplier;
|
||||
} else if (supplier.code == 'Hemat') {
|
||||
const newHitSupplier = {
|
||||
success: hitSupplier.success,
|
||||
|
@ -770,8 +790,9 @@ export class TransactionService {
|
|||
transactionData.partner_trx_id = orderTransactionDto.trx_id;
|
||||
transactionData.supplier_trx_id = trxId;
|
||||
transactionData.check_bill = orderTransactionDto.bill_trx_id;
|
||||
|
||||
console.log('statushitsupplier', hitSupplier.success)
|
||||
if (!hitSupplier.success) {
|
||||
console.log('masukstatusgagal', 'masuk')
|
||||
transactionData.balance_remaining = coaAccount.amount;
|
||||
transactionData.status = statusTransaction.FAILED;
|
||||
status = statusTransaction[transactionData.status];
|
||||
|
@ -784,8 +805,23 @@ export class TransactionService {
|
|||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
} else {
|
||||
console.log('masukstatuspending', 'masuk')
|
||||
transactionData.balance_remaining =
|
||||
coaAccount.amount - product_price.mark_up_price - costInventory;
|
||||
if (supplier.code == 'Vocagame') {
|
||||
|
||||
if (hitSupplier.status == 'Processing' || hitSupplier.status == 'Pending') {
|
||||
transactionData.status = statusTransaction.PENDING;
|
||||
status = statusTransaction[transactionData.status];
|
||||
} else {
|
||||
transactionData.seri_number = hitSupplier.sn;
|
||||
transactionData.status = statusTransaction.SUCCESS;
|
||||
status = statusTransaction[transactionData.status];
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if (
|
||||
hitSupplier.sn == null ||
|
||||
hitSupplier.sn == '' ||
|
||||
|
@ -798,6 +834,9 @@ export class TransactionService {
|
|||
transactionData.status = statusTransaction.SUCCESS;
|
||||
status = statusTransaction[transactionData.status];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await manager.insert(Transactions, transactionData);
|
||||
|
@ -860,6 +899,10 @@ export class TransactionService {
|
|||
orderTransactionDto.productId
|
||||
);
|
||||
|
||||
const productSubcategories = await this.productSubcategoriesService.findOne(
|
||||
product.sub_categories_id
|
||||
);
|
||||
|
||||
const supplier = await this.supplierService.findByCode(
|
||||
product.supplier.code,
|
||||
);
|
||||
|
@ -921,7 +964,9 @@ export class TransactionService {
|
|||
supplier,
|
||||
hitLoginHemat.data,
|
||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||
orderTransactionDto.bill_trx_id
|
||||
orderTransactionDto.bill_trx_id,
|
||||
productSubcategories.code_voca,
|
||||
product_price.price
|
||||
) : await doTransaction(
|
||||
orderTransactionDto.productCode,
|
||||
orderTransactionDto.destination,
|
||||
|
@ -929,7 +974,9 @@ export class TransactionService {
|
|||
supplier,
|
||||
"",
|
||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||
orderTransactionDto.bill_trx_id
|
||||
orderTransactionDto.bill_trx_id,
|
||||
productSubcategories.code_voca,
|
||||
product_price.price
|
||||
);
|
||||
|
||||
if (supplier.code != 'IRS') {
|
||||
|
@ -1045,6 +1092,10 @@ export class TransactionService {
|
|||
orderTransactionDto.productId
|
||||
);
|
||||
|
||||
const productSubcategories = await this.productSubcategoriesService.findOne(
|
||||
product.sub_categories_id
|
||||
);
|
||||
|
||||
const supplier = await this.supplierService.findByCode(
|
||||
product.supplier.code,
|
||||
);
|
||||
|
@ -1081,7 +1132,9 @@ export class TransactionService {
|
|||
supplier,
|
||||
hitLoginHemat.data,
|
||||
'INQUIRY',
|
||||
orderTransactionDto.bill_trx_id
|
||||
orderTransactionDto.bill_trx_id,
|
||||
productSubcategories.code_voca,
|
||||
product_price.price
|
||||
)
|
||||
} else if (supplier.code == 'Digiflazz') {
|
||||
hitSupplier = await doTransaction(
|
||||
|
@ -1091,7 +1144,9 @@ export class TransactionService {
|
|||
supplier,
|
||||
hitLoginHemat.data,
|
||||
'INQUIRY',
|
||||
orderTransactionDto.bill_trx_id
|
||||
orderTransactionDto.bill_trx_id,
|
||||
productSubcategories.code_voca,
|
||||
product_price.price
|
||||
)
|
||||
} else {
|
||||
hitSupplier = await doTransaction(
|
||||
|
@ -1101,7 +1156,9 @@ export class TransactionService {
|
|||
supplier,
|
||||
"",
|
||||
'INQUIRY',
|
||||
orderTransactionDto.bill_trx_id
|
||||
orderTransactionDto.bill_trx_id,
|
||||
productSubcategories.code_voca,
|
||||
product_price.price
|
||||
);
|
||||
}
|
||||
// const parsingResponse = hitSupplier.split(' ');
|
||||
|
@ -1590,6 +1647,10 @@ export class TransactionService {
|
|||
if (callback['sn']) {
|
||||
dataTransaction.seri_number = callback['sn'];
|
||||
}
|
||||
} else if (supplier.code == 'Vocagame') {
|
||||
if (callback['sn']) {
|
||||
dataTransaction.seri_number = callback['sn'];
|
||||
}
|
||||
} else {
|
||||
if (callback['sn']) {
|
||||
dataTransaction.seri_number = callback['sn'];
|
||||
|
|
Loading…
Reference in New Issue
Block a user