- added digiflazz supplier
This commit is contained in:
parent
04d2ed62ec
commit
823dbf1912
|
@ -1,4 +1,5 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import cryptoMd5 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';
|
||||||
|
@ -7,32 +8,112 @@ const irs_user = 'D10BD0';
|
||||||
const irs_pass = '6251F3';
|
const irs_pass = '6251F3';
|
||||||
|
|
||||||
export const doTransaction = async (
|
export const doTransaction = async (
|
||||||
productCode,
|
productCode,
|
||||||
destination,
|
destination,
|
||||||
idtrx,
|
idtrx,
|
||||||
supplier,
|
supplier,
|
||||||
authorization,
|
authorization,
|
||||||
typePaid,
|
typePaid,
|
||||||
|
billTrxId,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
if (supplier.code == 'IRS') {
|
if (supplier.code == 'IRS') {
|
||||||
const res = await axios.get(
|
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}`,
|
`${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;
|
return res.data;
|
||||||
} else if (supplier.code == 'NIRS') {
|
} else if (supplier.code == 'NIRS') {
|
||||||
const res = await axios.get(
|
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}`,
|
`${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;
|
return res.data;
|
||||||
} else if (supplier.code == 'Hemat') {
|
} else if (supplier.code == 'Digiflazz') {
|
||||||
if (authorization != "") {
|
if (typePaid == 'INQUIRY') {
|
||||||
console.log("initoken", authorization)
|
const md5HashDigiflazz = `${irs_user}${irs_pass}${idtrx}`;
|
||||||
|
const cryptoMd5 = require('crypto');
|
||||||
|
|
||||||
|
cryptoMd5.createHash('md5').update(md5HashDigiflazz).digest('hex');
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
headers: {'Content-Type': 'application/json',
|
headers: { 'Content-Type': 'application/json' },
|
||||||
'Authorization': 'Bearer ' + authorization}
|
};
|
||||||
|
const data = {
|
||||||
|
commands: 'inq-pasca',
|
||||||
|
username: irs_user,
|
||||||
|
customer_no: `${destination}`,
|
||||||
|
buyer_sku_code: `${productCode}`,
|
||||||
|
ref_id: `${idtrx}`,
|
||||||
|
sign: cryptoMd5,
|
||||||
|
testing: true,
|
||||||
|
};
|
||||||
|
const res = await axios.post(
|
||||||
|
`${supplier.url}/v1/transaction`,
|
||||||
|
data,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
} else if (typePaid == 'PAYMENT') {
|
||||||
|
const md5HashDigiflazz = `${irs_user}${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: irs_user,
|
||||||
|
customer_no: `${destination}`,
|
||||||
|
buyer_sku_code: `${productCode}`,
|
||||||
|
ref_id: `${billTrxId}`,
|
||||||
|
sign: cryptoMd5,
|
||||||
|
testing: true,
|
||||||
|
};
|
||||||
|
const res = await axios.post(
|
||||||
|
`${supplier.url}/v1/transaction`,
|
||||||
|
data,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
} else {
|
||||||
|
const md5HashDigiflazz = `${irs_user}${irs_pass}${idtrx}`;
|
||||||
|
const cryptoMd5 = require('crypto');
|
||||||
|
|
||||||
|
cryptoMd5.createHash('md5').update(md5HashDigiflazz).digest('hex');
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
};
|
||||||
|
const data = {
|
||||||
|
username: irs_user,
|
||||||
|
customer_no: `${destination}`,
|
||||||
|
buyer_sku_code: `${productCode}`,
|
||||||
|
ref_id: `${idtrx}`,
|
||||||
|
sign: cryptoMd5,
|
||||||
|
testing: true,
|
||||||
|
};
|
||||||
|
const res = await axios.post(
|
||||||
|
`${supplier.url}/v1/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 = {
|
const data = {
|
||||||
idtransaction: idtrx,
|
idtransaction: idtrx,
|
||||||
|
@ -40,25 +121,30 @@ export const doTransaction = async (
|
||||||
code: `${productCode}`,
|
code: `${productCode}`,
|
||||||
type: `${typePaid}`,
|
type: `${typePaid}`,
|
||||||
};
|
};
|
||||||
const res = await axios.post(`${supplier.url}/v1/transaction/request`, data, options);
|
const res = await axios.post(
|
||||||
|
`${supplier.url}/v1/transaction/request`,
|
||||||
|
data,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await axios.get(
|
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}`,
|
`${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;
|
return res.data;
|
||||||
|
|
||||||
console.log('restranshemat', res)
|
console.log('restranshemat', res);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('errtranshemat', err);
|
console.log('errtranshemat', err);
|
||||||
|
|
||||||
if (err.includes('Maaf Saldo anda tidak mencukupi')) {
|
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';
|
throw 'maaf saat ini transaksi sedang tidak bisa diproses, silahkan hubungi WND Solutions untuk bisa di proses kembali';
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -152,4 +152,25 @@ export class PpobCallbackController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public()
|
||||||
|
@Post('/digiflazz')
|
||||||
|
async getDigiflazz(@Req() request: FastifyRequest) {
|
||||||
|
const response = request.body;
|
||||||
|
console.log('responsehemat', response);
|
||||||
|
console.log('responsehemat2', request.body);
|
||||||
|
if (response['msg'] != 'Transaksi Sukses') {
|
||||||
|
//TODO: UPDATE GAGAL
|
||||||
|
await this.transactionService.checkCallbackOrderFailed(
|
||||||
|
response['data']['ref_id'],
|
||||||
|
response['data'],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
//TODO: UPDATE BERHASIL
|
||||||
|
await this.transactionService.checkCallbackOrderSuccess(
|
||||||
|
response['data']['ref_id'],
|
||||||
|
response['data'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -614,12 +614,14 @@ export class TransactionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
//HIT API SUPPLIER
|
//HIT API SUPPLIER
|
||||||
const trxId = Array(11)
|
let trxId;
|
||||||
.fill(null)
|
|
||||||
.map(() => {
|
trxId = Array(11)
|
||||||
return Math.round(Math.random() * 16).toString(16);
|
.fill(null)
|
||||||
})
|
.map(() => {
|
||||||
.join('');
|
return Math.round(Math.random() * 16).toString(16);
|
||||||
|
})
|
||||||
|
.join('');
|
||||||
|
|
||||||
let hitLoginHemat;
|
let hitLoginHemat;
|
||||||
|
|
||||||
|
@ -635,6 +637,7 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
hitLoginHemat.data,
|
hitLoginHemat.data,
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
|
orderTransactionDto.bill_trx_id
|
||||||
) : await doTransaction(
|
) : await doTransaction(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
|
@ -642,6 +645,7 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
"",
|
"",
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
|
orderTransactionDto.bill_trx_id
|
||||||
);
|
);
|
||||||
|
|
||||||
// let hitSupplier;
|
// let hitSupplier;
|
||||||
|
@ -677,6 +681,29 @@ export class TransactionService {
|
||||||
|
|
||||||
hitSupplier = newHitSupplier;
|
hitSupplier = newHitSupplier;
|
||||||
|
|
||||||
|
if (orderTransactionDto.bill_trx_id !== null) {
|
||||||
|
hitSupplier.harga = product_price.price;
|
||||||
|
}
|
||||||
|
} else if (supplier.code == 'Digiflazz') {
|
||||||
|
let newHitSupplier;
|
||||||
|
|
||||||
|
if (product.type == 'prepaid') {
|
||||||
|
newHitSupplier= {
|
||||||
|
success: hitSupplier.status.includes('Pending') || hitSupplier.status.includes('Sukses'),
|
||||||
|
harga: hitSupplier.price,
|
||||||
|
msg: hitSupplier.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
newHitSupplier= {
|
||||||
|
success: hitSupplier.status.includes('Pending') || hitSupplier.status.includes('Sukses'),
|
||||||
|
harga: hitSupplier.price,
|
||||||
|
msg: hitSupplier.message,
|
||||||
|
sn: hitSupplier.sn,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
hitSupplier = newHitSupplier;
|
||||||
|
|
||||||
if (orderTransactionDto.bill_trx_id !== null) {
|
if (orderTransactionDto.bill_trx_id !== null) {
|
||||||
hitSupplier.harga = product_price.price;
|
hitSupplier.harga = product_price.price;
|
||||||
}
|
}
|
||||||
|
@ -757,8 +784,18 @@ export class TransactionService {
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
transactionData.status = statusTransaction.PENDING;
|
if (
|
||||||
status = statusTransaction[transactionData.status];
|
hitSupplier.sn != null ||
|
||||||
|
hitSupplier.sn != '' ||
|
||||||
|
hitSupplier.sn != undefined
|
||||||
|
) {
|
||||||
|
transactionData.seri_number = hitSupplier.sn;
|
||||||
|
transactionData.status = statusTransaction.SUCCESS;
|
||||||
|
status = statusTransaction[transactionData.status];
|
||||||
|
} else {
|
||||||
|
transactionData.status = statusTransaction.PENDING;
|
||||||
|
status = statusTransaction[transactionData.status];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await manager.insert(Transactions, transactionData);
|
await manager.insert(Transactions, transactionData);
|
||||||
|
@ -882,6 +919,7 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
hitLoginHemat.data,
|
hitLoginHemat.data,
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
|
orderTransactionDto.bill_trx_id
|
||||||
) : await doTransaction(
|
) : await doTransaction(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
|
@ -889,6 +927,7 @@ export class TransactionService {
|
||||||
supplier,
|
supplier,
|
||||||
"",
|
"",
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
|
orderTransactionDto.bill_trx_id
|
||||||
);
|
);
|
||||||
|
|
||||||
if (supplier.code != 'IRS') {
|
if (supplier.code != 'IRS') {
|
||||||
|
@ -1030,21 +1069,39 @@ export class TransactionService {
|
||||||
hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier);
|
hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hitSupplier = supplier.code == 'Hemat' ? await doTransaction(
|
let hitSupplier;
|
||||||
|
|
||||||
|
if (supplier.code == 'Hemat') {
|
||||||
|
hitSupplier = await doTransaction(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
trxId,
|
trxId,
|
||||||
supplier,
|
supplier,
|
||||||
hitLoginHemat.data,
|
hitLoginHemat.data,
|
||||||
'INQUIRY'
|
'INQUIRY',
|
||||||
) : await doTransaction(
|
orderTransactionDto.bill_trx_id
|
||||||
`CEK${orderTransactionDto.productCode.slice(3)}`,
|
)
|
||||||
|
} else if (supplier.code == 'Digiflazz') {
|
||||||
|
hitSupplier = await doTransaction(
|
||||||
|
orderTransactionDto.productCode,
|
||||||
|
orderTransactionDto.destination,
|
||||||
|
trxId,
|
||||||
|
supplier,
|
||||||
|
hitLoginHemat.data,
|
||||||
|
'INQUIRY',
|
||||||
|
orderTransactionDto.bill_trx_id
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
await doTransaction(
|
||||||
|
hitSupplier= `CEK${orderTransactionDto.productCode.slice(3)}`,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
trxId,
|
trxId,
|
||||||
supplier,
|
supplier,
|
||||||
"",
|
"",
|
||||||
'INQUIRY'
|
'INQUIRY',
|
||||||
|
orderTransactionDto.bill_trx_id
|
||||||
);
|
);
|
||||||
|
}
|
||||||
// const parsingResponse = hitSupplier.split(' ');
|
// const parsingResponse = hitSupplier.split(' ');
|
||||||
|
|
||||||
if (supplier.code == 'Hemat') {
|
if (supplier.code == 'Hemat') {
|
||||||
|
@ -1052,6 +1109,11 @@ export class TransactionService {
|
||||||
success: hitSupplier.success == true,
|
success: hitSupplier.success == true,
|
||||||
msg: hitSupplier.msg,
|
msg: hitSupplier.msg,
|
||||||
};
|
};
|
||||||
|
} else if (supplier.code == 'Digiflazz') {
|
||||||
|
hitSupplier = {
|
||||||
|
success: hitSupplier.status.includes('Sukses'),
|
||||||
|
msg: hitSupplier.message,
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
hitSupplier = {
|
hitSupplier = {
|
||||||
success: hitSupplier.includes('diproses') || hitSupplier.includes('dalam proses'),
|
success: hitSupplier.includes('diproses') || hitSupplier.includes('dalam proses'),
|
||||||
|
@ -1500,6 +1562,10 @@ export class TransactionService {
|
||||||
} else {
|
} else {
|
||||||
dataProductHistoryPrice.price = parseInt(callback['data']['additional']['harga']);
|
dataProductHistoryPrice.price = parseInt(callback['data']['additional']['harga']);
|
||||||
}
|
}
|
||||||
|
} else if (supplier.code == 'Digiflazz') {
|
||||||
|
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