devbro468/Dev_x_store_botPublic · Bot Template
AIThis bot operates a digital storefront (DEV X STORE) selling subscription-based products — likely game hacks, accounts, or access keys — categorized by platform (Android Root, Non-Root, iPhone). It features a reseller program with discounted pricing, a dual-currency wallet (INR balance + Telegram Stars/XTR), and a full admin/co-admin panel for managing products, plans, per-plan pricing, stock (keys/accounts), coupons, and API endpoints. Purchases flow through a plan selection screen offering wallet payment, Stars invoices (sendInvoice with XTR currency), and coupon application. Successful Stars payments are handled via successful_payment webhook, crediting wallet or delivering keys directly. Admin tools include user listing with chunked messaging, stock viewing/deletion with inline keyboards, co-admin management, and API registry updates. The bot registers users on first interaction and
commands/_onCheck.js
javascript · 305 lines
1/**#command2name: /onCheck3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12try {13 var opts = (typeof options !== "undefined" && options) ? options : {};14 let isBackground = opts.is_background || false;15 let orderId = opts.order_id;16 let amount = opts.amount;17 let chatId = chat ? chat.chatid : null;18 let attempt = opts.attempt || 1;19 20 if (typeof params !== "undefined" && params && params.trim() !== "") {21 let splitParams = params.trim().split(" ");22 if (splitParams.length >= 1 && splitParams[0].length > 5) {23 orderId = splitParams[0];24 }25 if (splitParams.length >= 2) amount = splitParams[1];26 }27 28 let targetUserId = (typeof user !== "undefined" && user) ? user.telegramid : null;29 30 // 🛠️ ULTIMATE FALLBACK: Agar button ya params se orderId na mile, toh active pending order ID utha lo!31 if ((!orderId || orderId.trim() === "") && targetUserId) {32 orderId = User.getProperty("pending_order_id") || 33 Bot.getProperty("qr_order_id_" + targetUserId) || 34 User.getProperty("qr_order_id_" + targetUserId) ||35 User.getProperty("buy_pending_order_id");36 }37 38 let queryId = null;39 if (typeof request !== "undefined" && request) {40 if (request.callback_query && request.callback_query.id) {41 queryId = request.callback_query.id;42 } else if (request.id) {43 queryId = request.id;44 }45 }46 47 // 🎨 Premium emojis48 let e_chart = "<tg-emoji emoji-id='5992430854909989581'>📊</tg-emoji>";49 let e_plus = "<tg-emoji emoji-id='5346004239246183111'>➕</tg-emoji>";50 let e_arrow = "<tg-emoji emoji-id='5875506366050734240'>➡️</tg-emoji>";51 let e_coin = "<tg-emoji emoji-id='5778335621491723621'>🪙</tg-emoji>";52 let e_money = "<tg-emoji emoji-id='5348392971207194994'>💰</tg-emoji>";53 let e_time = "<tg-emoji emoji-id='5776213190387961618'>🕓</tg-emoji>";54 let e_check = "<tg-emoji emoji-id='5330237710655306682'>✅</tg-emoji>";55 56 function vanishQrMessage(uid, fallbackChatId) {57 try {58 let qrMsgId = Bot.getProperty("qr_msg_id_" + uid) ||59 User.getProperty("qr_msg_id_" + uid) ||60 User.getProperty("last_qr_message_id_" + uid);61 if (qrMsgId) {62 try { Api.deleteMessage({ chat_id: fallbackChatId, message_id: qrMsgId }); } catch (e) {}63 }64 } catch (e) {}65 }66 67 function clearQrState(uid) {68 Bot.setProperty("qr_msg_id_" + uid, null, "string");69 User.setProperty("qr_msg_id_" + uid, null, "string");70 User.setProperty("last_qr_message_id_" + uid, null, "string");71 Bot.setProperty("qr_order_id_" + uid, null, "string");72 User.setProperty("qr_order_id_" + uid, null, "string");73 Bot.setProperty("qr_watch_order_" + uid, null, "string");74 User.setProperty("qr_watch_order_" + uid, null, "string");75 Bot.setProperty("verifying_lock_" + uid, false, "boolean");76 User.setProperty("verifying_lock_" + uid, false, "boolean");77 User.setProperty("topup_verifying_lock_" + uid, false, "boolean");78 User.setProperty("pending_order_id", null);79 }80 81 function getUnifiedBalance(uid) {82 let resBal = 0;83 try { resBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (e) {}84 let bonusBal = Number(Bot.getProperty("balance" + uid) || 0);85 return resBal + bonusBal;86 }87 88 // ✅ STEP 1: Strict Order ID validation check89 if (!orderId || orderId.trim() === "") {90 if (queryId) {91 try {92 Api.answerCallbackQuery({93 callback_query_id: queryId,94 text: "⚠️ Active order nahi mila. Kripya pehle naya QR generate karein.",95 show_alert: true96 });97 } catch (e) {}98 }99 return;100 }101 102 // ✅ STEP 2: Duplicate Claim Check103 if (Bot.getProperty("claimed_topup_" + orderId)) {104 vanishQrMessage(targetUserId, chatId);105 if (targetUserId) clearQrState(targetUserId);106 107 if (queryId) {108 try {109 Api.answerCallbackQuery({110 callback_query_id: queryId,111 text: "✅ ALREADY CLAIMED ✅\nYe payment pehle hi verify hokar balance me add ho chuki hai.",112 show_alert: true113 });114 } catch (e) {}115 }116 return;117 }118 119 if (targetUserId && !isBackground) {120 let isChecking = User.getProperty("topup_verifying_lock_" + targetUserId);121 if (isChecking) {122 if (queryId) {123 try {124 Api.answerCallbackQuery({125 callback_query_id: queryId,126 text: "⏳ VERIFYING... PLEASE WAIT...",127 show_alert: true128 });129 } catch (e) {}130 }131 return;132 }133 User.setProperty("topup_verifying_lock_" + targetUserId, true, "boolean");134 }135 136 let responseData = (typeof content !== "undefined" && content) ? (typeof content === "object" ? content : JSON.parse(content)) : null;137 138 if (responseData && (responseData.status === "success" || responseData.status === "SUCCESS") && responseData.data) {139 140 // ✅ STEP 3: Mark claimed only NOW that payment is confirmed successful141 // (avoids race conditions on concurrent success calls, without falsely142 // locking out an order that hasn't actually been paid yet)143 if (Bot.getProperty("claimed_topup_" + orderId)) {144 // Someone else already processed this exact order in parallel — bail out145 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");146 return;147 }148 Bot.setProperty("claimed_topup_" + orderId, true, "boolean");149 150 let txData = responseData.data;151 let txAmount = txData.amount || amount;152 let utr = txData.utr || txData.transaction_id || "N/A";153 let senderName = txData.sender_name || (typeof user !== "undefined" && user ? user.first_name : "Valued User");154 let payTime = txData.payment_time_ist || "N/A";155 let addedAmount = parseFloat(txAmount) || 0;156 157 try {158 Libs.ResourcesLib.userRes("balance").add(addedAmount);159 } catch (e) {}160 let newBalance = getUnifiedBalance(targetUserId);161 162 // ==========================================163 164 // balance add kare (sirf ek baar, farming rokne ke liye)165 // ==========================================166 try {167 let referredByTopup = User.getProperty("referred_by");168 if (referredByTopup && !User.getProperty("ref_topup_bonus_given")) {169 let refBonusTopup = Number(Bot.getProperty("refer_earn_topup_amount"));170 if (isNaN(refBonusTopup)) refBonusTopup = 2;171 if (refBonusTopup > 0) {172 Libs.ResourcesLib.anotherUserRes("balance", referredByTopup).add(refBonusTopup);173 let pastEarnTopup = Number(Bot.getProperty("refer_earnings_" + referredByTopup) || 0);174 Bot.setProperty("refer_earnings_" + referredByTopup, pastEarnTopup + refBonusTopup, "number");175 try {176 Api.sendMessage({177 chat_id: referredByTopup,178 text: "<blockquote>💸 <b>Referral Bonus!</b>\n\nAapke referred friend ne balance add kiya — aapko ₹" + refBonusTopup.toFixed(2) + " mile hain!</blockquote>",179 parse_mode: "HTML"180 });181 } catch (e) {}182 }183 User.setProperty("ref_topup_bonus_given", true, "boolean");184 }185 } catch (e) {}186 187 // 🔔 Admin notification for wallet balance top-up188 try {189 let walletLogAdminId = Bot.getProperty("owner_id") || "8875810358";190 let walletAdminMsg = "<blockquote>" +191 "🔔 <b>WALLET BALANCE ADDED</b> ✔️\n\n" +192 "👤 <b>User:</b> " + senderName + " (<code>" + targetUserId + "</code>)\n" +193 "💰 <b>Amount Added:</b> ₹" + addedAmount.toFixed(2) + "\n" +194 "🧾 <b>UTR:</b> <code>" + utr + "</code>\n" +195 "🆔 <b>Order ID:</b> <code>" + orderId + "</code>" +196 "</blockquote>";197 Api.sendMessage({ chat_id: walletLogAdminId, text: walletAdminMsg, parse_mode: "HTML" });198 } catch (e) {}199 200 if (queryId) {201 try {202 Api.answerCallbackQuery({203 callback_query_id: queryId,204 text: "✅ PAYMENT VERIFIED SUCCESSFULLY!",205 show_alert: false206 });207 } catch (e) {}208 }209 210 if (targetUserId) {211 vanishQrMessage(targetUserId, chatId);212 clearQrState(targetUserId);213 }214 215 if (User.getProperty("buy_reseller_upgrade")) {216 let resellerPrice = Number(User.getProperty("buy_reseller_price") || 0);217 User.setProperty("buy_reseller_upgrade", null, "boolean");218 User.setProperty("buy_reseller_price", null, "number");219 220 Bot.setProperty("is_reseller_" + targetUserId, true, "boolean");221 222 Api.sendMessage({223 chat_id: chatId,224 text: "<blockquote><tg-emoji emoji-id='6102856637343600044'>🎉</tg-emoji> <b>CONGRATULATIONS!</b></blockquote>\n\n" +225 "<tg-emoji emoji-id='6215386799133433653'>👑</tg-emoji> <b>You are now a Reseller!</b>\n\n" +226 "<i>Payment verified aur permanent reseller status activate ho gaya!</i>",227 parse_mode: "HTML",228 reply_markup: JSON.stringify({ inline_keyboard: [[{ text: "Explore Shop", callback_data: "/buy_hack", style: "success" }]] })229 });230 231 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");232 return;233 }234 235 let pendingProdIdx = User.getProperty("buy_prod_idx");236 let pendingPlanIdx = User.getProperty("buy_plan_idx");237 238 if (pendingProdIdx !== null && pendingProdIdx !== undefined && pendingProdIdx !== "" &&239 pendingPlanIdx !== null && pendingPlanIdx !== undefined && pendingPlanIdx !== "") {240 241 Api.sendMessage({ 242 chat_id: chatId, 243 text: e_check + " <b>Payment verified! Generating your key now...</b>", 244 parse_mode: "HTML" 245 });246 247 Bot.run({248 command: "/confirm_buyitem",249 options: { params: pendingProdIdx + " " + pendingPlanIdx }250 });251 252 User.setProperty("buy_prod_idx", null);253 User.setProperty("buy_plan_idx", null);254 User.setProperty("buy_price", null);255 User.setProperty("buy_needpay", null);256 257 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");258 return;259 }260 261 let successText = "━━━━━━━━━━━━━━━━━━━━\n" +262 e_plus + " <b>PAYMENT SUCCESSFUL</b> " + e_plus + "\n" +263 "━━━━━━━━━━━━━━━━━━━━\n\n" +264 e_money + " <b>Added Amount:</b> ₹<b>" + addedAmount.toFixed(2) + "</b>\n" +265 e_chart + " <b>New Balance:</b> ₹<b>" + newBalance.toFixed(2) + "</b>\n" +266 e_arrow + " <b>UTR / Ref ID:</b> <code>" + utr + "</code>\n" +267 e_time + " <b>Time:</b> " + payTime + "\n\n" +268 "━━━━━━━━━━━━━━━━━━━━\n" +269 e_coin + " <i>Your funds have been successfully credited! 🎉</i>";270 271 Api.sendMessage({272 chat_id: chatId,273 text: successText,274 parse_mode: "HTML",275 reply_markup: JSON.stringify({276 inline_keyboard: [[277 { text: "🛒 Shop Now", callback_data: "/buy_hack", style: "success" },278 { text: "🔰 Profile", callback_data: "/profile", style: "primary" }279 ]]280 })281 });282 283 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");284 return;285 }286 287 if (queryId && !isBackground) {288 try {289 Api.answerCallbackQuery({290 callback_query_id: queryId,291 text: "⚠️ PAYMENT NOT RECEIVED YET\nPlease complete the payment first.",292 show_alert: true293 });294 } catch (e) {}295 }296 297 if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");298 299} catch (err) {300 try {301 let uid = (typeof user !== "undefined" && user) ? user.telegramid : null;302 if (uid) User.setProperty("topup_verifying_lock_" + uid, false, "boolean");303 } catch (e) {}304 Bot.sendMessage("⚠️ Error in verification check: " + err.message);305}