indrajitghosh20006/Testseller_01botPublic · Bot Template

ProfileTelegram

AIThis bot provides an admin‑controlled system for managing user balances, products, and reseller roles. It includes commands to add balances (via manual input, Binance Pay, or UPI), approve and credit payments, and set up product listings with categories and pricing. Admins can also add resellers, view reseller info, and manage stock entries. The bot uses built‑in TeleBotHost APIs such as Bot, Api, HTTP, and Libs for database operations and message handling.

Commerceadminbalanceproductresellerpaymentsbinance
138 commands0 envUpdated 17h agoCreated Sep 27, 2026
Back to folder

commands/_onCheck.js

javascript · 304 lines

Raw
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    return resBal;85  }86 87  // ✅ STEP 1: Strict Order ID validation check88  if (!orderId || orderId.trim() === "") {89    if (queryId) {90      try {91        Api.answerCallbackQuery({92          callback_query_id: queryId,93          text: "⚠️ Active order nahi mila. Kripya pehle naya QR generate karein.",94          show_alert: true95        });96      } catch (e) {}97    }98    return;99  }100 101  // ✅ STEP 2: Duplicate Claim Check102  if (Bot.getProperty("claimed_topup_" + orderId)) {103    vanishQrMessage(targetUserId, chatId);104    if (targetUserId) clearQrState(targetUserId);105 106    if (queryId) {107      try {108        Api.answerCallbackQuery({109          callback_query_id: queryId,110          text: "✅ ALREADY CLAIMED ✅\nYe payment pehle hi verify hokar balance me add ho chuki hai.",111          show_alert: true112        });113      } catch (e) {}114    }115    return;116  }117 118  if (targetUserId && !isBackground) {119    let isChecking = User.getProperty("topup_verifying_lock_" + targetUserId);120    if (isChecking) {121      if (queryId) {122        try {123          Api.answerCallbackQuery({124            callback_query_id: queryId,125            text: "⏳ VERIFYING... PLEASE WAIT...",126            show_alert: true127          });128        } catch (e) {}129      }130      return;131    }132    User.setProperty("topup_verifying_lock_" + targetUserId, true, "boolean");133  }134 135  let responseData = (typeof content !== "undefined" && content) ? (typeof content === "object" ? content : JSON.parse(content)) : null;136 137  if (responseData && (responseData.status === "success" || responseData.status === "SUCCESS") && responseData.data) {138 139    // ✅ STEP 3: Mark claimed only NOW that payment is confirmed successful140    // (avoids race conditions on concurrent success calls, without falsely141    // locking out an order that hasn't actually been paid yet)142    if (Bot.getProperty("claimed_topup_" + orderId)) {143      // Someone else already processed this exact order in parallel — bail out144      if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");145      return;146    }147    Bot.setProperty("claimed_topup_" + orderId, true, "boolean");148 149    let txData = responseData.data;150    let txAmount = txData.amount || amount;151    let utr = txData.utr || txData.transaction_id || "N/A";152    let senderName = txData.sender_name || (typeof user !== "undefined" && user ? user.first_name : "Valued User");153    let payTime = txData.payment_time_ist || "N/A";154    let addedAmount = parseFloat(txAmount) || 0;155 156    try {157      Libs.ResourcesLib.userRes("balance").add(addedAmount);158    } catch (e) {}159    let newBalance = getUnifiedBalance(targetUserId);160 161    // ==========================================162    // 🎁 REFER & EARN — referrer bonus jab referred friend PEHLI baar163    // balance add kare (sirf ek baar, farming rokne ke liye)164    // ==========================================165    try {166      let referredByTopup = User.getProperty("referred_by");167      if (referredByTopup && !User.getProperty("ref_topup_bonus_given")) {168        let refBonusTopup = Number(Bot.getProperty("refer_earn_topup_amount"));169        if (isNaN(refBonusTopup)) refBonusTopup = 2;170        if (refBonusTopup > 0) {171          Libs.ResourcesLib.anotherUserRes("balance", referredByTopup).add(refBonusTopup);172          let pastEarnTopup = Number(Bot.getProperty("refer_earnings_" + referredByTopup) || 0);173          Bot.setProperty("refer_earnings_" + referredByTopup, pastEarnTopup + refBonusTopup, "number");174          try {175            Api.sendMessage({176              chat_id: referredByTopup,177              text: "<blockquote>💸 <b>Referral Bonus!</b>\n\nAapke referred friend ne balance add kiya — aapko ₹" + refBonusTopup.toFixed(2) + " mile hain!</blockquote>",178              parse_mode: "HTML"179            });180          } catch (e) {}181        }182        User.setProperty("ref_topup_bonus_given", true, "boolean");183      }184    } catch (e) {}185 186    // 🔔 Admin notification for wallet balance top-up187    try {188      let walletLogAdminId = Bot.getProperty("owner_id") || "7839151435";189      let walletAdminMsg = "<blockquote>" +190        "🔔 <b>WALLET BALANCE ADDED</b> ✔️\n\n" +191        "👤 <b>User:</b> " + senderName + " (<code>" + targetUserId + "</code>)\n" +192        "💰 <b>Amount Added:</b> ₹" + addedAmount.toFixed(2) + "\n" +193        "🧾 <b>UTR:</b> <code>" + utr + "</code>\n" +194        "🆔 <b>Order ID:</b> <code>" + orderId + "</code>" +195        "</blockquote>";196      Api.sendMessage({ chat_id: walletLogAdminId, text: walletAdminMsg, parse_mode: "HTML" });197    } catch (e) {}198 199    if (queryId) {200      try {201        Api.answerCallbackQuery({202          callback_query_id: queryId,203          text: "✅ PAYMENT VERIFIED SUCCESSFULLY!",204          show_alert: false205        });206      } catch (e) {}207    }208 209    if (targetUserId) {210      vanishQrMessage(targetUserId, chatId);211      clearQrState(targetUserId);212    }213 214    if (User.getProperty("buy_reseller_upgrade")) {215      let resellerPrice = Number(User.getProperty("buy_reseller_price") || 0);216      User.setProperty("buy_reseller_upgrade", null, "boolean");217      User.setProperty("buy_reseller_price", null, "number");218 219      Bot.setProperty("is_reseller_" + targetUserId, true, "boolean");220 221      Api.sendMessage({222        chat_id: chatId,223        text: "<blockquote><tg-emoji emoji-id='6102856637343600044'>🎉</tg-emoji> <b>CONGRATULATIONS!</b></blockquote>\n\n" +224              "<tg-emoji emoji-id='6215386799133433653'>👑</tg-emoji> <b>You are now a Reseller!</b>\n\n" +225              "<i>Payment verified aur permanent reseller status activate ho gaya!</i>",226        parse_mode: "HTML",227        reply_markup: JSON.stringify({ inline_keyboard: [[{ text: "Explore Shop", callback_data: "/buy_hack", style: "success" }]] })228      });229 230      if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");231      return;232    }233 234    let pendingProdIdx = User.getProperty("buy_prod_idx");235    let pendingPlanIdx = User.getProperty("buy_plan_idx");236 237    if (pendingProdIdx !== null && pendingProdIdx !== undefined && pendingProdIdx !== "" &&238        pendingPlanIdx !== null && pendingPlanIdx !== undefined && pendingPlanIdx !== "") {239 240      Api.sendMessage({ 241        chat_id: chatId, 242        text: e_check + " <b>Payment verified! Generating your key now...</b>", 243        parse_mode: "HTML" 244      });245 246      Bot.run({247        command: "/confirm_buyitem",248        options: { params: pendingProdIdx + " " + pendingPlanIdx }249      });250 251      User.setProperty("buy_prod_idx", null);252      User.setProperty("buy_plan_idx", null);253      User.setProperty("buy_price", null);254      User.setProperty("buy_needpay", null);255 256      if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");257      return;258    }259 260    let successText = "━━━━━━━━━━━━━━━━━━━━\n" +261                      e_plus + " <b>PAYMENT SUCCESSFUL</b> " + e_plus + "\n" +262                      "━━━━━━━━━━━━━━━━━━━━\n\n" +263                      e_money + " <b>Added Amount:</b> ₹<b>" + addedAmount.toFixed(2) + "</b>\n" +264                      e_chart + " <b>New Balance:</b> ₹<b>" + newBalance.toFixed(2) + "</b>\n" +265                      e_arrow + " <b>UTR / Ref ID:</b> <code>" + utr + "</code>\n" +266                      e_time + " <b>Time:</b> " + payTime + "\n\n" +267                      "━━━━━━━━━━━━━━━━━━━━\n" +268                      e_coin + " <i>Your funds have been successfully credited! 🎉</i>";269 270    Api.sendMessage({271      chat_id: chatId,272      text: successText,273      parse_mode: "HTML",274      reply_markup: JSON.stringify({275        inline_keyboard: [[276          { text: "🛒 Shop Now", callback_data: "/buy_hack", style: "success" },277          { text: "🔰 Profile", callback_data: "/profile", style: "primary" }278        ]]279      })280    });281 282    if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");283    return;284  }285 286  if (queryId && !isBackground) {287    try {288      Api.answerCallbackQuery({289        callback_query_id: queryId,290        text: "⚠️ PAYMENT NOT RECEIVED YET\nPlease complete the payment first.",291        show_alert: true292      });293    } catch (e) {}294  }295 296  if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");297 298} catch (err) {299  try {300    let uid = (typeof user !== "undefined" && user) ? user.telegramid : null;301    if (uid) User.setProperty("topup_verifying_lock_" + uid, false, "boolean");302  } catch (e) {}303  Bot.sendMessage("⚠️ Error in verification check: " + err.message);304}