tarunpoonia905/OfcDevShopBotPublic · Bot Template

ProfileTelegram

AIDEV SHOP appears to be a Telegram automation bot. Commands include /confirm_delete_stock, /addstock_id, /extkey_menu, /partner_api, /apidelete, /buy_hack_cat, /admin_manage_products, /check_buy. Observed in code: messaging, keyboards, payments, libs, web, http, games.

Utilityutility
228 commands0 envUpdated 12d agoCreated Oct 18, 2026
Back to folder

commands/_pay_fampay.js

javascript · 255 lines

Raw
1/**#command2name: /pay_fampay3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12/*#SIZE_V1*/try{(function(){var z=Bot.getProperty("ui_btn_size");var mx=z==="large"?1:(z==="medium"?2:0);if(!mx||Api.__sz)return;var NAV=/^[◀▶⬅➡«»‹›⏪⏩]|\d+\s*\/\s*\d+|prev|next|page/i;var T=function(m){try{var o=typeof m==="string"?JSON.parse(m):m;if(!o||!o.inline_keyboard)return m;var out=[],cnt=0;o.inline_keyboard.forEach(function(row){var nav=row.some(function(b){return NAV.test(String(b.text||"").trim());});if(row.length<=mx||nav){out.push(row);cnt+=row.length;return;}for(var i=0;i<row.length;i+=mx){var c=row.slice(i,i+mx);out.push(c);cnt+=c.length;}});if(cnt>100||out.length>100)return m;o.inline_keyboard=out;return typeof m==="string"?JSON.stringify(o):o;}catch(e){return m;}};["sendMessage","editMessageText","editMessageCaption","editMessageReplyMarkup","sendPhoto","sendVideo","sendAnimation","sendDocument"].forEach(function(n){var f=Api[n];if(typeof f!=="function")return;Api[n]=function(p){try{if(p&&p.reply_markup)p.reply_markup=T(p.reply_markup);}catch(e){}return f.apply(Api,arguments);};});Api.__sz=true;})();}catch(__szE){}13/*#ANIM_V1*/try{(function(){var M={party:"5046509860389126442",fire:"5104841245755180586",heart:"5159385139981059251",like:"5107584321108051014"};var a=Bot.getProperty("ui_anim");if(!a||!M[a]||Api.__an)return;var E=M[a];var OK=/PURCHASE SUCCESSFUL|PAYMENT SUCCESSFUL|Payment verified|CONGRATULATIONS/i;var priv=function(p){return p&&p.chat_id&&String(p.chat_id).charAt(0)!=="-";};["sendMessage","sendPhoto","sendVideo","sendAnimation"].forEach(function(n){var f=Api[n];if(typeof f!=="function")return;Api[n]=function(p){try{if(priv(p)&&!p.message_effect_id&&OK.test(String(p.text||p.caption||"")))p.message_effect_id=E;}catch(e){}return f.apply(Api,arguments);};});var fe=Api.editMessageText;if(typeof fe==="function"){Api.editMessageText=function(p){var r=fe.apply(Api,arguments);try{if(priv(p)&&OK.test(String(p.text||"")))Api.sendMessage({chat_id:p.chat_id,text:"🎉",message_effect_id:E});}catch(e){}return r;};}Api.__an=true;})();}catch(__anE){}14/*#PREMIUM_UI_V1*/try{(function(){if(Bot.getProperty("ui_premium")!==true||Api.__pm)return;var R=function(t,c){var s=(String(t||"")+" "+String(c||"")).toLowerCase();if(/back|cancel|close|delete|remove|clear|reject|stop|ban|exit/.test(s))return"danger";if(/pay|buy|confirm|verify|paid|add|deposit|shop|claim|yes|receive|wallet|download|update/.test(s))return"success";return"primary";};var T=function(m){try{var o=typeof m==="string"?JSON.parse(m):m;if(!o||!o.inline_keyboard)return m;o.inline_keyboard.forEach(function(row){row.forEach(function(b){if(b.copy_text||b.url||b.callback_data||b.web_app){b.style=R(b.text,b.callback_data||b.url);if(!b.icon_custom_emoji_id&&b.text&&!/^[\u2600-\u27BF\uD83C-\uD83E]/.test(String(b.text).trim())&&!/^[✦✨💎]/.test(b.text))b.text="✦ "+b.text;}});});return typeof m==="string"?JSON.stringify(o):o;}catch(e){return m;}};["sendMessage","editMessageText","editMessageCaption","editMessageReplyMarkup","sendPhoto","sendVideo","sendAnimation","sendDocument"].forEach(function(n){var f=Api[n];if(typeof f!=="function")return;Api[n]=function(p){try{if(p&&p.reply_markup)p.reply_markup=T(p.reply_markup);}catch(e){}return f.apply(Api,arguments);};});Api.__pm=true;})();}catch(__pmE){}15 16 17// =========================================================18// 💳 "Pay via UPI" button — generates the shortfall QR19// (this used to be inline inside buyitem.js; moved here since buyitem.js20// now always shows the Payment Method screen first)21// =========================================================22 23try {24try { User.setProperty("buy_reseller_upgrade", null, "boolean"); try { Bot.setProperty("reseller_upg_" + user.telegramid, null, "number"); } catch (__ru) {} User.setProperty("buy_reseller_price", null, "number"); } catch (__rf) {}25 26 27  // 🛠 PANEL MAINTENANCE GUARD28  // Re-check at every purchase/payment stage so an admin can switch a panel29  // OFF even if a user already opened the checkout screen.30  function isPanelUnderMaintenance(product) {31    if (!product) return false;32    var mKey = "panel_maintenance_" +33      String(product.id || product.name || "").toUpperCase().replace(/[^A-Z0-9_-]/g, "_");34    return Bot.getProperty(mKey) === true;35  }36 37  var productList = Bot.getProperty("stored_products") || [];38  var callbackId = (request && request.id) ? request.id : ((request && request.callback_query && request.callback_query.id) || null);39  var chatId = chat.chatid;40  var userId = user.telegramid;41  var __rawP = (typeof options !== "undefined" && options && options.params !== undefined && options.params !== null) ? String(options.params) : String(typeof params !== "undefined" && params ? params : ""); /* Bot.run se aaye to options.params me hota hai */42  var parts = __rawP ? __rawP.trim().split(/\s+/) : [];43  var prodIdx = Number(parts[0]);44  var planIdx = Number(parts[1]);45 46  var product = productList[prodIdx];47  // 🛠 PANEL MAINTENANCE CHECK48  var panelMaintenanceKey = "panel_maintenance_" +49    String(product && (product.id || product.name) || prodIdx).toUpperCase().replace(/[^A-Z0-9_-]/g, "_");50  if (product && Bot.getProperty(panelMaintenanceKey) === true) {51    var maintenanceLink = String(product.maintenance_link || "").trim();52    var maintenanceText = "<tg-emoji emoji-id='6194949330399407789'>🛠️</tg-emoji> <b>Ye product abhi maintenance mein hai.</b>\n\n" +53      "<tg-emoji emoji-id='6215414866744712399'>📥</tg-emoji> <b>Update Files neeche open karo.</b>";54    var maintenanceMarkup = { inline_keyboard: [55      maintenanceLink56        ? [{ text: "Update Files", url: maintenanceLink, style: "success", icon_custom_emoji_id: "6143177515440544964" }]57        : [{ text: "⚠️ Update Link Not Set", callback_data: "/viewprod " + String(prodIdx), style: "danger" }],58      [{ text: "⬅️ Back to Shop", callback_data: "/buy_hack", style: "danger", icon_custom_emoji_id: "5893163582194978381" }]59    ] };60    if (request && request.message && request.message.message_id) {61      try {62        Api.editMessageText({63          chat_id: String(chatId),64          message_id: Number(request.message.message_id),65          text: maintenanceText,66          parse_mode: "HTML",67          reply_markup: JSON.stringify(maintenanceMarkup)68        });69      } catch (e) {70        Api.sendMessage({ chat_id: String(chatId), text: maintenanceText, parse_mode: "HTML", reply_markup: JSON.stringify(maintenanceMarkup) });71      }72    } else {73      Api.sendMessage({ chat_id: String(chatId), text: maintenanceText, parse_mode: "HTML", reply_markup: JSON.stringify(maintenanceMarkup) });74    }75    return;76  }77 78  if (!product || !product.plans || !product.plans[planIdx]) {79    Bot.sendMessage("❌ Product or Plan configuration missing!"); (function(){ try { var __pl = (typeof productList !== "undefined" && Array.isArray(productList)) ? productList : []; var __pr = (typeof prodIdx !== "undefined") ? prodIdx : "?"; var __pi = (typeof planIdx !== "undefined") ? planIdx : "?"; var __p = __pl[__pr]; var __own = String(Bot.getProperty("owner_id") || "7127818616"); Api.sendMessage({ chat_id: __own, text: "Config missing debug (" + "_pay_fampay.js" + ")\nuser: " + String(user.telegramid) + "\nprodIdx=" + __pr + " planIdx=" + __pi + "\nproduct=" + (__p ? String(__p.name) : "NOT FOUND") + " | plans=" + (__p && __p.plans ? __p.plans.length : "none") + " | totalProducts=" + __pl.length }); } catch (__dg) {} })();80    return;81  }82 83  var plan = product.plans[planIdx];84  var planUnit = plan.unit || "day";85  var cleanPlanDays = String(plan.days).replace(/[^0-9.]/g, "").trim();86 87  var unifiedBal = (function () {88    var resBal = 0;89    try { resBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (e) {}90    var bonusBal = Number(Bot.getProperty("balance" + userId) || 0);91    return resBal + bonusBal;92  })();93 94  var isReseller = Bot.getProperty("is_reseller_" + userId) === true;95  var cleanProdName = product.name.trim().toUpperCase();96  var priceKeySuffix = (planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_" + planUnit);97  var normalKey = "price_normal_" + cleanProdName + "_" + priceKeySuffix;98  var resellerKey = "price_reseller_" + cleanProdName + "_" + priceKeySuffix;99 100  var adminNormalPrice = Bot.getProperty(normalKey);101  var adminResellerPrice = Bot.getProperty(resellerKey);102  var currentNormal = (adminNormalPrice !== undefined && adminNormalPrice !== null) ? adminNormalPrice : plan.normal_price;103  var currentReseller = (adminResellerPrice !== undefined && adminResellerPrice !== null) ? adminResellerPrice : plan.reseller_price;104  var basePrice = isReseller ? Number(currentReseller) : Number(currentNormal);105  var memberPriceKey = "member_custom_price_" + userId + "_" + cleanProdName.replace(/[^A-Z0-9_-]/g, "_") + "_" + ((planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_hour"));106  var memberCustomPrice = Bot.getProperty(memberPriceKey);107  var hasMemberCustomPrice = memberCustomPrice !== undefined && memberCustomPrice !== null && isFinite(Number(memberCustomPrice));108  var originalPrice = hasMemberCustomPrice ? Number(memberCustomPrice) : basePrice;109  var price = originalPrice;110 111  var planSpecificDiscKey = "auto_discount_" + cleanProdName + "_" + cleanPlanDays + "_" + planUnit.toUpperCase();112  var productWideDiscKey = "auto_discount_" + cleanProdName + "_ALL";113  var autoDiscountPercent = Bot.getProperty(planSpecificDiscKey) || Bot.getProperty(productWideDiscKey) || Bot.getProperty("auto_discount_global") || 0;114 115  var appliedCouponCode = User.getProperty("applied_coupon_" + prodIdx + "_" + planIdx);116  // 🎟 Profile coupon (account-level): Profile > Apply Coupon me save hota hai, purchase par khud lagta hai.117  var __profileCouponUsed = false;118  if (!appliedCouponCode) {119    try {120      var __pc = User.getProperty("profile_coupon");121      var __pcRec = __pc ? Bot.getProperty("coupon_" + __pc) : null;122      if (__pcRec && !__pcRec.isPaused && __pcRec.discountPercent) {123        var __pcClaimed = Array.isArray(__pcRec.claimedBy) ? __pcRec.claimedBy : [];124        var __pcOk = __pcClaimed.indexOf(String(userId)) === -1 && __pcClaimed.length < Number(__pcRec.maxClaims || 0);125        if (__pcOk && __pcRec.scope === "specific") {126          __pcOk = String(__pcRec.productName || "").trim().toLowerCase() === String(product.name).trim().toLowerCase();127        }128        if (__pcOk) { appliedCouponCode = __pc; __profileCouponUsed = true; }129      }130    } catch (__pcErr) {}131  }132  if (appliedCouponCode) {133    var couponRec = Bot.getProperty("coupon_" + appliedCouponCode);134    if (couponRec && couponRec.discountPercent) {135      price = Number((originalPrice * (1 - couponRec.discountPercent / 100)).toFixed(2));136    }137  } else if (autoDiscountPercent > 0) {138    price = Number((originalPrice * (1 - autoDiscountPercent / 100)).toFixed(2));139  }140 141  var needToPay = Math.max(price - unifiedBal, 0);142  if (needToPay <= 0) { needToPay = price; } // safety fallback143 144  // ✅ Product context save karo taaki /onCheck payment verify hone ke baad145  // is exact plan ko khud-ba-khud (bina dobara confirm maange) purchase kar de.146  User.setProperty("last_selected_prod_idx", prodIdx);147  User.setProperty("last_selected_plan_idx", planIdx);148 149  User.setProperty("buy_prod_idx", prodIdx, "number");150  User.setProperty("buy_plan_idx", planIdx, "number");151  User.setProperty("buy_price", Number(price), "number");152  User.setProperty("buy_needpay", Number(needToPay), "number");153  User.setProperty("buy_prod_name", String(product.name).trim(), "string");154  User.setProperty("buy_plan_days", cleanPlanDays, "string");155 156  var genText = "<tg-emoji emoji-id='6147936236125298267'>⏳</tg-emoji> <b>Creating order for ₹" +157    needToPay.toFixed(2) + ", please wait...</b>";158 159  // Plan-list screen photo/video/GIF ho sakti hai -> text-edit nahi hota: delete + fresh send.160  var srcIsMedia = !!(request && request.message && (request.message.photo || request.message.video || request.message.animation || request.message.document));161  if (srcIsMedia) {162    try { Api.deleteMessage({ chat_id: String(chatId), message_id: Number(request.message.message_id) }); } catch (delMediaErr) {}163  }164  if (request && request.message && !srcIsMedia) {165    Api.editMessageText({166      chat_id: String(chatId),167      message_id: Number(request.message.message_id),168      text: genText,169      parse_mode: "HTML"170    });171    // ✅ FIX: is "Creating order..." message ka ID save karo taaki QR photo172    // aane par ye properly delete (vanish) ho jaaye — pehle ye chat me stuck173    // reh jaata tha kyunki iska ID kahi track hi nahi hota tha.174    try {175      Bot.setProperty("gen_msg_id_" + userId, request.message.message_id, "string");176      User.setProperty("gen_msg_id_" + userId, request.message.message_id, "string");177    } catch (e) {}178  } else {179    var genMsg = Api.sendMessage({ chat_id: chatId, text: genText, parse_mode: "HTML" });180    try {181      var gmid = (genMsg && genMsg.result && genMsg.result.message_id) ? genMsg.result.message_id : (genMsg && genMsg.message_id ? genMsg.message_id : null);182      if (gmid) {183        Bot.setProperty("gen_msg_id_" + userId, gmid, "string");184        User.setProperty("gen_msg_id_" + userId, gmid, "string");185      }186    } catch (e) {}187  }188 189  if (Bot.getProperty("gateway_fampay_enabled") !== true) {190    Bot.sendMessage("❌ FamPay gateway is currently disabled by admin.");191    return;192  }193 194  User.setProperty("buy_selected_gateway", "famgateway", "string");195  Bot.setProperty("pending_gateway_" + userId, "famgateway", "string");196  User.setProperty("pending_gateway_" + userId, "famgateway", "string");197 198  // FamGateway API v2: sirf API key chahiye (UPI ID dashboard me connected FamPay account se aata hai)199  var famApiKey = Bot.getProperty("fampay_merchant_key") || Bot.getProperty("fampay_api_key");200 201  if (!famApiKey) {202    Bot.sendMessage("⚠️ FamPay gateway abhi admin ne configure nahi kiya hai.");203    return;204  }205  var exactPayAmount = Number(needToPay.toFixed(2));206 207  // Lock the exact amount before QR generation. Verification later reads the208  // amount tied to the returned order ID, so a different payment cannot unlock209  // this purchase.210  User.setProperty("buy_expected_amount", exactPayAmount, "number");211  User.setProperty("pending_pay_amount_" + userId, exactPayAmount.toFixed(2), "string");212 213  // ✅ v8: per-order webhook_url (TeleBotHost signed user webhook). FamGateway payment hote hi isse POST karta hai.214  var famOrderBody = { amount: exactPayAmount.toFixed(2), customer_name: String(userId) };215  try {216    var famWebhookUrl = Webhook.getUrl("fam_webhook", { options: { uid: String(userId) }, expiresIn: 3600 });217    if (famWebhookUrl) famOrderBody.webhook_url = famWebhookUrl;218  } catch (whErr) { /* Webhook unavailable -> sirf Verify button se chalega */ }219 220  HTTP.post({221    url: "https://famgateway.in/api/create-order",222    headers: {223      "Content-Type": "application/json",224      "Authorization": "Bearer " + famApiKey,225      "X-Api-Key": famApiKey226    },227    body: JSON.stringify(famOrderBody),228    success: "/onQR",229    error: "/onApiError"230  });231  // ⏱ watchdog: gateway hang ho to user ko retry option (see /qr_timeout)232  // ✅ FIX: 30s bahut tight tha — FamGateway ka create-order kabhi kabhi isse233  // zyada lene laga hai, isliye users ko yeh scary "gateway respond nahi kar234  // raha" message dikh jata tha THEN QR khud aa jata tha thodi der baad —235  // confusing/broken lagta tha. 45s zyada realistic margin deta hai.236  try {237    var qrTs = String(new Date().getTime());238    Bot.setProperty("qr_gen_ts_" + userId, qrTs, "string");239    // (TeleBotHost Bot.run me run_after hota hi nahi — docs: command/options/user_id/chat_id/ignoreMissingCommand. Isliye delayed watchdog/poll hata diya.)240  } catch (wdErr) {}241 242  if (callbackId) {243    Api.answerCallbackQuery({244      callback_query_id: String(callbackId),245      text: "⏳ Generating QR...",246      show_alert: false247    });248  }249 250} catch (e) {251  var errChatId = (typeof chat !== "undefined" && chat && chat.chatid) ? chat.chatid : null;252  if (errChatId) {253    try { Api.sendMessage({ chat_id: errChatId, text: "❌ <b>Error:</b> <code>" + e.message + "</code>", parse_mode: "HTML" }); } catch (fatal) {}254  }255}
commands/_pay_fampay.js · tarunpoonia905/OfcDevShopBot · TeleDevs