- added digiflazz supplier
This commit is contained in:
parent
04d2ed62ec
commit
823dbf1912
|
@ -1,4 +1,5 @@
|
|||
import axios from 'axios';
|
||||
import cryptoMd5 from "crypto";
|
||||
|
||||
const irs_url = 'http://h2h.elangpixiu.com/api/h2h';
|
||||
const irs_id = 'PT0005';
|
||||
|
@ -7,32 +8,112 @@ const irs_user = 'D10BD0';
|
|||
const irs_pass = '6251F3';
|
||||
|
||||
export const doTransaction = async (
|
||||
productCode,
|
||||
destination,
|
||||
idtrx,
|
||||
supplier,
|
||||
authorization,
|
||||
typePaid,
|
||||
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}`,
|
||||
`${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}`,
|
||||
`${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 == 'Hemat') {
|
||||
if (authorization != "") {
|
||||
console.log("initoken", authorization)
|
||||
} else if (supplier.code == 'Digiflazz') {
|
||||
if (typePaid == 'INQUIRY') {
|
||||
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',
|
||||
'Authorization': 'Bearer ' + authorization}
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
};
|
||||
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 = {
|
||||
idtransaction: idtrx,
|
||||
|
@ -40,25 +121,30 @@ export const doTransaction = async (
|
|||
code: `${productCode}`,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
console.log('restranshemat', res)
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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
|
||||
const trxId = Array(11)
|
||||
.fill(null)
|
||||
.map(() => {
|
||||
return Math.round(Math.random() * 16).toString(16);
|
||||
})
|
||||
.join('');
|
||||
let trxId;
|
||||
|
||||
trxId = Array(11)
|
||||
.fill(null)
|
||||
.map(() => {
|
||||
return Math.round(Math.random() * 16).toString(16);
|
||||
})
|
||||
.join('');
|
||||
|
||||
let hitLoginHemat;
|
||||
|
||||
|
@ -635,6 +637,7 @@ export class TransactionService {
|
|||
supplier,
|
||||
hitLoginHemat.data,
|
||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||
orderTransactionDto.bill_trx_id
|
||||
) : await doTransaction(
|
||||
orderTransactionDto.productCode,
|
||||
orderTransactionDto.destination,
|
||||
|
@ -642,6 +645,7 @@ export class TransactionService {
|
|||
supplier,
|
||||
"",
|
||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||
orderTransactionDto.bill_trx_id
|
||||
);
|
||||
|
||||
// let hitSupplier;
|
||||
|
@ -677,6 +681,29 @@ export class TransactionService {
|
|||
|
||||
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) {
|
||||
hitSupplier.harga = product_price.price;
|
||||
}
|
||||
|
@ -757,8 +784,18 @@ export class TransactionService {
|
|||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
} else {
|
||||
transactionData.status = statusTransaction.PENDING;
|
||||
status = statusTransaction[transactionData.status];
|
||||
if (
|
||||
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);
|
||||
|
@ -882,6 +919,7 @@ export class TransactionService {
|
|||
supplier,
|
||||
hitLoginHemat.data,
|
||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||
orderTransactionDto.bill_trx_id
|
||||
) : await doTransaction(
|
||||
orderTransactionDto.productCode,
|
||||
orderTransactionDto.destination,
|
||||
|
@ -889,6 +927,7 @@ export class TransactionService {
|
|||
supplier,
|
||||
"",
|
||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||
orderTransactionDto.bill_trx_id
|
||||
);
|
||||
|
||||
if (supplier.code != 'IRS') {
|
||||
|
@ -1030,21 +1069,39 @@ export class TransactionService {
|
|||
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.destination,
|
||||
trxId,
|
||||
supplier,
|
||||
hitLoginHemat.data,
|
||||
'INQUIRY'
|
||||
) : await doTransaction(
|
||||
`CEK${orderTransactionDto.productCode.slice(3)}`,
|
||||
'INQUIRY',
|
||||
orderTransactionDto.bill_trx_id
|
||||
)
|
||||
} 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,
|
||||
trxId,
|
||||
supplier,
|
||||
"",
|
||||
'INQUIRY'
|
||||
'INQUIRY',
|
||||
orderTransactionDto.bill_trx_id
|
||||
);
|
||||
}
|
||||
// const parsingResponse = hitSupplier.split(' ');
|
||||
|
||||
if (supplier.code == 'Hemat') {
|
||||
|
@ -1052,6 +1109,11 @@ export class TransactionService {
|
|||
success: hitSupplier.success == true,
|
||||
msg: hitSupplier.msg,
|
||||
};
|
||||
} else if (supplier.code == 'Digiflazz') {
|
||||
hitSupplier = {
|
||||
success: hitSupplier.status.includes('Sukses'),
|
||||
msg: hitSupplier.message,
|
||||
};
|
||||
} else {
|
||||
hitSupplier = {
|
||||
success: hitSupplier.includes('diproses') || hitSupplier.includes('dalam proses'),
|
||||
|
@ -1500,6 +1562,10 @@ export class TransactionService {
|
|||
} else {
|
||||
dataProductHistoryPrice.price = parseInt(callback['data']['additional']['harga']);
|
||||
}
|
||||
} else if (supplier.code == 'Digiflazz') {
|
||||
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