151 lines
4.4 KiB
TypeScript
151 lines
4.4 KiB
TypeScript
import axios from 'axios';
|
|
import cryptoMd5 from "crypto";
|
|
|
|
const irs_url = 'http://h2h.elangpixiu.com/api/h2h';
|
|
const irs_id = 'PT0005';
|
|
const irs_pin = '04JFGC';
|
|
const irs_user = 'D10BD0';
|
|
const irs_pass = '6251F3';
|
|
|
|
export const doTransaction = async (
|
|
productCode,
|
|
destination,
|
|
idtrx,
|
|
supplier,
|
|
authorization,
|
|
typePaid,
|
|
billTrxId,
|
|
) => {
|
|
try {
|
|
if (supplier.code == 'IRS') {
|
|
const res = await axios.get(
|
|
`${irs_url}?id=${irs_id}&pin=${irs_pin}&user=${irs_user}&pass=${irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`,
|
|
);
|
|
|
|
return res.data;
|
|
} else if (supplier.code == 'NIRS') {
|
|
const res = await axios.get(
|
|
`${supplier.url}?id=${supplier.irs_id}&pin=${supplier.irs_pin}&user=${supplier.irs_user}&pass=${supplier.irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`,
|
|
);
|
|
|
|
return res.data;
|
|
} else if (supplier.code == 'Digiflazz') {
|
|
if (typePaid == 'INQUIRY') {
|
|
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
|
const cryptoMd5 = require('crypto');
|
|
|
|
cryptoMd5.createHash('md5').update(md5HashDigiflazz).digest('hex');
|
|
|
|
const options = {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
};
|
|
const data = {
|
|
commands: 'inq-pasca',
|
|
username: supplier.irs_user,
|
|
customer_no: `${destination}`,
|
|
buyer_sku_code: `${productCode}`,
|
|
ref_id: `${idtrx}`,
|
|
sign: cryptoMd5,
|
|
testing: true,
|
|
};
|
|
const res = await axios.post(
|
|
`${supplier.url}/transaction`,
|
|
data,
|
|
options,
|
|
);
|
|
|
|
return res.data;
|
|
} else if (typePaid == 'PAYMENT') {
|
|
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
|
const cryptoMd5 = require('crypto');
|
|
|
|
cryptoMd5.createHash('md5').update(md5HashDigiflazz).digest('hex');
|
|
|
|
const options = {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
};
|
|
const data = {
|
|
commands: 'pay-pasca',
|
|
username: supplier.irs_user,
|
|
customer_no: `${destination}`,
|
|
buyer_sku_code: `${productCode}`,
|
|
ref_id: `${billTrxId}`,
|
|
sign: cryptoMd5,
|
|
testing: true,
|
|
};
|
|
const res = await axios.post(
|
|
`${supplier.url}/transaction`,
|
|
data,
|
|
options,
|
|
);
|
|
|
|
return res.data;
|
|
} else {
|
|
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
|
const cryptoMd5 = require('crypto');
|
|
|
|
cryptoMd5.createHash('md5').update(md5HashDigiflazz).digest('hex');
|
|
|
|
const options = {
|
|
headers: {'Content-Type': 'application/json'},
|
|
};
|
|
const data = {
|
|
username: supplier.irs_user,
|
|
customer_no: `${destination}`,
|
|
buyer_sku_code: `${productCode}`,
|
|
ref_id: `${idtrx}`,
|
|
sign: cryptoMd5,
|
|
testing: true,
|
|
};
|
|
const res = await axios.post(
|
|
`${supplier.url}/transaction`,
|
|
data,
|
|
options,
|
|
);
|
|
|
|
return res.data;
|
|
}
|
|
} else if (supplier.code == 'Hemat') {
|
|
if (authorization != '') {
|
|
console.log('initoken', authorization);
|
|
|
|
const options = {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${authorization}`,
|
|
},
|
|
};
|
|
const data = {
|
|
idtransaction: idtrx,
|
|
destination: `${destination}`,
|
|
code: `${productCode}`,
|
|
type: `${typePaid}`,
|
|
};
|
|
const res = await axios.post(
|
|
`${supplier.url}/v1/transaction/request`,
|
|
data,
|
|
options,
|
|
);
|
|
|
|
return res.data;
|
|
}
|
|
}
|
|
|
|
const res = await axios.get(
|
|
`${supplier.url}?memberID=${supplier.irs_id}&pin=${supplier.irs_pin}&password=${supplier.irs_pass}&product=${productCode}&dest=${destination}&counter=1&refID=${idtrx}`,
|
|
);
|
|
|
|
return res.data;
|
|
|
|
console.log('restranshemat', res);
|
|
} catch (err) {
|
|
console.log('errtranshemat', err);
|
|
|
|
if (err.includes('Maaf Saldo anda tidak mencukupi')) {
|
|
throw 'maaf saat ini transaksi sedang tidak bisa diproses, silahkan hubungi WND Solutions untuk bisa di proses kembali';
|
|
} else {
|
|
throw err;
|
|
}
|
|
}
|
|
};
|