- integrating vocagame supplier
This commit is contained in:
@@ -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,62 @@ export const doTransaction = async (
|
||||
);
|
||||
|
||||
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') {
|
||||
if (typePaid == 'INQUIRY') {
|
||||
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
||||
|
||||
Reference in New Issue
Block a user