The following changes were made by the replace_file_content tool to: /root/aadharbot/gateways.js. If relevant, proactively run terminal commands to execute this code for the USER. Don't ask for permission. [diff_block_start] @@ -769,6 +769,58 @@ } else { expectedDate = formatDateIST(new Date()); } + } else if (isMuskmelon) { + console.log(`[GATEWAY] Muskmelon / Monepay detected (${gatewayHost}). Processing token...`); + const token = parsedUrl.searchParams.get('token'); + if (!token) { + throw new Error("Muskmelon token missing in checkout URL"); + } + + const infoRes = await fetch(`https://${gatewayHost}/api/payment/order/info/${token}`, { + headers: { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', + 'Referer': requestUrl + } + }); + + if (!infoRes.ok) throw new Error(`Muskmelon API returned HTTP ${infoRes.status}`); + const infoJson = await infoRes.json(); + console.log(`[GATEWAY] Muskmelon order info response:`, JSON.stringify(infoJson)); + + if (infoJson.status !== 200 || !infoJson.data) { + throw new Error(infoJson.message || "Failed to retrieve payment info from Muskmelon"); + } + + const d = infoJson.data; + orderId = d.apiTxnId || d.apiPaymentId || token; + + let upiUrl = null; + if (d.upiIntent) { + upiUrl = d.upiIntent.upi || d.upiIntent.phonepe || d.upiIntent.gpay || d.upiIntent.paytm; + } + if (!upiUrl && d.qrCode) { + if (d.qrCode.startsWith('upi://')) { + upiUrl = d.qrCode; + } else if (d.qrCode.startsWith('data:image')) { + const base64Data = d.qrCode.replace(/^data:image\/[a-z]+;base64,/, ""); + qrBuffer = Buffer.from(base64Data, 'base64'); + } + } + + if (!upiUrl && !qrBuffer) { + throw new Error("Muskmelon did not provide UPI URL or QR Code"); + } + + if (upiUrl && !qrBuffer) { + if (!upiUrl.startsWith('upi://pay?')) { + upiUrl = upiUrl.replace(/^(phonepe|gpay|paytmmp|tez):\/\/(upi\/)?(pay|cash_wallet)\?/, 'upi://pay?'); + } + const QRCode = require('qrcode'); + qrBuffer = await QRCode.toBuffer(upiUrl, { type: 'png', width: 400 }); + } + + expectedDate = formatDateIST(new Date()); + console.log(`[GATEWAY] Muskmelon resolved successfully. Order ID: ${orderId}, UPI: ${upiUrl}`); } else { // Standard flow (xspay, etc.) let orderIdVal = parsedUrl.searchParams.get('orderId') || parsedUrl.searchParams.get('order_id') || parsedUrl.searchParams.get('orderNo'); [diff_block_end] Please note that the above snippet only shows the MODIFIED lines from the last change. It shows up to 3 lines of unchanged lines before and after the modified lines. The actual file contents may have many more lines not shown.