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] @@ -576,7 +576,7 @@ console.error("Error:", e); console.error('[SUPPORT NOTIF] Error sending UTR notification:', e.message); } - addPendingPayment(userId, orderId, serialNumber, expectedAmount, expectedDate, session.planType, utr, supportMsgId); + addPendingPayment(userId, orderId, serialNumber, expectedAmount, expectedDate, session.planType, utr, supportMsgId, session.paymentToken); // Delete the loading message await ctx.telegram.deleteMessage(ctx.chat.id, loadingMsg.message_id).catch(() => { }); @@ -594,7 +594,10 @@ // ── Fast Per-Payment Checker ────────────────────────────────────────── // Check every 15 seconds for the first 3 minutes (12 attempts) for instant detection - let token = cachedPaymentToken || process.env.GAME_PAYMENT_TOKEN; + let token = session.paymentToken || cachedPaymentToken; + if (!token) { + token = await getFreshPaymentToken().catch(() => null); + } if (token) { let fastAttempt = 0; const MAX_FAST_ATTEMPTS = 12; // 12 × 15s = 3 minutes @@ -623,7 +623,8 @@ // Auto-refresh token if expired (604 or 10002) and retry if (histJson.code === 604 || histJson.code === 10002 || histJson.msg === 'Token expired' || histJson.message === 'Token expired') { console.log(`[FAST-CHECKER] Token expired (code ${histJson.code}). Refreshing...`); - token = await refreshPaymentToken(); + token = await getFreshPaymentToken().catch(() => null); + if (!token) return; histRes = await fetch(`https://api.oeur39rmwe.com/session/member/deposit?startDate=${startDate}&endDate=${endDate}¤t=1&size=20`, { method: 'GET', headers: { 'Authorization': 'IND', 'Token': token, 'User-Agent': 'Mozilla/5.0' } @@ -642,7 +642,7 @@ } } } catch (e) { - console.error("Error:", e); + console.error("Error:", e); console.error(`[FAST-CHECKER] Error on attempt ${fastAttempt}:`, e.message); } }, 15000); // every 15 seconds @@ -662,7 +662,7 @@ try { return JSON.parse(fs.readFileSync(PAYMENTS_FILE, 'utf8')); } catch (e) { - console.error("Error:", e); + console.error("Error:", e); return []; } } @@ -670,7 +670,7 @@ fs.writeFileSync(PAYMENTS_FILE, JSON.stringify(payments, null, 2)); } -function addPendingPayment(userId, orderId, serialNumber, expectedAmount, depositDate, planType = 'credits', utr = null, supportMsgId = null) { +function addPendingPayment(userId, orderId, serialNumber, expectedAmount, depositDate, planType = 'credits', utr = null, supportMsgId = null, paymentToken = null) { const payments = getPendingPayments(); if (payments.some(p => p.orderId === orderId)) return; payments.push({ @@ -681,6 +681,7 @@ planType, utr, supportMsgId, + paymentToken, createdAt: Date.now() }); savePendingPayments(payments); @@ -690,8 +690,16 @@ const payments = getPendingPayments(); if (payments.length === 0) return; - let token = cachedPaymentToken || process.env.GAME_PAYMENT_TOKEN; - if (!token) return; + let token = cachedPaymentToken; + if (!token) { + try { + token = await getFreshPaymentToken(); + cachedPaymentToken = token; + } catch (e) { + console.error('[DAEMON] Could not obtain token for checkPendingPayments:', e.message); + return; + } + } console.log(`[DAEMON] Running background check on ${payments.length} pending payments...`); @@ -720,7 +720,8 @@ // Auto-refresh token if expired (604 or 10002) and retry if (json.code === 604 || json.code === 10002 || json.msg === 'Token expired' || json.message === 'Token expired') { console.log(`[DAEMON] Token expired (code ${json.code}) in background check. Refreshing...`); - token = await refreshPaymentToken(); + token = await getFreshPaymentToken(); + cachedPaymentToken = token; res = await fetch(historyUrl, { method: 'GET', headers: { [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.