indrajitghosh20006/Igstore_01botPublic Β· Bot Template
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 8h agoCreated Oct 30, 2026
commands/_buyitem.js
javascript Β· 258 lines
1/**#command2name: /buyitem3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// PREMIUM BUTTON ICONS13(function(){14 try {15 if (!JSON.__premiumPatched) {16 var __origStringify = JSON.stringify;17 JSON.stringify = function(value, replacer, space) {18 try {19 if (value && value.inline_keyboard && Array.isArray(value.inline_keyboard)) {20 var premiumIds = [21 "6143444134125379822",22 "6091379307907652768",23 "6147534454819661264",24 "6147817325660741985",25 "6235683689292897318",26 "6102856637343600044"27 ];28 var rows = value.inline_keyboard.map(function(row, ri) {29 if (!Array.isArray(row)) return row;30 return row.map(function(btn, bi) {31 if (!btn || typeof btn !== "object") return btn;32 var copy = {};33 for (var k in btn) copy[k] = btn[k];34 if (!copy.icon_custom_emoji_id) copy.icon_custom_emoji_id = premiumIds[(ri + bi) % premiumIds.length];35 return copy;36 });37 });38 var cloned = {};39 for (var key in value) cloned[key] = value[key];40 cloned.inline_keyboard = rows;41 return __origStringify.call(JSON, cloned, replacer, space);42 }43 } catch (e) {}44 return __origStringify.call(JSON, value, replacer, space);45 };46 JSON.__premiumPatched = true;47 }48 } catch (e) {}49})();50 51 52 53// =========================================================54// π PLAN CLICK HANDLER β Premium "Payment Method" confirmation screen55// (Pay from Wallet / Pay via UPI / Apply Coupon / Back to Shop)56// β
Supports Hour / Minute / Day duration units57// β
Supports coupon discounts (global or product-specific)58// =========================================================59 60try {61 62 // π PANEL MAINTENANCE GUARD63 // Re-check at every purchase/payment stage so an admin can switch a panel64 // OFF even if a user already opened the checkout screen.65 function isPanelUnderMaintenance(product) {66 if (!product) return false;67 var mKey = "panel_maintenance_" +68 String(product.id || product.name || "").toUpperCase().replace(/[^A-Z0-9_-]/g, "_");69 return Bot.getProperty(mKey) === true;70 }71 72 var productList = Bot.getProperty("stored_products") || [];73 var callbackId = (request && request.id) ? request.id : ((request && request.callback_query && request.callback_query.id) || null);74 var chatId = chat.chatid;75 var userId = user.telegramid;76 77 var parts = params ? params.split(" ") : [];78 if (parts.length < 2) {79 var cbData = (request && request.callback_query) ? request.callback_query.data : "";80 parts = cbData.replace("buyitem ", "").split(" ");81 }82 83 var prodIdx = Number(parts[0]);84 var planIdx = Number(parts[1]);85 86 var product = productList[prodIdx];87 // π PANEL MAINTENANCE CHECK88 var panelMaintenanceKey = "panel_maintenance_" +89 String(product && (product.id || product.name) || prodIdx).toUpperCase().replace(/[^A-Z0-9_-]/g, "_");90 if (product && Bot.getProperty(panelMaintenanceKey) === true) {91 var maintenanceText = "π <b>PANEL UNDER MAINTENANCE</b>\n\n" +92 "π¦ <b>Panel:</b> <code>" + String(product.name || "Product") + "</code>\n\n" +93 "β³ Purchase/payment is temporarily disabled for this panel.\nPlease try again later.";94 var maintenanceCb = (request && request.id) ? request.id : ((request && request.callback_query && request.callback_query.id) || null);95 if (maintenanceCb) {96 try { Api.answerCallbackQuery({ callback_query_id: String(maintenanceCb), text: "π Panel is under maintenance", show_alert: true }); } catch (e) {}97 }98 if (request && request.message && request.message.message_id) {99 try {100 Api.editMessageText({101 chat_id: String(chatId),102 message_id: Number(request.message.message_id),103 text: maintenanceText,104 parse_mode: "HTML",105 reply_markup: JSON.stringify({ inline_keyboard: [[106 { text: "β¬
οΈ Back to Shop", callback_data: "/buy_hack", style: "danger", icon_custom_emoji_id: "5893163582194978381" }107 ]] })108 });109 } catch (e) {110 Api.sendMessage({ chat_id: String(chatId), text: maintenanceText, parse_mode: "HTML" });111 }112 } else {113 Api.sendMessage({ chat_id: String(chatId), text: maintenanceText, parse_mode: "HTML" });114 }115 return;116 }117 118 if (!product || !product.plans || !product.plans[planIdx]) {119 Bot.sendMessage("β Product or Plan configuration missing!");120 return;121 }122 123 var plan = product.plans[planIdx];124 var planUnit = plan.unit || "day";125 var cleanPlanDays = String(plan.days).replace(/[^0-9.]/g, "").trim();126 var unitLabelWord = (planUnit === "hour") ? (Number(cleanPlanDays) === 1 ? "Hour" : "Hours") :127 (planUnit === "minute") ? (Number(cleanPlanDays) === 1 ? "Minute" : "Minutes") :128 (Number(cleanPlanDays) === 1 ? "Day" : "Days");129 var durationDisplay = plan.durationDisplay || (cleanPlanDays + " " + unitLabelWord);130 131 var unifiedBal = (function () {132 var resBal = 0;133 try { resBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (e) {}134 var bonusBal = Number(Bot.getProperty("balance" + userId) || 0);135 return resBal + bonusBal;136 })();137 138 var isReseller = Bot.getProperty("is_reseller_" + userId) === true;139 var cleanProdName = product.name.trim().toUpperCase();140 141 // β
Unit-aware price key (Day plans keep the old key format for backward-compat)142 var priceKeySuffix = (planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_" + planUnit);143 var normalKey = "price_normal_" + cleanProdName + "_" + priceKeySuffix;144 var resellerKey = "price_reseller_" + cleanProdName + "_" + priceKeySuffix;145 146 var adminNormalPrice = Bot.getProperty(normalKey);147 var adminResellerPrice = Bot.getProperty(resellerKey);148 149 var currentNormal = (adminNormalPrice !== undefined && adminNormalPrice !== null) ? adminNormalPrice : plan.normal_price;150 var currentReseller = (adminResellerPrice !== undefined && adminResellerPrice !== null) ? adminResellerPrice : plan.reseller_price;151 152 var basePrice = isReseller ? Number(currentReseller) : Number(currentNormal);153 var memberPriceKey = "member_custom_price_" + userId + "_" + cleanProdName.replace(/[^A-Z0-9_-]/g, "_") + "_" + ((planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_hour"));154 var memberCustomPrice = Bot.getProperty(memberPriceKey);155 var hasMemberCustomPrice = memberCustomPrice !== undefined && memberCustomPrice !== null && isFinite(Number(memberCustomPrice));156 var originalPrice = hasMemberCustomPrice ? Number(memberCustomPrice) : basePrice;157 var price = originalPrice;158 159 // πΈ Auto-discount (admin-set, no coupon code needed) β plan-specific > product-wide > global160 var planSpecificDiscKey = "auto_discount_" + cleanProdName + "_" + cleanPlanDays + "_" + planUnit.toUpperCase();161 var productWideDiscKey = "auto_discount_" + cleanProdName + "_ALL";162 var autoDiscountPercent = Bot.getProperty(planSpecificDiscKey) || Bot.getProperty(productWideDiscKey) || Bot.getProperty("auto_discount_global") || 0;163 164 // π Coupon check (if user applied one for this exact prod/plan) β coupon overrides auto-discount165 var appliedCouponCode = User.getProperty("applied_coupon_" + prodIdx + "_" + planIdx);166 var couponDiscountPercent = 0;167 if (appliedCouponCode) {168 var couponRec = Bot.getProperty("coupon_" + appliedCouponCode);169 if (couponRec && couponRec.discountPercent) {170 couponDiscountPercent = couponRec.discountPercent;171 price = Number((originalPrice * (1 - couponDiscountPercent / 100)).toFixed(2));172 }173 } else if (autoDiscountPercent > 0) {174 couponDiscountPercent = autoDiscountPercent; // reuse the same display variable175 price = Number((originalPrice * (1 - autoDiscountPercent / 100)).toFixed(2));176 }177 178 // π PREMIUM EMOJI SET (verified valid custom-emoji IDs from your reference bot)179 var e_diamond = "<tg-emoji emoji-id='6266967801580231067'>π</tg-emoji>";180 var e_pack = "<tg-emoji emoji-id='6147767796097884213'>π¦</tg-emoji>";181 var e_hour = "<tg-emoji emoji-id='6147565374289220368'>β±οΈ</tg-emoji>";182 var e_tag = "<tg-emoji emoji-id='6147565374289220368'>π²</tg-emoji>";183 var e_wallet = "<tg-emoji emoji-id='5348392971207194994'>π³</tg-emoji>";184 var e_check = "<tg-emoji emoji-id='6100657257605763582'>βοΈ</tg-emoji>";185 var e_offer = "<tg-emoji emoji-id='6102856637343600044'>π</tg-emoji>";186 var e_lock = "<tg-emoji emoji-id='6215386799133433653'>π</tg-emoji>";187 var e_coupon = "<tg-emoji emoji-id='6093677128295914531'>π«</tg-emoji>";188 var e_back = "<tg-emoji emoji-id='5893163582194978381'>β¬
οΈ</tg-emoji>";189 190 var priceLine;191 if (couponDiscountPercent > 0) {192 priceLine = e_tag + " <b>Price:</b> <s>βΉ" + originalPrice.toFixed(2) + "</s> β <b>βΉ" + price.toFixed(2) + "</b> " + e_offer + " <b>-" + couponDiscountPercent + "%</b>";193 } else if (hasMemberCustomPrice && Number(basePrice) !== Number(originalPrice)) {194 priceLine = e_tag + " <b>Member Price:</b> <s>βΉ" + Number(basePrice).toFixed(2) + "</s> β <b>βΉ" + price.toFixed(2) + "</b> π€";195 } else {196 priceLine = e_tag + " <b>Price:</b> βΉ<code>" + price.toFixed(2) + "</code>";197 }198 199 // =====================================================200 // π PREMIUM CHECKOUT SCREEN β always shown on plan click201 // =====================================================202 var confirmText =203 "<blockquote>" + e_diamond + " <b>CONFIRM YOUR ORDER</b> " + e_diamond + "</blockquote>\n" +204 "βββββββββββββββββββββ\n\n" +205 e_pack + " <b>Product:</b> " + product.name + "\n" +206 e_hour + " <b>Duration:</b> " + durationDisplay + "\n" +207 priceLine + "\n" +208 e_wallet + " <b>Wallet Balance:</b> βΉ<code>" + unifiedBal.toFixed(2) + "</code>\n\n" +209 "βββββββββββββββββββββ\n" +210 e_lock + " <i>Secure checkout β choose a payment method below</i> " + e_check;211 212 var confirmButtons = [];213 214 if (unifiedBal >= price) {215 confirmButtons.push([216 { text: "Pay βΉ" + price.toFixed(2) + " from Wallet", callback_data: "/confirm_buyitem " + prodIdx + " " + planIdx, style: "success", icon_custom_emoji_id: "6100657257605763582" }217 ]);218 } else {219 var needToPayPreview = (price - unifiedBal).toFixed(2);220 confirmButtons.push([221 { text: "Pay βΉ" + needToPayPreview + " via UPI", callback_data: "/pay_upi " + prodIdx + " " + planIdx, style: "success", icon_custom_emoji_id: "5348392971207194994" }222 ]);223 }224 225 confirmButtons.push([226 { text: "Apply Coupon Code", callback_data: "/apply_coupon " + prodIdx + " " + planIdx, style: "primary", icon_custom_emoji_id: "6093677128295914531" }227 ]);228 confirmButtons.push([229 { text: "Back to Shop", callback_data: "/buy_hack", style: "danger", icon_custom_emoji_id: "5893163582194978381" }230 ]);231 232 if (request && request.message) {233 Api.editMessageText({234 chat_id: String(chatId),235 message_id: Number(request.message.message_id),236 text: confirmText,237 parse_mode: "HTML",238 reply_markup: JSON.stringify({ inline_keyboard: confirmButtons })239 });240 } else {241 Api.sendMessage({242 chat_id: String(chatId),243 text: confirmText,244 parse_mode: "HTML",245 reply_markup: JSON.stringify({ inline_keyboard: confirmButtons })246 });247 }248 249 if (callbackId) {250 Api.answerCallbackQuery({ callback_query_id: String(callbackId) });251 }252 253} catch (e) {254 var errChatId = (typeof chat !== "undefined" && chat && chat.chatid) ? chat.chatid : null;255 if (errChatId) {256 try { Api.sendMessage({ chat_id: errChatId, text: "β <b>Error:</b> <code>" + e.message + "</code>", parse_mode: "HTML" }); } catch (fatal) {}257 }258}