indrajitghosh20006/HgfhhuybotPublic · Bot Template

ProfileTelegram

AIThis bot provides a command‑based admin interface for managing user balances, products, and resellers. It supports adding balances via UPI or Binance Pay, approving payments, and configuring product details and categories. The bot also handles user role changes, stock uploads, and offers a simple calculator UI for entering amounts. All interactions are handled through short commands and inline keyboards, with no long‑running listeners or external frameworks.

Utilityadminbalanceproductresellerpaymentupi
138 commands0 envUpdated 15h agoCreated Sep 27, 2026
Back to folder

commands/_pay_upi.js

javascript · 136 lines

Raw
1/**#command2name: /pay_upi3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// =========================================================13// 💳 "Pay via UPI" button — generates the shortfall QR14// (this used to be inline inside buyitem.js; moved here since buyitem.js15// now always shows the Payment Method screen first)16// =========================================================17 18try {19  var productList = Bot.getProperty("stored_products") || [];20  var callbackId = (request && request.id) ? request.id : ((request && request.callback_query && request.callback_query.id) || null);21  var chatId = chat.chatid;22  var userId = user.telegramid;23 24  var parts = params ? String(params).trim().split(" ") : [];25  var prodIdx = Number(parts[0]);26  var planIdx = Number(parts[1]);27 28  var product = productList[prodIdx];29  if (!product || !product.plans || !product.plans[planIdx]) {30    Bot.sendMessage("❌ Product or Plan configuration missing!");31    return;32  }33 34  var plan = product.plans[planIdx];35  var planUnit = plan.unit || "day";36  var cleanPlanDays = String(plan.days).replace(/[^0-9.]/g, "").trim();37 38  var unifiedBal = (function () {39    var resBal = 0;40    try { resBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (e) {}41    return resBal;42  })();43 44  var isReseller = Bot.getProperty("is_reseller_" + userId) === true;45  var cleanProdName = product.name.trim().toUpperCase();46  var priceKeySuffix = (planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_" + planUnit);47  var normalKey = "price_normal_" + cleanProdName + "_" + priceKeySuffix;48  var resellerKey = "price_reseller_" + cleanProdName + "_" + priceKeySuffix;49 50  var adminNormalPrice = Bot.getProperty(normalKey);51  var adminResellerPrice = Bot.getProperty(resellerKey);52  var currentNormal = (adminNormalPrice !== undefined && adminNormalPrice !== null) ? adminNormalPrice : plan.normal_price;53  var currentReseller = (adminResellerPrice !== undefined && adminResellerPrice !== null) ? adminResellerPrice : plan.reseller_price;54  var originalPrice = isReseller ? Number(currentReseller) : Number(currentNormal);55  var price = originalPrice;56 57  var planSpecificDiscKey = "auto_discount_" + cleanProdName + "_" + cleanPlanDays + "_" + planUnit.toUpperCase();58  var productWideDiscKey = "auto_discount_" + cleanProdName + "_ALL";59  var autoDiscountPercent = Bot.getProperty(planSpecificDiscKey) || Bot.getProperty(productWideDiscKey) || Bot.getProperty("auto_discount_global") || 0;60 61  var appliedCouponCode = User.getProperty("applied_coupon_" + prodIdx + "_" + planIdx);62  if (appliedCouponCode) {63    var couponRec = Bot.getProperty("coupon_" + appliedCouponCode);64    if (couponRec && couponRec.discountPercent) {65      price = Number((originalPrice * (1 - couponRec.discountPercent / 100)).toFixed(2));66    }67  } else if (autoDiscountPercent > 0) {68    price = Number((originalPrice * (1 - autoDiscountPercent / 100)).toFixed(2));69  }70 71  var needToPay = Math.max(price - unifiedBal, 0);72  if (needToPay <= 0) { needToPay = price; } // safety fallback73 74  // ✅ Product context save karo taaki /onCheck payment verify hone ke baad75  // is exact plan ko khud-ba-khud (bina dobara confirm maange) purchase kar de.76  User.setProperty("last_selected_prod_idx", prodIdx);77  User.setProperty("last_selected_plan_idx", planIdx);78 79  User.setProperty("buy_prod_idx", prodIdx, "number");80  User.setProperty("buy_plan_idx", planIdx, "number");81  User.setProperty("buy_price", Number(price), "number");82  User.setProperty("buy_needpay", Number(needToPay), "number");83  User.setProperty("buy_prod_name", String(product.name).trim(), "string");84  User.setProperty("buy_plan_days", cleanPlanDays, "string");85 86  var genText = "<tg-emoji emoji-id='6147936236125298267'>⏳</tg-emoji> <b>Creating order for ₹" +87    needToPay.toFixed(2) + ", please wait...</b>";88 89  if (request && request.message) {90    Api.editMessageText({91      chat_id: String(chatId),92      message_id: Number(request.message.message_id),93      text: genText,94      parse_mode: "HTML"95    });96    // ✅ FIX: is "Creating order..." message ka ID save karo taaki QR photo97    // aane par ye properly delete (vanish) ho jaaye — pehle ye chat me stuck98    // reh jaata tha kyunki iska ID kahi track hi nahi hota tha.99    try {100      Bot.setProperty("gen_msg_id_" + userId, request.message.message_id, "string");101      User.setProperty("gen_msg_id_" + userId, request.message.message_id, "string");102    } catch (e) {}103  } else {104    var genMsg = Api.sendMessage({ chat_id: chatId, text: genText, parse_mode: "HTML" });105    try {106      var gmid = (genMsg && genMsg.result && genMsg.result.message_id) ? genMsg.result.message_id : (genMsg && genMsg.message_id ? genMsg.message_id : null);107      if (gmid) {108        Bot.setProperty("gen_msg_id_" + userId, gmid, "string");109        User.setProperty("gen_msg_id_" + userId, gmid, "string");110      }111    } catch (e) {}112  }113 114  var upi_id = Bot.getProperty("payment_upi_id") || "devreang@fam";115 116  HTTP.get({117    url: "https://fampay.anujbots.xyz/qr.php?upi=" + encodeURIComponent(upi_id) +118         "&amount=" + encodeURIComponent(needToPay.toFixed(2)),119    success: "/onQR",120    error: "/onApiError"121  });122 123  if (callbackId) {124    Api.answerCallbackQuery({125      callback_query_id: String(callbackId),126      text: "⏳ Generating QR...",127      show_alert: false128    });129  }130 131} catch (e) {132  var errChatId = (typeof chat !== "undefined" && chat && chat.chatid) ? chat.chatid : null;133  if (errChatId) {134    try { Api.sendMessage({ chat_id: errChatId, text: "❌ <b>Error:</b> <code>" + e.message + "</code>", parse_mode: "HTML" }); } catch (fatal) {}135  }136}