Payment Gateway Order Kuota
by XshopTopup
12
Raw
/*
Code payment gateway Menggunakan https://apiorkut.my.id/
Dokumentasi cek https://xstbot.apiorkut.my.id/
Jika ingin menggunakan api payment gateway ini harus memiliki website seperti ini dikarenakan 1 website api payment gateway hanya untuk satu Apikey dari QRIS Order kuota
*/
case 'depo': case 'deposit': {
try {
const nomor = sender.replace("@s.whatsapp.net", "");
const userData = JSON.parse(fs.readFileSync('./db/users.json'));
const userProfile = userData.find((user) => user.nomor === nomor);
if (!userProfile) {
return m.reply(`Kamu belum terdaftar, silahkan ketik : *Daftar*\nuntuk bisa mengakses`);
}
const { role } = userProfile;
if (!text) return m.reply(`*DEPOSIT SALDO OTOMATIS*\n\nSilahkan gunakan dengan cara :\n${prefix + command} nominalnya\n\nContoh :\n${prefix + command} 10000\n\nMinimal deposit otomatis adalah Rp 10.000 dan maksimal Rp 499.000`);
const amount = args[0];
const minimalDepo = 10000;
const maximalDepo = 499000;
if (!amount || isNaN(parseInt(amount))) return m.reply('Deposit Harus Berupa Angka!');
if (parseInt(amount) < minimalDepo) return m.reply(`Minimal deposit saldo otomatis adalah Rp 10.000. Jika kamu ingin deposit dibawah itu silahkan ketik ${prefix}depomanual atau hubungi Admin`);
if (parseInt(amount) > maximalDepo) return m.reply(`Maksimal deposit saldo otomatis adalah Rp 10.000.000. Jika kamu ingin deposit diatas itu silahkan ketik ${prefix}depomanual atau hubungi Admin`);
const uniqueRefID = generateUniqueRefID();
try {
const qrisResponse = await axios.post(
'https://xstbot.apiorkut.my.id/api/deposit',
{
amount: parseInt(amount),
username: userProfile.name || "Deposit Bot User",
phone: nomor
},
{
headers: {
'Content-Type': 'application/json'
}
}
);
if (!qrisResponse.data || !qrisResponse.data.id) {
return m.reply("Gagal membuat QRIS: Silahkan hubungi admin");
}
const qrisData = qrisResponse.data;
const transactionId = qrisData.id;
const uniqueCode = qrisData.unique_code;
const totalAmount = qrisData.total;
const qrisImageUrl = qrisData.qris;
const expireTimestamp = qrisData.expireAt;
const expiryMinutes = Math.floor((expireTimestamp - Date.now()) / 60000);
let depositSaldoBot = `[ *Deposit Saldo Otomatis* ]\n\n`;
depositSaldoBot += `-> Jumlah Deposit: ${rupiah(parseInt(amount))}\n`;
depositSaldoBot += `-> Kode Unik: ${uniqueCode}\n`;
depositSaldoBot += `-> Total Bayar: ${rupiah(totalAmount)}\n`;
depositSaldoBot += `-> ID Transaksi: ${transactionId}\n\n`;
depositSaldoBot += `Silahkan Scan QR ini untuk melakukan pembayaran, berlaku selama ${expiryMinutes} menit.`;
const sentMessage = await xstbot.sendMessage(
m.chat,
{ image: { url: qrisImageUrl }, caption: depositSaldoBot },
{ quoted: m }
);
const startTime = Date.now();
const maxWaitTime = 10 * 60 * 1000;
let transactionStatus = "";
const checkPayment = async () => {
try {
while (true) {
await new Promise(resolve => setTimeout(resolve, 10000));
const elapsed = Date.now() - startTime;
if (elapsed >= maxWaitTime) {
await xstbot.sendMessage(m.chat, { text: "Pembayaran QRIS telah kedaluwarsa." }, { quoted: m });
return;
}
const statusResponse = await axios.get(
`https://xstbot.apiorkut.my.id/api/cekstatus/${transactionId}`
);
if (statusResponse.data.status === "expired") {
await xstbot.sendMessage(m.chat, { text: "Pembayaran QRIS telah kedaluwarsa." }, { quoted: m });
return;
}
if (statusResponse.data.status === "success") {
try {
const transactionData = statusResponse.data.transaction;
const pathUser = './db/users.json';
const target = nomor;
const amountToAdd = totalAmount;
let userData = [];
if (fs.existsSync(pathUser)) {
const rawData = fs.readFileSync(pathUser, 'utf8');
userData = JSON.parse(rawData);
}
const targetUserIndex = userData.findIndex((user) => user.nomor === target);
if (targetUserIndex !== -1) {
const sebelum = userData[targetUserIndex].saldo;
userData[targetUserIndex].saldo += amountToAdd;
const akhir = userData[targetUserIndex].saldo;
fs.writeFileSync(pathUser, JSON.stringify(userData, null, 2));
await xstbot.sendMessage(m.chat, {
text: `───〔 *Deposit Berhasil* 〕──\n\n*Nomor :* ${target}\n*Jumlah Deposit :* ${rupiah(parseInt(amount))}\n*Kode Unik :* ${uniqueCode}\n*Total Masuk :* ${rupiah(totalAmount)}\n*Saldo Sebelumnya :* ${formatSaldo(sebelum)}\n*Saldo Sekarang :* ${formatSaldo(akhir)}\n*Waktu :* ${hariini}, ${time1} WIB`
}, { quoted: m });
} else {
await xstbot.sendMessage(m.chat, {
text: `*Deposit Berhasil* tapi gagal mengupdate saldo. Silahkan hubungi admin dengan menyertakan ID Transaksi: ${transactionId}`
}, { quoted: m });
}
break;
} catch (error) {
console.error('Error updating user balance:', error);
await xstbot.sendMessage(m.chat, {
text: `*Deposit Berhasil* tapi gagal mengupdate saldo. Silahkan hubungi admin dengan menyertakan ID Transaksi: ${transactionId}`
}, { quoted: m });
break;
}
}
}
} catch (error) {
console.error('Payment check error:', error);
m.reply("Terjadi kesalahan saat memeriksa status pembayaran. Silakan hubungi admin jika pembayaran sudah dilakukan.");
}
};
checkPayment();
} catch (error) {
if (error.response && error.response.status === 409) {
m.reply('Kamu masih memiliki transaksi deposit aktif. Silakan selesaikan pembayaran sebelumnya atau tunggu hingga kedaluwarsa.');
} else if (error.response && error.response.status === 503) {
m.reply('Sistem deposit sedang sibuk. Silakan coba lagi nanti.');
} else {
m.reply('Terjadi kesalahan saat memproses permintaan deposit. Silakan coba lagi nanti.');
}
}
} catch (error) {
console.error('User verification error:', error);
m.reply('Terjadi kesalahan saat memverifikasi data pengguna. Silakan coba lagi nanti atau hubungi admin.');
}
break;
}