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/_pay_upi.js
javascript Β· 202 lines
1/**#command2name: /pay_upi3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12/**#command13name: /pay_upi14answer: 15keyboard: 16parse_mode: markdown17aliases: 18allow_only_group: false19need_reply: false20case_insensitive: false21is_web: 022#command**/23 24// =========================================================25// π³ "Pay via UPI" button β generates the shortfall QR26// (this used to be inline inside buyitem.js; moved here since buyitem.js27// now always shows the Payment Method screen first)28// =========================================================29 30try {31 32 // π PANEL MAINTENANCE GUARD33 // Re-check at every purchase/payment stage so an admin can switch a panel34 // OFF even if a user already opened the checkout screen.35 function isPanelUnderMaintenance(product) {36 if (!product) return false;37 var mKey = "panel_maintenance_" +38 String(product.id || product.name || "").toUpperCase().replace(/[^A-Z0-9_-]/g, "_");39 return Bot.getProperty(mKey) === true;40 }41 42 var productList = Bot.getProperty("stored_products") || [];43 var callbackId = (request && request.id) ? request.id : ((request && request.callback_query && request.callback_query.id) || null);44 var chatId = chat.chatid;45 var userId = user.telegramid;46 47 var parts = params ? String(params).trim().split(" ") : [];48 var prodIdx = Number(parts[0]);49 var planIdx = Number(parts[1]);50 51 var product = productList[prodIdx];52 // π PANEL MAINTENANCE CHECK53 var panelMaintenanceKey = "panel_maintenance_" +54 String(product && (product.id || product.name) || prodIdx).toUpperCase().replace(/[^A-Z0-9_-]/g, "_");55 if (product && Bot.getProperty(panelMaintenanceKey) === true) {56 var maintenanceText = "π <b>PANEL UNDER MAINTENANCE</b>\n\n" +57 "π¦ <b>Panel:</b> <code>" + String(product.name || "Product") + "</code>\n\n" +58 "β³ Purchase/payment is temporarily disabled for this panel.\nPlease try again later.";59 var maintenanceCb = (request && request.id) ? request.id : ((request && request.callback_query && request.callback_query.id) || null);60 if (maintenanceCb) {61 try { Api.answerCallbackQuery({ callback_query_id: String(maintenanceCb), text: "π Panel is under maintenance", show_alert: true }); } catch (e) {}62 }63 if (request && request.message && request.message.message_id) {64 try {65 Api.editMessageText({66 chat_id: String(chatId),67 message_id: Number(request.message.message_id),68 text: maintenanceText,69 parse_mode: "HTML",70 reply_markup: JSON.stringify({ inline_keyboard: [[71 { text: "β¬
οΈ Back to Shop", callback_data: "/buy_hack", style: "danger", icon_custom_emoji_id: "5893163582194978381" }72 ]] })73 });74 } catch (e) {75 Api.sendMessage({ chat_id: String(chatId), text: maintenanceText, parse_mode: "HTML" });76 }77 } else {78 Api.sendMessage({ chat_id: String(chatId), text: maintenanceText, parse_mode: "HTML" });79 }80 return;81 }82 83 if (!product || !product.plans || !product.plans[planIdx]) {84 Bot.sendMessage("β Product or Plan configuration missing!");85 return;86 }87 88 var plan = product.plans[planIdx];89 var planUnit = plan.unit || "day";90 var cleanPlanDays = String(plan.days).replace(/[^0-9.]/g, "").trim();91 92 var unifiedBal = (function () {93 var resBal = 0;94 try { resBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (e) {}95 var bonusBal = Number(Bot.getProperty("balance" + userId) || 0);96 return resBal + bonusBal;97 })();98 99 var isReseller = Bot.getProperty("is_reseller_" + userId) === true;100 var cleanProdName = product.name.trim().toUpperCase();101 var priceKeySuffix = (planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_" + planUnit);102 var normalKey = "price_normal_" + cleanProdName + "_" + priceKeySuffix;103 var resellerKey = "price_reseller_" + cleanProdName + "_" + priceKeySuffix;104 105 var adminNormalPrice = Bot.getProperty(normalKey);106 var adminResellerPrice = Bot.getProperty(resellerKey);107 var currentNormal = (adminNormalPrice !== undefined && adminNormalPrice !== null) ? adminNormalPrice : plan.normal_price;108 var currentReseller = (adminResellerPrice !== undefined && adminResellerPrice !== null) ? adminResellerPrice : plan.reseller_price;109 var basePrice = isReseller ? Number(currentReseller) : Number(currentNormal);110 var memberPriceKey = "member_custom_price_" + userId + "_" + cleanProdName.replace(/[^A-Z0-9_-]/g, "_") + "_" + ((planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_hour"));111 var memberCustomPrice = Bot.getProperty(memberPriceKey);112 var hasMemberCustomPrice = memberCustomPrice !== undefined && memberCustomPrice !== null && isFinite(Number(memberCustomPrice));113 var originalPrice = hasMemberCustomPrice ? Number(memberCustomPrice) : basePrice;114 var price = originalPrice;115 116 var planSpecificDiscKey = "auto_discount_" + cleanProdName + "_" + cleanPlanDays + "_" + planUnit.toUpperCase();117 var productWideDiscKey = "auto_discount_" + cleanProdName + "_ALL";118 var autoDiscountPercent = Bot.getProperty(planSpecificDiscKey) || Bot.getProperty(productWideDiscKey) || Bot.getProperty("auto_discount_global") || 0;119 120 var appliedCouponCode = User.getProperty("applied_coupon_" + prodIdx + "_" + planIdx);121 if (appliedCouponCode) {122 var couponRec = Bot.getProperty("coupon_" + appliedCouponCode);123 if (couponRec && couponRec.discountPercent) {124 price = Number((originalPrice * (1 - couponRec.discountPercent / 100)).toFixed(2));125 }126 } else if (autoDiscountPercent > 0) {127 price = Number((originalPrice * (1 - autoDiscountPercent / 100)).toFixed(2));128 }129 130 var needToPay = Math.max(price - unifiedBal, 0);131 if (needToPay <= 0) { needToPay = price; } // safety fallback132 133 // β
Product context save karo taaki /onCheck payment verify hone ke baad134 // is exact plan ko khud-ba-khud (bina dobara confirm maange) purchase kar de.135 User.setProperty("last_selected_prod_idx", prodIdx);136 User.setProperty("last_selected_plan_idx", planIdx);137 138 User.setProperty("buy_prod_idx", prodIdx, "number");139 User.setProperty("buy_plan_idx", planIdx, "number");140 User.setProperty("buy_price", Number(price), "number");141 User.setProperty("buy_needpay", Number(needToPay), "number");142 User.setProperty("buy_prod_name", String(product.name).trim(), "string");143 User.setProperty("buy_plan_days", cleanPlanDays, "string");144 145 var genText = "<tg-emoji emoji-id='6147936236125298267'>β³</tg-emoji> <b>Creating order for βΉ" +146 needToPay.toFixed(2) + ", please wait...</b>";147 148 if (request && request.message) {149 Api.editMessageText({150 chat_id: String(chatId),151 message_id: Number(request.message.message_id),152 text: genText,153 parse_mode: "HTML"154 });155 // β
FIX: is "Creating order..." message ka ID save karo taaki QR photo156 // aane par ye properly delete (vanish) ho jaaye β pehle ye chat me stuck157 // reh jaata tha kyunki iska ID kahi track hi nahi hota tha.158 try {159 Bot.setProperty("gen_msg_id_" + userId, request.message.message_id, "string");160 User.setProperty("gen_msg_id_" + userId, request.message.message_id, "string");161 } catch (e) {}162 } else {163 var genMsg = Api.sendMessage({ chat_id: chatId, text: genText, parse_mode: "HTML" });164 try {165 var gmid = (genMsg && genMsg.result && genMsg.result.message_id) ? genMsg.result.message_id : (genMsg && genMsg.message_id ? genMsg.message_id : null);166 if (gmid) {167 Bot.setProperty("gen_msg_id_" + userId, gmid, "string");168 User.setProperty("gen_msg_id_" + userId, gmid, "string");169 }170 } catch (e) {}171 }172 173 var exactPayAmount = Number(needToPay.toFixed(2));174 var gramApiKey = String(Bot.getProperty("gramupi_api_key") || "").trim();175 if (!gramApiKey) {176 Bot.sendMessage("β Gram UPI Gateway API Key configured nahi hai.", {parse_mode:"HTML"});177 return;178 }179 180 User.setProperty("buy_expected_amount", exactPayAmount, "number");181 User.setProperty("pending_pay_amount_" + userId, exactPayAmount.toFixed(2), "string");182 183 HTTP.get({184 url: "https://gateway.anujbots.in/autoqr.php?api_key=" + encodeURIComponent(String(gramApiKey)) + "&amount=" + encodeURIComponent(String(exactPayAmount)),185 success: "/onBuyQR",186 error: "/onApiError"187 });188 189 if (callbackId) {190 Api.answerCallbackQuery({191 callback_query_id: String(callbackId),192 text: "β³ Generating QR...",193 show_alert: false194 });195 }196 197} catch (e) {198 var errChatId = (typeof chat !== "undefined" && chat && chat.chatid) ? chat.chatid : null;199 if (errChatId) {200 try { Api.sendMessage({ chat_id: errChatId, text: "β <b>Error:</b> <code>" + e.message + "</code>", parse_mode: "HTML" }); } catch (fatal) {}201 }202}