kkapil9112/Aestheticmodes9_botPublic · Bot Template
AIA Telegram-based digital goods store bot with a full admin panel for managing products, plans, stock, keys, categories, resellers, balances, and coupons. It uses TeleBotHost APIs like Bot, Api, User, Libs.ResourcesLib, and HTTP to run a shop interface, handle admin-only commands, track users, and send inventory/balance summaries. The implementation appears focused on selling game-related accounts and keys such as FreeFire items, with customer-facing store, balance, coupon, and back-to-menu flows.
Commerceshopadmin-panelbalanceresellercouponsstock-management
102 commands1 envUpdated 29d agoCreated Aug 9, 2026
commands/_onCheck.js
javascript · 333 lines
1/**#command2name: /onCheck3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// =========================================================13// 🚀 COMMAND = /onCheck (Payment Response Verification Handler - ADD FUND)14// STATUS: ✅ FIXED - unified balance store + duplicate-claim protection + QR vanish15// =========================================================16 17try {18 var opts = (typeof options !== "undefined" && options) ? options : {};19 let isBackground = opts.is_background || false;20 let orderId = opts.order_id;21 let amount = opts.amount;22 let chatId = opts.chat_id || (typeof chat !== "undefined" && chat ? chat.chatid : null);23 let attempt = opts.attempt || 1;24 25 if (typeof params !== "undefined" && params && params.trim() !== "") {26 let splitParams = params.trim().split(" ");27 if (splitParams.length >= 1) orderId = splitParams[0];28 if (splitParams.length >= 2) amount = splitParams[1];29 }30 31 let queryId = null;32 if (typeof request !== "undefined" && request) {33 if (request.callback_query && request.callback_query.id) {34 queryId = request.callback_query.id;35 } else if (request.id) {36 queryId = request.id;37 }38 }39 40 let targetUserId = (typeof user !== "undefined" && user) ? user.telegramid : null;41 42 // 🎨 Premium emoji set43 let e_chart = "<tg-emoji emoji-id='5992430854909989581'>📊</tg-emoji>";44 let e_plus = "<tg-emoji emoji-id='5346004239246183111'>➕</tg-emoji>";45 let e_arrow = "<tg-emoji emoji-id='5875506366050734240'>➡️</tg-emoji>";46 let e_coin = "<tg-emoji emoji-id='5778335621491723621'>🪙</tg-emoji>";47 let e_money = "<tg-emoji emoji-id='5348392971207194994'>💰</tg-emoji>";48 let e_time = "<tg-emoji emoji-id='5776213190387961618'>🕓</tg-emoji>";49 let e_lock = "<tg-emoji emoji-id='5350447674971660988'>🔒</tg-emoji>";50 let e_warn = "<tg-emoji emoji-id='6219547832169273793'>⚠️</tg-emoji>";51 let e_check = "<tg-emoji emoji-id='5330237710655306682'>✅</tg-emoji>";52 53 // Helper: fetch + vanish the active QR message for this user54 function vanishQrMessage(uid, fallbackChatId) {55 try {56 let qrMsgId = Bot.getProperty("qr_msg_id_" + uid) ||57 User.getProperty("qr_msg_id_" + uid) ||58 User.getProperty("last_qr_message_id_" + uid);59 if (qrMsgId) {60 try { Api.deleteMessage({ chat_id: fallbackChatId, message_id: qrMsgId }); } catch (e) {}61 }62 } catch (e) {}63 }64 65 // Helper: fully clear all QR/order related state for this user66 function clearQrState(uid) {67 Bot.setProperty("qr_msg_id_" + uid, null, "string");68 User.setProperty("qr_msg_id_" + uid, null, "string");69 User.setProperty("last_qr_message_id_" + uid, null, "string");70 Bot.setProperty("qr_order_id_" + uid, null, "string");71 User.setProperty("qr_order_id_" + uid, null, "string");72 Bot.setProperty("qr_watch_order_" + uid, null, "string");73 User.setProperty("qr_watch_order_" + uid, null, "string");74 Bot.setProperty("qr_caption_" + uid, null, "string");75 User.setProperty("qr_caption_" + uid, null, "string");76 Bot.setProperty("qr_buttons_" + uid, null, "string");77 User.setProperty("qr_buttons_" + uid, null, "string");78 Bot.setProperty("verifying_lock_" + uid, false, "boolean");79 User.setProperty("verifying_lock_" + uid, false, "boolean");80 User.setProperty("topup_verifying_lock_" + uid, false, "boolean");81 User.setProperty("pending_order_id", null);82 }83 84 // Helper: unified wallet balance (same source used everywhere in the bot now)85 function getUnifiedBalance(uid) {86 let resBal = 0;87 try { resBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (e) {}88 let bonusBal = Number(Bot.getProperty("balance" + uid) || 0);89 return resBal + bonusBal;90 }91 92 // =====================================================93 // 🛑 0. DUPLICATE-CLICK LOCK (stops double taps on "I have paid")94 // =====================================================95 if (targetUserId && !isBackground) {96 let isChecking = User.getProperty("topup_verifying_lock_" + targetUserId);97 if (isChecking) {98 if (queryId) {99 try {100 Api.answerCallbackQuery({101 callback_query_id: queryId,102 text: "⏳ ALREADY CHECKING — PLEASE WAIT...",103 show_alert: true104 });105 } catch (e) {}106 }107 return;108 }109 User.setProperty("topup_verifying_lock_" + targetUserId, true, "boolean");110 }111 112 // =====================================================113 // 🛑 1. ALREADY-CLAIMED CHECK (stops double balance credit on same order)114 // =====================================================115 if (orderId && Bot.getProperty("claimed_topup_" + orderId)) {116 vanishQrMessage(targetUserId, chatId);117 if (targetUserId) clearQrState(targetUserId);118 119 if (queryId) {120 try {121 Api.answerCallbackQuery({122 callback_query_id: queryId,123 text: "✅ ALREADY CLAIMED ✅\nYe payment pehle hi verify ho chuki hai aur balance wallet me add ho chuka hai.",124 show_alert: true125 });126 } catch (e) {}127 }128 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");129 return;130 }131 132 let responseData = (typeof content !== "undefined" && content) ? (typeof content === "object" ? content : JSON.parse(content)) : null;133 134 // --- 2. SUCCESS PAYMENT CONDITION ---135 if (responseData && (responseData.status === "success" || responseData.status === "SUCCESS") && responseData.data) {136 let txData = responseData.data;137 let txAmount = txData.amount || amount;138 let utr = txData.utr || txData.transaction_id || "N/A";139 let senderName = txData.sender_name || (typeof user !== "undefined" && user ? user.first_name : "Valued User");140 let payTime = txData.payment_time_ist || "N/A";141 let addedAmount = parseFloat(txAmount) || 0;142 143 // ✅ Mark this order as claimed FIRST (closes the double-click race window)144 if (orderId) Bot.setProperty("claimed_topup_" + orderId, true, "boolean");145 146 // ✅ FIX: Credit into the SAME wallet store used everywhere else in the bot147 // (previously this wrote to a separate User.getProperty("balance") string that148 // purchase flows never read, so a deposit here never actually became spendable149 // balance and different screens showed different numbers).150 try {151 Libs.ResourcesLib.userRes("balance").add(addedAmount);152 } catch (e) {}153 let newBalance = getUnifiedBalance(targetUserId);154 155 if (queryId) {156 try {157 Api.answerCallbackQuery({158 callback_query_id: queryId,159 text: "✅ PAYMENT VERIFIED SUCCESSFULLY!",160 show_alert: false161 });162 } catch (e) {}163 }164 165 // ✅ Vanish the QR message completely instead of leaving it lying around166 if (targetUserId) {167 vanishQrMessage(targetUserId, chatId);168 clearQrState(targetUserId);169 }170 171 // =====================================================172 // 🛒 NEW: Agar ye top-up kisi pending PLAN PURCHASE (buyitem.js shortfall)173 // ke liye tha, to ab balance exactly cover ho chuka hai — bina dobara174 // confirm maange, seedha key purchase auto-complete karo.175 // =====================================================176 // =====================================================177 // 👑 NEW: Agar ye top-up pending RESELLER UPGRADE ke liye tha, to ab178 // balance cover ho chuka hai — turant permanent reseller bana do.179 // =====================================================180 if (User.getProperty("buy_reseller_upgrade")) {181 let resellerPrice = Number(User.getProperty("buy_reseller_price") || 0);182 User.setProperty("buy_reseller_upgrade", null, "boolean");183 User.setProperty("buy_reseller_price", null, "number");184 185 Bot.setProperty("is_reseller_" + targetUserId, true, "boolean");186 187 Api.sendMessage({188 chat_id: chatId,189 text: "<blockquote><tg-emoji emoji-id='6102856637343600044'>🎉</tg-emoji> <b>CONGRATULATIONS!</b></blockquote>\n\n" +190 "<tg-emoji emoji-id='6215386799133433653'>👑</tg-emoji> <b>You are now a Reseller!</b>\n\n" +191 "<i>Payment verified aur permanent reseller status activate ho gaya! Ab aapko har product/plan par reseller pricing milegi.</i>",192 parse_mode: "HTML",193 reply_markup: JSON.stringify({ inline_keyboard: [[{ text: "Explore Shop", callback_data: "/buy_hack", style: "success", icon_custom_emoji_id: "5866053971960929280" }]] })194 });195 196 let ownerId2 = Bot.getProperty("owner_id") || "8812621370";197 try {198 Api.sendMessage({199 chat_id: ownerId2,200 text: "👑 <b>NEW RESELLER (via QR)!</b>\n👤 <b>User:</b> <code>" + targetUserId + "</code>\n💰 <b>Paid:</b> ₹" + resellerPrice.toFixed(2),201 parse_mode: "HTML"202 });203 } catch (e) {}204 205 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");206 return;207 }208 209 let pendingProdIdx = User.getProperty("buy_prod_idx");210 let pendingPlanIdx = User.getProperty("buy_plan_idx");211 212 if (pendingProdIdx !== null && pendingProdIdx !== undefined && pendingProdIdx !== "" &&213 pendingPlanIdx !== null && pendingPlanIdx !== undefined && pendingPlanIdx !== "") {214 215 let depositNote =216 "<blockquote>" + e_check + " <b>PAYMENT VERIFIED</b>\n" +217 e_money + " <b>Added Amount:</b> ₹<b>" + addedAmount.toFixed(2) + "</b>\n" +218 e_arrow + " <b>UTR:</b> <code>" + utr + "</code>\n\n" +219 "<tg-emoji emoji-id='6147936236125298267'>⏳</tg-emoji> <i>Generating your key now, please wait...</i></blockquote>";220 221 Api.sendMessage({ chat_id: chatId, text: depositNote, parse_mode: "HTML" });222 223 let adminId2 = 6191635812;224 Api.sendMessage({225 chat_id: adminId2,226 text: "<blockquote>" + e_chart + " <b>DEPOSIT RECEIVED (Plan Purchase)</b></blockquote>\n" +227 "━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n" +228 "<tg-emoji emoji-id='6145572393499762737'>👤</tg-emoji> <b>User:</b> <a href='tg://user?id=" + (targetUserId || "") + "'>" + senderName + "</a> (<code>" + (targetUserId || "N/A") + "</code>)\n" +229 e_money + " <b>Amount:</b> ₹<b>" + addedAmount.toFixed(2) + "</b>\n" +230 e_arrow + " <b>UTR:</b> <code>" + utr + "</code>\n" +231 "━━━━━━━━━━━━━━━━━━━━━━━━━━\n" +232 "<tg-emoji emoji-id='6147936236125298267'>⏳</tg-emoji> <i>Auto-completing pending plan purchase now...</i>",233 parse_mode: "HTML"234 });235 236 // Purchase completion me le jao — /confirm_buyitem seedha API se key deliver karega237 Bot.run({238 command: "/confirm_buyitem",239 options: { params: pendingProdIdx + " " + pendingPlanIdx }240 });241 242 // Pending-buy flags clear karo (last_pending_* ko /confirm_buyitem khud set karega)243 User.setProperty("buy_prod_idx", null);244 User.setProperty("buy_plan_idx", null);245 User.setProperty("buy_price", null);246 User.setProperty("buy_needpay", null);247 User.setProperty("buy_prod_name", null);248 User.setProperty("buy_plan_days", null);249 250 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");251 return;252 }253 254 let successText = "━━━━━━━━━━━━━━━━━━━━\n" +255 e_plus + " <b>PAYMENT SUCCESSFUL</b> " + e_plus + "\n" +256 "━━━━━━━━━━━━━━━━━━━━\n\n" +257 e_money + " <b>Added Amount:</b> ₹<b>" + addedAmount.toFixed(2) + "</b>\n" +258 e_chart + " <b>New Balance:</b> ₹<b>" + newBalance.toFixed(2) + "</b>\n" +259 e_arrow + " <b>UTR / Ref ID:</b> <code>" + utr + "</code>\n" +260 e_time + " <b>Time:</b> " + payTime + "\n\n" +261 "━━━━━━━━━━━━━━━━━━━━\n" +262 e_coin + " <i>Your funds have been successfully credited to your wallet! 🎉</i>";263 264 Api.sendMessage({265 chat_id: chatId,266 text: successText,267 parse_mode: "HTML",268 reply_markup: JSON.stringify({269 inline_keyboard: [[270 { text: "🛒 Shop Now", callback_data: "/buy_hack", style: "success" },271 { text: "🔰 Profile", callback_data: "/profile", style: "primary" }272 ]]273 })274 });275 276 let adminId = 6191635812;277 let adminUsername = (typeof user !== "undefined" && user && user.username) ? "@" + user.username : "No Username";278 let adminText =279 "<blockquote>" + e_chart + " <b>NEW DEPOSIT RECEIVED</b> " + e_chart + "</blockquote>\n" +280 "━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n" +281 "<tg-emoji emoji-id='6145572393499762737'>👤</tg-emoji> <b>User:</b> <a href='tg://user?id=" + (targetUserId || "") + "'>" + senderName + "</a> (<code>" + (targetUserId || "N/A") + "</code>)\n" +282 "<tg-emoji emoji-id='6041705726206808304'>🌐</tg-emoji> <b>Username:</b> " + adminUsername + "\n\n" +283 e_money + " <b>Amount Added:</b> ₹<b>" + addedAmount.toFixed(2) + "</b>\n" +284 "<tg-emoji emoji-id='5348392971207194994'>💳</tg-emoji> <b>Wallet Total Now:</b> ₹<b>" + newBalance.toFixed(2) + "</b>\n" +285 e_arrow + " <b>UTR / Ref ID:</b> <code>" + utr + "</code>\n" +286 e_time + " <b>Time:</b> " + payTime + "\n" +287 "━━━━━━━━━━━━━━━━━━━━━━━━━━\n" +288 "<tg-emoji emoji-id='5330237710655306682'>✅</tg-emoji> <i>Auto-verified & auto-credited — no manual action needed.</i>";289 290 Api.sendMessage({291 chat_id: adminId,292 text: adminText,293 parse_mode: "HTML"294 });295 296 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");297 return;298 }299 300 // --- 3. PAYMENT NOT RECEIVED YET ---301 if (queryId && !isBackground) {302 try {303 Api.answerCallbackQuery({304 callback_query_id: queryId,305 text: "⚠️ PAYMENT NOT RECEIVED YET ⚠️\nPlease complete the payment first, then tap again.",306 show_alert: true307 });308 } catch (e) {}309 }310 311 if (isBackground && attempt < 60 && orderId) {312 Bot.run({313 command: "/verify_background",314 options: {315 order_id: orderId,316 amount: amount,317 chat_id: chatId,318 attempt: attempt + 1,319 is_background: true320 },321 run_after: 5322 });323 }324 325 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");326 327} catch (err) {328 try {329 let uid = (typeof user !== "undefined" && user) ? user.telegramid : null;330 if (uid) User.setProperty("topup_verifying_lock_" + uid, false, "boolean");331 } catch (e) {}332 Bot.sendMessage("⚠️ Error in verification check: " + err.message);333}