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] @@ -592,11 +592,62 @@ } else { expectedDate = formatDateIST(new Date()); } + } else if (isXmdhPay) { + console.log(`[GATEWAY] XmdhPay detected (${gatewayHost}). Fetching checkout page...`); + orderId = parsedUrl.searchParams.get('orderNo') || parsedUrl.searchParams.get('orderId') || parsedUrl.searchParams.get('param'); + + const htmlRes = await fetch(requestUrl, { + method: 'GET', + headers: { + 'Origin': `https://${gatewayHost}`, + 'Referer': `https://${gatewayHost}/`, + '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' + } + }); + + if (!htmlRes.ok) throw new Error(`XmdhPay checkout page returned HTTP ${htmlRes.status}`); + const html = await htmlRes.text(); + + if (!orderId) { + const orderMatch = html.match(/class=["']no["']>([^<]+) m[1]); + const chosen = matches.find(u => u.includes('phonepe') || u.includes('gpay')) || matches[0]; + + if (!chosen) { + throw new Error("Failed to extract payment link from XmdhPay checkout page"); + } + + let rawUrl = chosen.replace(/&/g, '&'); + let upiUrl = rawUrl.replace(/^(phonepe|gpay|paytmmp):\/\/(upi\/)?(pay|cash_wallet)\?/, 'upi://pay?'); + if (!upiUrl.includes('am=')) { + upiUrl += `&am=${amount}`; + } + + console.log(`[GATEWAY] XmdhPay resolved UPI: ${upiUrl}, Order ID: ${orderId}`); + const QRCode = require('qrcode'); + qrBuffer = await QRCode.toBuffer(upiUrl, { type: 'png', width: 400 }); + + if (orderId && orderId.startsWith('PI')) { + const match = orderId.match(/^PI(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/); + if (match) { + const [_, yyyy, mm, dd, hh, min, ss] = match; + const dt = new Date(Date.UTC(Number(yyyy), Number(mm) - 1, Number(dd), Number(hh) - 8, Number(min), Number(ss))); + expectedDate = formatDateIST(dt); + } else { + expectedDate = formatDateIST(new Date()); + } + } else { + expectedDate = formatDateIST(new Date()); + } } else { // Standard flow (xspay, etc.) - let orderIdVal = parsedUrl.searchParams.get('orderId') || parsedUrl.searchParams.get('order_id'); - if (!orderIdVal && parsedUrl.hash) { - const hashMatch = parsedUrl.hash.match(/[?&]orderId=([^&]+)/i) || parsedUrl.hash.match(/[?&]order_id=([^&]+)/i); + let orderIdVal = parsedUrl.searchParams.get('orderId') || parsedUrl.searchParams.get('order_id') || parsedUrl.searchParams.get('orderNo'); + if (!orderIdVal && parsedUrl.hash) { + const hashMatch = parsedUrl.hash.match(/[?&]orderId=([^&]+)/i) || parsedUrl.hash.match(/[?&]order_id=([^&]+)/i) || parsedUrl.hash.match(/[?&]orderNo=([^&]+)/i); if (hashMatch) { orderIdVal = hashMatch[1]; } @@ -603,36 +603,66 @@ orderId = orderIdVal; console.log(`[GATEWAY] Standard gateway detected. Order ID: ${orderId}`); - if (gatewayHost.startsWith('pay.') && (gatewayHost.includes('xspay') || gatewayHost.includes('55ace') || gatewayHost.includes('vip') || gatewayHost.includes('cc'))) { - gatewayApiUrl = `https://${gatewayHost.replace('pay.', 'payapi.')}`; - } else if (gatewayHost.startsWith('cashier.')) { - gatewayApiUrl = `https://${gatewayHost.replace('cashier.', 'api.')}`; - } - - const payRes = await fetch(`${gatewayApiUrl}/payment?orderId=${orderId}&deviceType=1`, { - method: 'GET', - headers: { - 'Refdomain': 'ind.55ace.com', - 'Origin': `https://${gatewayHost}`, - 'Referer': `https://${gatewayHost}/`, - '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' - } - }); - - if (!payRes.ok) throw new Error(`Pay API returned HTTP ${payRes.status}`); - const payJson = await payRes.json(); - - if (payJson.code !== 0 || !payJson.imgData) { - throw new Error(payJson.msg || "Failed to retrieve QR image data"); - } - - const base64Data = payJson.imgData.replace(/^data:image\/png;base64,/, ""); - qrBuffer = Buffer.from(base64Data, 'base64'); - - const match = orderId.match(/^UM(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/); - if (match) { - const [_, yy, mm, dd, hh, min, ss] = match; - expectedDate = `20${yy}-${mm}-${dd} ${hh}:${min}:${ss}`; + // Pre-check if requestUrl is an HTML checkout page with embedded UPI / data-url + let htmlHandled = false; + try { + const checkRes = await fetch(requestUrl, { + method: 'GET', + 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' + } + }); + if (checkRes.ok) { + const pageHtml = await checkRes.text(); + const matches = [...pageHtml.matchAll(/data-url=["']([^"']+)["']/gi)].map(m => m[1]); + const chosen = matches.find(u => u.includes('phonepe') || u.includes('gpay')) || matches[0]; + if (chosen) { + let rawUrl = chosen.replace(/&/g, '&'); + let upiUrl = rawUrl.replace(/^(phonepe|gpay|paytmmp):\/\/(upi\/)?(pay|cash_wallet)\?/, 'upi://pay?'); + if (!upiUrl.includes('am=')) upiUrl += `&am=${amount}`; + const QRCode = require('qrcode'); + qrBuffer = await QRCode.toBuffer(upiUrl, { type: 'png', width: 400 }); + expectedDate = formatDateIST(new Date()); + console.log(`[GATEWAY] Fallback resolved UPI from HTML: ${upiUrl}`); + htmlHandled = true; + } + } + } catch (checkErr) { + console.warn(`[GATEWAY] Fallback HTML pre-check note:`, checkErr.message); + } + + if (!htmlHandled) { + if (gatewayHost.startsWith('pay.') && (gatewayHost.includes('xspay') || gatewayHost.includes('55ace') || gatewayHost.includes('vip') || gatewayHost.includes('cc'))) { + gatewayApiUrl = `https://${gatewayHost.replace('pay.', 'payapi.')}`; + } else if (gatewayHost.startsWith('cashier.')) { + gatewayApiUrl = `https://${gatewayHost.replace('cashier.', 'api.')}`; + } + + const payRes = await fetch(`${gatewayApiUrl}/payment?orderId=${orderId}&deviceType=1`, { + method: 'GET', + headers: { + 'Refdomain': 'ind.55ace.com', + 'Origin': `https://${gatewayHost}`, + 'Referer': `https://${gatewayHost}/`, + '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' + } + }); + + if (!payRes.ok) throw new Error(`Pay API returned HTTP ${payRes.status}`); + const payJson = await payRes.json(); + + if (payJson.code !== 0 || !payJson.imgData) { + throw new Error(payJson.msg || "Failed to retrieve QR image data"); + } + + const base64Data = payJson.imgData.replace(/^data:image\/png;base64,/, ""); + qrBuffer = Buffer.from(base64Data, 'base64'); + + const match = orderId.match(/^UM(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/); + if (match) { + const [_, yy, mm, dd, hh, min, ss] = match; + expectedDate = `20${yy}-${mm}-${dd} ${hh}:${min}:${ss}`; + } } } @@ -651,6 +651,7 @@ isDirectUpi, isPlayBridge, isBifrostPay, + isXmdhPay, tenantId, gatewayHost, gatewayApiUrl [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.