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/_onSuccessfulPayment.js

javascript · 181 lines

Raw
1/**#command2name: /onSuccessfulPayment3answer: 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// ⭐ Handles Telegram's successful_payment event (Stars payment completed).19// Two payload types:20//   "deposit:<userId>:<amount>"        -> credit Stars wallet balance21//   "buy:<userId>:<prodIdx>:<planIdx>" -> deliver key directly (manual-first, then API)22// ⚠️ PLATFORM NOTE: same routing caveat as _onPreCheckoutQuery.js — this is23// also duplicated as a fallback inside _start.js.24// =========================================================25 26try {27  var sp = (request && request.message && request.message.successful_payment)28    ? request.message.successful_payment29    : (request && request.successful_payment ? request.successful_payment : null);30 31  if (!sp) { return; }32 33  var chatId = chat.chatid;34  var payload = sp.invoice_payload || "";35  var starsPaid = Number(sp.total_amount || 0); // XTR amount = Stars count (no decimals)36  var telegramChargeId = sp.telegram_payment_charge_id || "N/A";37 38  var parts = payload.split(":");39  var mode = parts[0];40 41  // 📒 Log every Stars transaction for admin visibility42  function logStarsTransaction(entry) {43    var log = Bot.getProperty("stars_transactions") || [];44    log.push(entry);45    if (log.length > 500) { log = log.slice(log.length - 500); } // keep it bounded46    Bot.setProperty("stars_transactions", log, "json");47  }48 49  if (mode === "deposit") {50    var depUserId = parts[1];51    var depAmount = Number(parts[2]);52 53    var current = Number(Bot.getProperty("stars_balance_" + depUserId) || 0);54    var newBal = current + starsPaid;55    Bot.setProperty("stars_balance_" + depUserId, newBal, "number");56 57    logStarsTransaction({58      type: "deposit",59      userId: depUserId,60      stars: starsPaid,61      chargeId: telegramChargeId,62      date: new Date().toLocaleString()63    });64 65    Api.sendMessage({66      chat_id: chatId,67      text: "<blockquote>⭐ <b>STARS DEPOSIT SUCCESSFUL!</b></blockquote>\n\n" +68            "⭐ <b>Added:</b> " + starsPaid + " Stars\n" +69            "💫 <b>New Stars Balance:</b> " + newBal + "\n" +70            "🧾 <b>Transaction ID:</b> <code>" + telegramChargeId + "</code>\n\n" +71            "<i>Aapke Stars wallet me add ho gaye!</i>",72      parse_mode: "HTML",73      reply_markup: JSON.stringify({ inline_keyboard: [[{ text: "Back to Menu", callback_data: "/back", style: "danger", icon_custom_emoji_id: "5893163582194978381" }]] })74    });75 76    var ownerId = Bot.getProperty("owner_id") || "7127818616";77    try {78      Api.sendMessage({79        chat_id: ownerId,80        text: "<blockquote>⭐ <b>NEW STARS DEPOSIT</b></blockquote>\n👤 <b>User:</b> <code>" + depUserId + "</code>\n⭐ <b>Amount:</b> " + starsPaid + " Stars\n🧾 <b>Charge ID:</b> <code>" + telegramChargeId + "</code>",81        parse_mode: "HTML"82      });83    } catch (e) {}84 85  } else if (mode === "buy") {86    var buyUserId = parts[1];87    var prodIdx = Number(parts[2]);88    var planIdx = Number(parts[3]);89 90    var productList = Bot.getProperty("stored_products") || [];91    var product = productList[prodIdx];92    var plan = product ? product.plans[planIdx] : null;93 94    if (!product || !plan) {95      Api.sendMessage({ chat_id: chatId, text: "⚠️ Payment received but product config changed. Contact support with charge ID: " + telegramChargeId, parse_mode: "HTML" });96      return;97    }98 99    var planUnit = plan.unit || "day";100    var cleanPlanDays = String(plan.days).replace(/[^0-9.]/g, "").trim();101    var durationDisplay = plan.durationDisplay || (cleanPlanDays + " " + (planUnit === "hour" ? "Hour(s)" : planUnit === "minute" ? "Minute(s)" : "Day(s)"));102    var cleanProdName = product.name.trim().toUpperCase();103 104    // 🔑 MANUAL STOCK FIRST (same rule as the UPI flow — never waste a paid API call if manual stock exists)105    var scopeSuffix = (planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_" + planUnit);106    var manualKeysStorageKey = "manual_keys_" + cleanProdName + "_" + cleanPlanDays;107    var backupStockKey = "stock_" + product.name.trim() + "_" + cleanPlanDays + "_Day";108    var manualStock = Bot.getProperty(manualKeysStorageKey);109    var isBackupUsed = false;110    if (!manualStock || (Array.isArray(manualStock) && manualStock.length === 0)) {111      manualStock = Bot.getProperty(backupStockKey);112      isBackupUsed = true;113    }114    if (typeof manualStock === "string" && manualStock.trim() !== "") {115      try { manualStock = JSON.parse(manualStock); } catch (e) { manualStock = manualStock.split("\n").map(function (k) { return k.trim(); }).filter(Boolean); }116    }117 118    var generatedKey = null;119    if (Array.isArray(manualStock) && manualStock.length > 0) {120      generatedKey = manualStock.shift();121      if (isBackupUsed) { Bot.setProperty(backupStockKey, manualStock, "json"); }122      else { Bot.setProperty(manualKeysStorageKey, manualStock, "json"); }123    }124 125    logStarsTransaction({126      type: "purchase",127      userId: buyUserId,128      product: product.name,129      plan: durationDisplay,130      stars: starsPaid,131      chargeId: telegramChargeId,132      date: new Date().toLocaleString()133    });134 135    if (generatedKey) {136      // ✅ Manual delivery137      var purchaseHistory = User.getProperty("my_purchased_keys") || [];138      purchaseHistory.push({139        productName: product.name,140        days: durationDisplay,141        key: generatedKey,142        cost: starsPaid + " ⭐",143        date: new Date().toLocaleDateString()144      });145      User.setProperty("my_purchased_keys", purchaseHistory, "json");146 147      Api.sendMessage({148        chat_id: chatId,149        text: "<blockquote>⭐ <b>PAYMENT SUCCESSFUL — KEY DELIVERED!</b></blockquote>\n\n" +150              "📦 <b>Product:</b> " + product.name + "\n" +151              "⏳ <b>Duration:</b> " + durationDisplay + "\n" +152              "⭐ <b>Paid:</b> " + starsPaid + " Stars\n" +153              "🔑 <b>Your Key:</b> <code>" + generatedKey + "</code>\n\n" +154              "<i>Enjoy your purchase! 🎉</i>",155        parse_mode: "HTML",156        reply_markup: JSON.stringify({ inline_keyboard: [[{ text: "📋 Copy Key", copy_text: { text: generatedKey } }], [{ text: "Back to Menu", callback_data: "/back", style: "danger", icon_custom_emoji_id: "5893163582194978381" }]] })157      });158    } else {159      // No manual stock — flag for admin to deliver via existing API/manual process160      Api.sendMessage({161        chat_id: chatId,162        text: "<blockquote>⭐ <b>PAYMENT RECEIVED!</b></blockquote>\n\n" +163              "<i>Manual stock khaali hai — aapki key jald hi deliver ki jaayegi. Agar API-based delivery configured hai, wo bhi automatically try hogi.</i>\n\n" +164              "🧾 <b>Charge ID:</b> <code>" + telegramChargeId + "</code>",165        parse_mode: "HTML"166      });167    }168 169    var ownerId2 = Bot.getProperty("owner_id") || "7127818616";170    try {171      Api.sendMessage({172        chat_id: ownerId2,173        text: "<blockquote>⭐ <b>NEW STARS PURCHASE</b></blockquote>\n👤 <b>User:</b> <code>" + buyUserId + "</code>\n📦 <b>Product:</b> " + product.name + " (" + durationDisplay + ")\n⭐ <b>Paid:</b> " + starsPaid + " Stars\n🔑 <b>Delivery:</b> " + (generatedKey ? "Manual Stock ✅" : "PENDING ⚠️") + "\n🧾 <b>Charge ID:</b> <code>" + telegramChargeId + "</code>",174        parse_mode: "HTML"175      });176    } catch (e) {}177  }178 179} catch (err) {180  try { Bot.sendMessage("⚠️ Successful Payment Handler Error: " + err.message, { parse_mode: "HTML" }); } catch (e2) {}181}
commands/_onSuccessfulPayment.js · tarunpoonia905/OfcDevShopBot · TeleDevs