ayushyadav7970824760/goldensellingstore_botPublic · Bot Template

AIThis Telegram store bot lets customers browse digital products and plans, apply coupons, add funds via UPI, and receive purchased keys. It includes a full admin panel for managing products, reordering items, setting reseller prices, viewing and removing key stock, configuring UPI payment details and update links, and checking user balances. Co-admins and resellers are supported, and support tickets are forwarded to the admin.

Commercedigital_storeadmin_panelupi_paymentsresellercouponskey_stock
ProfileTelegram
146 commands0 envUpdated 2d agoCreated Sep 5, 2026
Back to folder

commands/_onCheck.js

javascript · 319 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    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    // 🎁 REFER & EARN — referrer bonus jab referred friend PEHLI baar164    // 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") || "8477746023";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 199      // Optional fund group/channel announcement.200      var fundGroupIdAuto = Bot.getProperty("fund_group_id") || Bot.getProperty("sale_channel_id");201      if (fundGroupIdAuto) {202        Api.sendMessage({203          chat_id: fundGroupIdAuto,204          text: "<blockquote><tg-emoji emoji-id='6194922667242429131'>🎉</tg-emoji> <b>NEW FUND ADDED</b> <tg-emoji emoji-id='6266967801580231067'>💎</tg-emoji></blockquote>\n\n"+205            "<tg-emoji emoji-id='6145572393499762737'>👤</tg-emoji> <b>User:</b> " + (typeof user !== "undefined" && user && user.username ? "@"+user.username : senderName) + " (<code>"+targetUserId+"</code>)\n"+206            "<tg-emoji emoji-id='6267068789146260253'>💰</tg-emoji> <b>Amount:</b> ₹<code>"+addedAmount.toFixed(2)+"</code>\n"+207            "<tg-emoji emoji-id='5330237710655306682'>🧾</tg-emoji> <b>UTR:</b> <code>"+utr+"</code>\n"+208            "<tg-emoji emoji-id='6215386799133433653'>✅</tg-emoji> <b>Status:</b> Auto Verified",209          parse_mode:"HTML"210        });211      }212    } catch (e) {}213 214    if (queryId) {215      try {216        Api.answerCallbackQuery({217          callback_query_id: queryId,218          text: "✅ PAYMENT VERIFIED SUCCESSFULLY!",219          show_alert: false220        });221      } catch (e) {}222    }223 224    if (targetUserId) {225      vanishQrMessage(targetUserId, chatId);226      clearQrState(targetUserId);227    }228 229    if (User.getProperty("buy_reseller_upgrade")) {230      let resellerPrice = Number(User.getProperty("buy_reseller_price") || 0);231      User.setProperty("buy_reseller_upgrade", null, "boolean");232      User.setProperty("buy_reseller_price", null, "number");233 234      Bot.setProperty("is_reseller_" + targetUserId, true, "boolean");235 236      Api.sendMessage({237        chat_id: chatId,238        text: "<blockquote><tg-emoji emoji-id='6102856637343600044'>🎉</tg-emoji> <b>CONGRATULATIONS!</b></blockquote>\n\n" +239              "<tg-emoji emoji-id='6215386799133433653'>👑</tg-emoji> <b>You are now a Reseller!</b>\n\n" +240              "<i>Payment verified aur permanent reseller status activate ho gaya!</i>",241        parse_mode: "HTML",242        reply_markup: JSON.stringify({ inline_keyboard: [[{ text: "Explore Shop", callback_data: "/buy_hack", style: "success" }]] })243      });244 245      if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");246      return;247    }248 249    let pendingProdIdx = User.getProperty("buy_prod_idx");250    let pendingPlanIdx = User.getProperty("buy_plan_idx");251 252    if (pendingProdIdx !== null && pendingProdIdx !== undefined && pendingProdIdx !== "" &&253        pendingPlanIdx !== null && pendingPlanIdx !== undefined && pendingPlanIdx !== "") {254 255      Api.sendMessage({ 256        chat_id: chatId, 257        text: e_check + " <b>Payment verified! Generating your key now...</b>", 258        parse_mode: "HTML" 259      });260 261      Bot.run({262        command: "/confirm_buyitem",263        options: { params: pendingProdIdx + " " + pendingPlanIdx }264      });265 266      User.setProperty("buy_prod_idx", null);267      User.setProperty("buy_plan_idx", null);268      User.setProperty("buy_price", null);269      User.setProperty("buy_needpay", null);270 271      if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");272      return;273    }274 275    let successText = "━━━━━━━━━━━━━━━━━━━━\n" +276                      e_plus + " <b>PAYMENT SUCCESSFUL</b> " + e_plus + "\n" +277                      "━━━━━━━━━━━━━━━━━━━━\n\n" +278                      e_money + " <b>Added Amount:</b> ₹<b>" + addedAmount.toFixed(2) + "</b>\n" +279                      e_chart + " <b>New Balance:</b> ₹<b>" + newBalance.toFixed(2) + "</b>\n" +280                      e_arrow + " <b>UTR / Ref ID:</b> <code>" + utr + "</code>\n" +281                      e_time + " <b>Time:</b> " + payTime + "\n\n" +282                      "━━━━━━━━━━━━━━━━━━━━\n" +283                      e_coin + " <i>Your funds have been successfully credited! 🎉</i>";284 285    Api.sendMessage({286      chat_id: chatId,287      text: successText,288      parse_mode: "HTML",289      reply_markup: JSON.stringify({290        inline_keyboard: [[291          { text: "🛒 Shop Now", callback_data: "/buy_hack", style: "success" },292          { text: "🔰 Profile", callback_data: "/profile", style: "primary" }293        ]]294      })295    });296 297    if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");298    return;299  }300 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.",306        show_alert: true307      });308    } catch (e) {}309  }310 311  if (targetUserId) User.setProperty("topup_verifying_lock_" + targetUserId, false, "boolean");312 313} catch (err) {314  try {315    let uid = (typeof user !== "undefined" && user) ? user.telegramid : null;316    if (uid) User.setProperty("topup_verifying_lock_" + uid, false, "boolean");317  } catch (e) {}318  Bot.sendMessage("⚠️ Error in verification check: " + err.message);319}