The following changes were made by the replace_file_content tool to: /root/aadharbot/modules/pay/services/paymentService.js. If relevant, proactively run terminal commands to execute this code for the USER. Don't ask for permission. [diff_block_start] @@ -177,6 +177,7 @@ let submitJson = null; let lastSubmitError = null; + let qrResult = null; for (let i = 0; i < candidatePaymentIds.length; i++) { const pid = candidatePaymentIds[i]; @@ -197,15 +197,24 @@ console.log(`[PAYMENT] Submit API response (paymentId=${pid}):`, JSON.stringify(resJson)); if (resJson.code === 0 && resJson.data && resJson.data.result && resJson.data.result.requestUrl) { - submitJson = resJson; - break; - } - - const mappedErr = CASHIER_ERROR_MAP[resJson.code] || resJson.message || resJson.msg || `Payment gateway returned code ${resJson.code}`; - lastSubmitError = new Error(mappedErr); - - if (i < candidatePaymentIds.length - 1) { - await new Promise(r => setTimeout(r, 1500)); + const testUrl = resJson.data.result.requestUrl; + console.log(`[PAYMENT] Processing checkout URL: ${testUrl}`); + try { + qrResult = await gateways.generateQR(testUrl, amount); + requestUrl = testUrl; + submitJson = resJson; + break; + } catch (qrErr) { + console.warn(`[PAYMENT WARNING] generateQR failed for paymentId ${pid}: ${qrErr.message}. Trying next candidate...`); + lastSubmitError = qrErr; + } + } else { + const mappedErr = CASHIER_ERROR_MAP[resJson.code] || resJson.message || resJson.msg || `Payment gateway returned code ${resJson.code}`; + lastSubmitError = new Error(mappedErr); + } + + if (i < candidatePaymentIds.length - 1) { + await new Promise(r => setTimeout(r, 1000)); } } catch (err) { lastSubmitError = err; @@ -212,17 +212,13 @@ if (i < candidatePaymentIds.length - 1) { - await new Promise(r => setTimeout(r, 1500)); - } - } - } - - if (!submitJson || !submitJson.data || !submitJson.data.result || !submitJson.data.result.requestUrl) { + await new Promise(r => setTimeout(r, 1000)); + } + } + } + + if (!qrResult) { throw lastSubmitError || new Error("Failed to generate payment order from server"); } - requestUrl = submitJson.data.result.requestUrl; - console.log(`[PAYMENT] Processing checkout URL: ${requestUrl}`); - - const qrResult = await gateways.generateQR(requestUrl, amount); gatewayHost = qrResult.gatewayHost; const { qrBuffer, @@ -238,6 +238,7 @@ isPayflow, isDirectUpi, isPlayBridge, + isMuskmelon, isBifrostPay, isXmdhPay, isCoinPay, @@ -309,7 +309,8 @@ } if (serialNumber === 'N/A') { - throw new Error("Failed to fetch Serial Number from deposit history. Please try again in a few seconds."); + console.warn(`[PAYMENT WARNING] Serial number not matched after 10 attempts. Falling back to orderId: ${orderId}`); + serialNumber = orderId || ('IND' + Date.now()); } // Delete the loading message @@ -334,6 +334,7 @@ isPayflow: isPayflow, isDirectUpi: isDirectUpi, isPlayBridge: isPlayBridge, + isMuskmelon: isMuskmelon, isBifrostPay: isBifrostPay, isXmdhPay: isXmdhPay, isCoinPay: isCoinPay, [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.