@babuperumana/upipg
v1.0.2
Published
Drop-in UPI payment gateway and automated verification with interactive buttons support for WhatsApp bots (my-md-baileys, my-md-btns, Baileys)
Maintainers
Readme
@babuperumana/upipg — Drop-in UPI Payment Gateway for Node.js & WhatsApp Bots
@babuperumana/upipg is a powerful, drop-in automated UPI payment confirmation library for Node.js, tailored specifically for WhatsApp bots using my-md-baileys and my-md-btns (as well as standard Baileys / whatsapp-web.js). It uses BharatPe's merchant API with session credentials to verify payments in real-time without webhooks.
🌟 Features
- Interactive Payment Buttons (
my-md-btnsIntegration) — Built-in helper to automatically send clickable UPI app buttons, copy exact amount buttons, and order status buttons! - Direct Image Buffer Output — Generates styled PNG QR code cards directly as a Node.js
Buffer. - Micro-Amount Collision Avoidance — Automatically assigns unique fractional increments (e.g.,
₹500.00→₹500.03) so multiple customers can pay simultaneously without ambiguity. - Non-Blocking Background Verification — Polls BharatPe transaction servers every few seconds in the background.
- Event-Driven Architecture — Built on Node.js
EventEmitter. Simply listen forsuccess,expired, orcredentials_expiredevents. - No Webhooks Needed — Works on local PCs, VPS, AWS, Heroku, or Raspberry Pi without public IP addresses, domain names, or SSL certificates.
🚀 Quick Start
1. Installation
npm install @babuperumana/upipg my-md-baileys my-md-btns2. Basic Initialization
const { UpiPG } = require('@babuperumana/upipg');
const pg = new UpiPG({
upiId: "yourname@yesbankltd",
merchantName: "My Digital Store",
merchantId: "12345678",
apiToken: "<token from BharatPe DevTools>",
apiCookie: "<Cookie header from BharatPe DevTools>",
pollInterval: 5000, // 5 seconds
timeout: 300 // 5 minutes
});
// Listen for successful payment confirmation
pg.on('success', (session) => {
console.log(`✅ Payment confirmed! UTR: ${session.utr} | Payer: ${session.payerName}`);
});💬 Interactive WhatsApp Bot Example (my-md-baileys + my-md-btns)
const makeWASocket, { useMultiFileAuthState } = require('my-md-baileys');
const { UpiPG, sendInteractivePaymentRequest } = require('@babuperumana/upipg');
async function startBot() {
const { state, saveCreds } = await useMultiFileAuthState('auth_info');
const sock = makeWASocket({ auth: state });
sock.ev.on('creds.update', saveCreds);
const pg = new UpiPG({
upiId: "yourupi@bank",
merchantName: "My Digital Store",
merchantId: "12345678",
apiToken: "...",
apiCookie: "..."
});
// Automatically trigger next step when customer pays
pg.on('success', async (session) => {
const customerJid = session.metadata.jid;
await sock.sendMessage(customerJid, {
text: `✅ *Payment Verified!*\nOrder ID: \`${session.orderId}\`\nUTR: \`${session.utr}\`\n\n🎉 Activating your service now...`
});
// Trigger fulfillment here
});
sock.ev.on('messages.upsert', async ({ messages }) => {
const msg = messages[0];
if (!msg.message || msg.key.fromMe) return;
const sender = msg.key.remoteJid;
const text = (msg.message.conversation || '').toLowerCase();
if (text === 'buy product') {
// 1. Create session (assigns micro-amount like ₹500.03)
const session = await pg.createPayment({
amount: 500,
metadata: { jid: sender }
});
// 2. Send Interactive QR Card + Buttons (Copy Amount, Open App, Check Status)
await sendInteractivePaymentRequest(
sock,
sender,
session,
"yourupi@bank",
"My Digital Store",
{ quoted: msg }
);
}
});
}
startBot();🛠️ Publishing Updates to NPM
npm run build
npm publish --access publicLicense
MIT
