indrajitghosh20006/Igstore_01botPublic Β· Bot Template

ProfileTelegram

AIThe bot provides an admin interface for a digital store, allowing the owner or co‑admins to add balances, products, plans, and categories. It supports payment workflows via UPI and Binance Pay, automatically generating QR codes and handling manual approval of deposits. The code patches inline keyboards to use premium emoji icons and includes helper functions for user and bot properties. Overall, it serves as a commerce management tool for a Telegram-based storefront.

Commercestoreadminbalanceproductplancategory
170 commands0 envUpdated 7h agoCreated Oct 30, 2026
Back to folder

commands/_confirm_reseller_upgrade.js

javascript Β· 155 lines

Raw
1/**#command2name: /confirm_reseller_upgrade3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12/**#command13name: /confirm_reseller_upgrade14answer: 15keyboard: 16parse_mode: markdown17aliases: 18allow_only_group: false19need_reply: 020case_insensitive: false21is_web: 022#command**/23 24/**#command25name: /confirm_reseller_upgrade26answer: 27keyboard: 28parse_mode: markdown29aliases: 30allow_only_group: false31need_reply: false32case_insensitive: false33is_web: 034#command**/35 36// =========================================================37// πŸ‘‘ Reseller Upgrade β€” Confirm button handler38// Balance sufficient -> instant upgrade. Insufficient -> shortfall QR39// (payment completion handled automatically in _onCheck.js).40// =========================================================41 42try {43  var userId = String(user.telegramid);44  var chatId = chat.chatid;45  var confirmQueryId = request ? (request.id || (request.callback_query && request.callback_query.id)) : null;46  if (confirmQueryId) { try { Api.answerCallbackQuery({ callback_query_id: String(confirmQueryId), text: "Processing reseller upgrade..." }); } catch (ackErr) {} }47 48  if (Bot.getProperty("is_reseller_" + userId)) {49    Bot.sendMessage("πŸ’Ž Aap already ek Reseller hain!");50    return;51  }52 53  var price = Number(Bot.getProperty("reseller_upgrade_price") || Bot.getProperty("reseller_price") || 0);54  if (!price) {55    Bot.sendMessage("❌ Reseller Upgrade price admin ne abhi set nahi kiya.");56    return;57  }58 59  var unifiedBal = (function () {60    var resBal = 0;61    try { resBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (e) {}62    var bonusBal = Number(Bot.getProperty("balance" + userId) || 0);63    return resBal + bonusBal;64  })();65 66  function grantReseller(chatIdTarget) {67    Bot.setProperty("is_reseller_" + userId, true, "boolean");68    try {69      var resellerList = Bot.getProperty("resellers_list") || [];70      if (!Array.isArray(resellerList)) resellerList = [];71      if (resellerList.map(function(x){ return String(x); }).indexOf(String(userId)) === -1) resellerList.push(String(userId));72      Bot.setProperty("resellers_list", resellerList, "json");73      Bot.setProperty("reseller_fee_paid_" + userId, price, "number");74    } catch (listErr) {}75    var congratsText =76      "<blockquote>πŸŽ‰ <b>CONGRATULATIONS!</b></blockquote>\n\n" +77      "πŸ‘‘ <b>You are now a Reseller!</b>\n\n" +78      "<i>Aapko ab har product/plan par reseller pricing milegi, priority processing, aur reseller-only stock ka access. Enjoy your upgraded status!</i>";79    Api.sendMessage({80      chat_id: chatIdTarget,81      text: congratsText,82      parse_mode: "HTML",83      reply_markup: JSON.stringify({ inline_keyboard: [[{ text: "Explore Shop", callback_data: "/buy_hack" }]] })84    });85 86    var ownerId = Bot.getProperty("owner_id") || "7839151435";87    try {88      Api.sendMessage({89        chat_id: ownerId,90        text: "πŸ‘‘ <b>NEW RESELLER!</b>\nπŸ‘€ <b>User:</b> <code>" + userId + "</code>\nπŸ’° <b>Paid:</b> β‚Ή" + price.toFixed(2),91        parse_mode: "HTML"92      });93    } catch (e) {}94  }95 96  if (unifiedBal >= price) {97    // Deduct from the same combined wallet shown to the user: primary balance first,98    // then the secondary/bonus balance. This prevents negative balance and mismatch.99    var primaryBal = 0;100    try { primaryBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (eBal) {}101    var bonusBalNow = Number(Bot.getProperty("balance" + userId) || 0);102    var fromPrimary = Math.min(primaryBal, price);103    var fromBonus = price - fromPrimary;104    try {105      if (fromPrimary > 0) Libs.ResourcesLib.userRes("balance").add(-fromPrimary);106      if (fromBonus > 0) Bot.setProperty("balance" + userId, Math.max(0, bonusBalNow - fromBonus), "number");107      grantReseller(chatId);108    } catch (deductErr) {109      Bot.sendMessage("❌ Upgrade could not be completed safely. Please contact support before trying again.");110      return;111    }112  } else {113    var needToPay = price - unifiedBal;114    User.setProperty("buy_reseller_upgrade", true, "boolean");115    User.setProperty("buy_reseller_price", price, "number");116 117    var genText = "⏳ <b>Creating order for β‚Ή" + needToPay.toFixed(2) + ", please wait...</b>";118    if (request && request.message) {119      Api.editMessageText({ chat_id: String(chatId), message_id: Number(request.message.message_id), text: genText, parse_mode: "HTML" });120      try {121        Bot.setProperty("gen_msg_id_" + userId, request.message.message_id, "string");122        User.setProperty("gen_msg_id_" + userId, request.message.message_id, "string");123      } catch (e) {}124    } else {125      var genMsg = Api.sendMessage({ chat_id: chatId, text: genText, parse_mode: "HTML" });126      try {127        var gmid = (genMsg && genMsg.result && genMsg.result.message_id) ? genMsg.result.message_id : (genMsg && genMsg.message_id ? genMsg.message_id : null);128        if (gmid) {129          Bot.setProperty("gen_msg_id_" + userId, gmid, "string");130          User.setProperty("gen_msg_id_" + userId, gmid, "string");131        }132      } catch (e) {}133    }134 135    var apiKey = (function(){ var k = Bot.getProperty("gramupi_api_key"); k = k == null ? "" : String(k).trim(); k = k.replace(/^([`\"])(.*)\1$/, "$2").trim(); return k; })();136    if (!apiKey) {137      Bot.sendMessage("❌ Gram UPI Gateway API Key configured nahi hai. Admin Panel β†’ Set Payment ( UPI + Gram UPI Gateway ) se set karein.", {parse_mode:"HTML"});138      return;139    }140    var exactUpgradeAmount = Number(needToPay.toFixed(2));141    User.setProperty("buy_expected_amount", exactUpgradeAmount, "number");142    User.setProperty("pending_pay_amount_" + userId, exactUpgradeAmount.toFixed(2), "string");143    HTTP.get({144      url: "https://gateway.anujbots.in/autoqr.php?api_key=" + encodeURIComponent(String(apiKey)) + "&amount=" + encodeURIComponent(String(exactUpgradeAmount)),145      success: "/onQR",146      error: "/onApiError"147  });148  }149 150  var queryId = request ? (request.id || (request.callback_query && request.callback_query.id)) : null;151  if (queryId) { try { Api.answerCallbackQuery({ callback_query_id: String(queryId) }); } catch (e) {} }152 153} catch (err) {154  Bot.sendMessage("⚠️ Error: " + err.message);155}