Kembali
[PG] integrasi pakasir.com
Potongan fitur WhatsApp bot integrasi payment gateway pakasir.com simple, mudah dipahami.
/**
* @project : Payment Gateway Paksir
* @author : Neo π¨βπ»
* @license : MIT / Personal
* @description: WhatsApp bot integrasi pg pakasir.com
* Website : www.neostore.biz.id
**/
case "pakasir": {
const PAKASIR_SLUG = "ISI_SLUG_PROJECT";
const PAKASIR_API_KEY = "ISI_API_KEY";
const amount = Number(text);
if (!amount || isNaN(amount)) {
return m.reply("Contoh:\n.pakasir 1000");
}
if (amount < 1000) {
return m.reply("Minimal pembayaran Rp1.000");
}
const kodeUnik = Math.floor(Math.random() * 100) + 1;
const nominal = amount + kodeUnik;
const orderId = `INV-${Date.now()}`;
const createRes = await fetch("https://app.pakasir.com/api/transactioncreate/qris", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
project: PAKASIR_SLUG,
order_id: orderId,
amount: nominal,
api_key: PAKASIR_API_KEY
})
});
const createJson = await createRes.json();
const payment = createJson?.payment;
if (!payment?.payment_number) {
return m.reply("Gagal membuat QRIS Pakasir.");
}
const QRCode = await import("qrcode");
const qrBuffer = await QRCode.default.toBuffer(payment.payment_number);
const qrisMsg = await conn.sendMessage(
m.chat,
{
image: qrBuffer,
caption: `δΉ PAYMENT PAKASIR
β’ Order ID : ${orderId}
β’ Nominal : Rp${nominal.toLocaleString("id-ID")}
β’ Metode : QRIS
β’ Status : Menunggu Pembayaran
β’ Expired : 5 Menit
Silakan scan QRIS di atas.
Status pembayaran dicek otomatis setiap 10 detik.`
},
{ quoted: m }
);
let selesai = false;
const hapusQris = async () => {
try {
await conn.sendMessage(m.chat, {
delete: qrisMsg.key
});
} catch {}
};
const interval = setInterval(async () => {
try {
const detailUrl =
`https://app.pakasir.com/api/transactiondetail` +
`?project=${encodeURIComponent(PAKASIR_SLUG)}` +
`&amount=${nominal}` +
`&order_id=${encodeURIComponent(orderId)}` +
`&api_key=${encodeURIComponent(PAKASIR_API_KEY)}`;
const detailRes = await fetch(detailUrl);
const detailJson = await detailRes.json();
const status = detailJson?.transaction?.status?.toLowerCase();
if (status === "completed") {
selesai = true;
clearInterval(interval);
clearTimeout(timeout);
await hapusQris();
return conn.sendMessage(
m.chat,
{
text: `β
PAYMENT BERHASIL
β’ Order ID : ${orderId}
β’ Nominal : Rp${nominal.toLocaleString("id-ID")}
β’ Status : COMPLETED`
},
{ quoted: m }
);
}
} catch (err) {
console.log("Pakasir check error:", err.message);
}
}, 10000);
const timeout = setTimeout(async () => {
if (selesai) return;
selesai = true;
clearInterval(interval);
await hapusQris();
return conn.sendMessage(
m.chat,
{
text: `β° PAYMENT EXPIRED
β’ Order ID : ${orderId}
β’ Nominal : Rp${nominal.toLocaleString("id-ID")}
β’ Status : EXPIRED
Silakan buat pembayaran baru.`
},
{ quoted: m }
);
}, 5 * 60 * 1000);
}
break;