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] @@ -677,6 +677,39 @@ } else { expectedDate = formatDateIST(new Date()); } + } else if (isCoinPay) { + console.log(`[GATEWAY] CoinPay detected (${gatewayHost}). Processing session token...`); + let sessionToken = parsedUrl.searchParams.get('session'); + if (!sessionToken && parsedUrl.hash) { + const hashMatch = parsedUrl.hash.match(/[?&]session=([^&]+)/i); + if (hashMatch) { + sessionToken = decodeURIComponent(hashMatch[1]); + } + } + + if (!sessionToken) { + throw new Error('CoinPay session token not found in URL'); + } + + const coinpayData = decryptCoinPayToken(sessionToken); + console.log(`[GATEWAY] CoinPay decrypted successfully. Order ID: ${coinpayData.order_id}, Amount: ${coinpayData.amount}`); + + orderId = coinpayData.order_id; + const upiUrl = coinpayData.payment_intent; + + if (!upiUrl || (!upiUrl.startsWith('upi://') && !upiUrl.startsWith('https://'))) { + throw new Error(`CoinPay returned invalid payment intent: ${upiUrl}`); + } + + console.log(`[GATEWAY] CoinPay resolved UPI: ${upiUrl}, Order ID: ${orderId}`); + const QRCode = require('qrcode'); + qrBuffer = await QRCode.toBuffer(upiUrl, { type: 'png', width: 400 }); + + if (coinpayData.iat) { + expectedDate = formatDateIST(new Date(Number(coinpayData.iat) * 1000)); + } else { + expectedDate = formatDateIST(new Date()); + } } 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.