Merge branch 'development' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into devops-staging
This commit is contained in:
commit
fba39ca42d
|
@ -1,5 +1,6 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import {HttpException, HttpStatus, NotFoundException} from "@nestjs/common";
|
import {HttpException, HttpStatus, NotFoundException} from "@nestjs/common";
|
||||||
|
import {createHmac} from "crypto";
|
||||||
|
|
||||||
const irs_url = 'http://h2h.elangpixiu.com/api/h2h';
|
const irs_url = 'http://h2h.elangpixiu.com/api/h2h';
|
||||||
const irs_id = 'PT0005';
|
const irs_id = 'PT0005';
|
||||||
|
@ -15,6 +16,8 @@ export const doTransaction = async (
|
||||||
authorization,
|
authorization,
|
||||||
typePaid,
|
typePaid,
|
||||||
billTrxId,
|
billTrxId,
|
||||||
|
productVocaSubCategoryId,
|
||||||
|
productPrice
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
if (supplier.code == 'IRS') {
|
if (supplier.code == 'IRS') {
|
||||||
|
@ -29,6 +32,62 @@ export const doTransaction = async (
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
|
} else if (supplier.code == 'Vocagame') {
|
||||||
|
const merchantId = supplier.irs_user;
|
||||||
|
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'},
|
||||||
|
};
|
||||||
|
|
||||||
|
const mergedDestination = destination;
|
||||||
|
const regex = /\(([^)]+)\)/;
|
||||||
|
const match = regex.exec(mergedDestination);
|
||||||
|
|
||||||
|
let productDestination = ""
|
||||||
|
let productRegion = ""
|
||||||
|
if (match) {
|
||||||
|
productDestination = match[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://ppob-backend.k3s.bangun-kreatif.com/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;
|
||||||
|
|
||||||
|
if (responseVoca != null) {
|
||||||
|
const resDetail = await axios.get(
|
||||||
|
`${supplier.url}/v1/core/transaction/${responseVoca.invoiceId}/detail?signature=${signature}`,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
|
||||||
|
return resDetail
|
||||||
|
}
|
||||||
} else if (supplier.code == 'Digiflazz') {
|
} else if (supplier.code == 'Digiflazz') {
|
||||||
if (typePaid == 'INQUIRY') {
|
if (typePaid == 'INQUIRY') {
|
||||||
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
||||||
|
|
|
@ -16,6 +16,11 @@ export class ProductSubCategories extends BaseModel {
|
||||||
})
|
})
|
||||||
code: string;
|
code: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
code_voca: string;
|
||||||
|
|
||||||
@ManyToOne(() => ProductCategories, (categories) => categories.sub_categories)
|
@ManyToOne(() => ProductCategories, (categories) => categories.sub_categories)
|
||||||
category: ProductCategories;
|
category: ProductCategories;
|
||||||
|
|
||||||
|
|
|
@ -174,4 +174,24 @@ 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
|
||||||
|
await this.transactionService.checkCallbackOrderFailed(
|
||||||
|
response['reference'],
|
||||||
|
response,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
//TODO: UPDATE BERHASIL
|
||||||
|
await this.transactionService.checkCallbackOrderSuccess(
|
||||||
|
response['reference'],
|
||||||
|
response,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,16 +90,16 @@ export class TransactionController {
|
||||||
@Body() orderTransactionDto: OrderTransactionDto,
|
@Body() orderTransactionDto: OrderTransactionDto,
|
||||||
@Request() req,
|
@Request() req,
|
||||||
) {
|
) {
|
||||||
if (req.get('host').includes('ppob-backend.k3s.bangun-kreatif.com')) {
|
// if (req.get('host').includes('ppob-backend.k3s.bangun-kreatif.com')) {
|
||||||
return {
|
// return {
|
||||||
data: await this.transactionService.orderTransaction(
|
// data: await this.transactionService.orderTransaction(
|
||||||
orderTransactionDto,
|
// orderTransactionDto,
|
||||||
req.user,
|
// req.user,
|
||||||
),
|
// ),
|
||||||
statusCode: HttpStatus.CREATED,
|
// statusCode: HttpStatus.CREATED,
|
||||||
message: 'success',
|
// message: 'success',
|
||||||
};
|
// };
|
||||||
} else {
|
// } else {
|
||||||
return {
|
return {
|
||||||
data: await this.transactionService.orderTransactionProd(
|
data: await this.transactionService.orderTransactionProd(
|
||||||
orderTransactionDto,
|
orderTransactionDto,
|
||||||
|
@ -108,7 +108,7 @@ export class TransactionController {
|
||||||
statusCode: HttpStatus.CREATED,
|
statusCode: HttpStatus.CREATED,
|
||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('order-bill-prod')
|
@Post('order-bill-prod')
|
||||||
|
|
|
@ -637,7 +637,9 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
hitLoginHemat.data,
|
hitLoginHemat.data,
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
orderTransactionDto.bill_trx_id
|
orderTransactionDto.bill_trx_id,
|
||||||
|
product.sub_categories.code_voca,
|
||||||
|
product_price.price
|
||||||
) : await doTransaction(
|
) : await doTransaction(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
|
@ -645,7 +647,9 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
"",
|
"",
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
orderTransactionDto.bill_trx_id
|
orderTransactionDto.bill_trx_id,
|
||||||
|
product.sub_categories.code_voca,
|
||||||
|
product_price.price
|
||||||
);
|
);
|
||||||
|
|
||||||
// let hitSupplier;
|
// let hitSupplier;
|
||||||
|
@ -672,6 +676,16 @@ export class TransactionService {
|
||||||
if (orderTransactionDto.bill_trx_id !== null) {
|
if (orderTransactionDto.bill_trx_id !== null) {
|
||||||
hitSupplier.harga = product_price.price;
|
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'),
|
||||||
|
harga: hitSupplier.data.totalAmount,
|
||||||
|
msg: hitSupplier.message,
|
||||||
|
sn: hitSupplier.data.sn,
|
||||||
|
};
|
||||||
|
|
||||||
|
hitSupplier = newHitSupplier;
|
||||||
} else if (supplier.code == 'Hemat') {
|
} else if (supplier.code == 'Hemat') {
|
||||||
const newHitSupplier = {
|
const newHitSupplier = {
|
||||||
success: hitSupplier.success,
|
success: hitSupplier.success,
|
||||||
|
@ -786,6 +800,20 @@ export class TransactionService {
|
||||||
} else {
|
} else {
|
||||||
transactionData.balance_remaining =
|
transactionData.balance_remaining =
|
||||||
coaAccount.amount - product_price.mark_up_price - costInventory;
|
coaAccount.amount - product_price.mark_up_price - costInventory;
|
||||||
|
if (supplier.code == 'Vocagame') {
|
||||||
|
|
||||||
|
if (hitSupplier.status == 'Processing') {
|
||||||
|
transactionData.status = statusTransaction.PENDING;
|
||||||
|
status = statusTransaction[transactionData.status];
|
||||||
|
} else {
|
||||||
|
transactionData.seri_number = hitSupplier.sn;
|
||||||
|
transactionData.status = statusTransaction.SUCCESS;
|
||||||
|
status = statusTransaction[transactionData.status];
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
hitSupplier.sn == null ||
|
hitSupplier.sn == null ||
|
||||||
hitSupplier.sn == '' ||
|
hitSupplier.sn == '' ||
|
||||||
|
@ -798,6 +826,9 @@ export class TransactionService {
|
||||||
transactionData.status = statusTransaction.SUCCESS;
|
transactionData.status = statusTransaction.SUCCESS;
|
||||||
status = statusTransaction[transactionData.status];
|
status = statusTransaction[transactionData.status];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await manager.insert(Transactions, transactionData);
|
await manager.insert(Transactions, transactionData);
|
||||||
|
@ -921,7 +952,9 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
hitLoginHemat.data,
|
hitLoginHemat.data,
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
orderTransactionDto.bill_trx_id
|
orderTransactionDto.bill_trx_id,
|
||||||
|
product.sub_categories.code_voca,
|
||||||
|
product_price.price
|
||||||
) : await doTransaction(
|
) : await doTransaction(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
|
@ -929,7 +962,9 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
"",
|
"",
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
orderTransactionDto.bill_trx_id
|
orderTransactionDto.bill_trx_id,
|
||||||
|
product.sub_categories.code_voca,
|
||||||
|
product_price.price
|
||||||
);
|
);
|
||||||
|
|
||||||
if (supplier.code != 'IRS') {
|
if (supplier.code != 'IRS') {
|
||||||
|
@ -1081,7 +1116,9 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
hitLoginHemat.data,
|
hitLoginHemat.data,
|
||||||
'INQUIRY',
|
'INQUIRY',
|
||||||
orderTransactionDto.bill_trx_id
|
orderTransactionDto.bill_trx_id,
|
||||||
|
product.sub_categories.code_voca,
|
||||||
|
product_price.price
|
||||||
)
|
)
|
||||||
} else if (supplier.code == 'Digiflazz') {
|
} else if (supplier.code == 'Digiflazz') {
|
||||||
hitSupplier = await doTransaction(
|
hitSupplier = await doTransaction(
|
||||||
|
@ -1091,7 +1128,9 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
hitLoginHemat.data,
|
hitLoginHemat.data,
|
||||||
'INQUIRY',
|
'INQUIRY',
|
||||||
orderTransactionDto.bill_trx_id
|
orderTransactionDto.bill_trx_id,
|
||||||
|
product.sub_categories.code_voca,
|
||||||
|
product_price.price
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
hitSupplier = await doTransaction(
|
hitSupplier = await doTransaction(
|
||||||
|
@ -1101,7 +1140,9 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
"",
|
"",
|
||||||
'INQUIRY',
|
'INQUIRY',
|
||||||
orderTransactionDto.bill_trx_id
|
orderTransactionDto.bill_trx_id,
|
||||||
|
product.sub_categories.code_voca,
|
||||||
|
product_price.price
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// const parsingResponse = hitSupplier.split(' ');
|
// const parsingResponse = hitSupplier.split(' ');
|
||||||
|
@ -1590,6 +1631,10 @@ export class TransactionService {
|
||||||
if (callback['sn']) {
|
if (callback['sn']) {
|
||||||
dataTransaction.seri_number = callback['sn'];
|
dataTransaction.seri_number = callback['sn'];
|
||||||
}
|
}
|
||||||
|
} else if (supplier.code == 'Vocagame') {
|
||||||
|
if (callback['sn']) {
|
||||||
|
dataTransaction.seri_number = callback['sn'];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (callback['sn']) {
|
if (callback['sn']) {
|
||||||
dataTransaction.seri_number = callback['sn'];
|
dataTransaction.seri_number = callback['sn'];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user