ayushyadav7970824760/goldensellingstore_botPublic · Bot Template

AIThis Telegram store bot lets customers browse digital products and plans, apply coupons, add funds via UPI, and receive purchased keys. It includes a full admin panel for managing products, reordering items, setting reseller prices, viewing and removing key stock, configuring UPI payment details and update links, and checking user balances. Co-admins and resellers are supported, and support tickets are forwarded to the admin.

Commercedigital_storeadmin_panelupi_paymentsresellercouponskey_stock
ProfileTelegram
146 commands0 envUpdated 2d agoCreated Sep 5, 2026
Back to folder

commands/_pay_upi.js

javascript · 200 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") || "ayushrds@nyes";115 116  // =====================================================117  // ✋ MANUAL MODE — Fampay ka QR use nahi hota, apna plain QR banate hain.118  // =====================================================119  if ((Bot.getProperty("upi_payment_mode") || "auto") === "manual") {120    var manualOrderId2 = "MANUAL" + String(Date.now());121    try { Bot.setProperty("qr_order_amount_" + manualOrderId2, needToPay.toFixed(2), "string"); } catch (e) {}122 123    var manualUpiUri2 = "upi://pay?pa=" + encodeURIComponent(upi_id) +124                         "&pn=" + encodeURIComponent(Bot.getProperty("bot_name") || "GOLDEN MODS STORE") +125                         "&am=" + encodeURIComponent(needToPay.toFixed(2)) +126                         "&cu=INR";127    var pLogoUrl3 = Bot.getProperty("bot_logo_url");128    var manualQrImage2 = "https://quickchart.io/qr?text=" + encodeURIComponent(manualUpiUri2) + "&size=400&margin=2" +129      (pLogoUrl3 ? "&centerImageUrl=" + encodeURIComponent(pLogoUrl3) + "&centerImageSizeRatio=0.22" : "");130 131    var botDisplayName2 = Bot.getProperty("bot_name") || "GOLDEN SELLING STORE";132    var manualGatewayMsg2 =133      "<blockquote>🛍️ <b>" + botDisplayName2 + " — UPI QR ACTIVE</b> 💳</blockquote>\n" +134      "➤ ───────────────────\n" +135      "<tg-emoji emoji-id='5260399854500191689'>🏪</tg-emoji> <b>Merchant Name:</b> " + botDisplayName2 + "\n\n" +136      "💰 <b>Scan &amp; pay exactly</b> ₹<code>" + needToPay.toFixed(2) + "</code>\n\n" +137      "👉 <i>Tap <b>Verify Payment</b> below after completing payment.</i>\n" +138      "➤ ───────────────────\n" +139      "<blockquote>⏳ <b>Session expires in 5 minutes.</b></blockquote>";140 141    var manualInlineButtons2 = [142      [{ text: "💳 ✅ VERIFY PAYMENT", callback_data: "/check " + manualOrderId2, style: "success", icon_custom_emoji_id: "5330237710655306682" }],143      [{ text: "❌ Cancel Order", callback_data: "/cancel_topup " + manualOrderId2, style: "danger" }]144    ];145 146    var manualGenMsgId2 = null;147    try { manualGenMsgId2 = Bot.getProperty("gen_msg_id_" + userId) || User.getProperty("gen_msg_id_" + userId); } catch (e) {}148 149    var manualSentQrMsg2 = Api.sendPhoto({150      chat_id: chatId,151      photo: manualQrImage2,152      caption: manualGatewayMsg2,153      parse_mode: "HTML",154      reply_markup: JSON.stringify({ inline_keyboard: manualInlineButtons2 })155    });156 157    if (manualGenMsgId2) {158      try { Api.deleteMessage({ chat_id: chatId, message_id: manualGenMsgId2 }); } catch (e) {}159      Bot.setProperty("gen_msg_id_" + userId, null, "string");160      User.setProperty("gen_msg_id_" + userId, null, "string");161    }162 163    try {164      var manualQrMsgId2 = (manualSentQrMsg2 && manualSentQrMsg2.result && manualSentQrMsg2.result.message_id) ? manualSentQrMsg2.result.message_id : (manualSentQrMsg2 && manualSentQrMsg2.message_id ? manualSentQrMsg2.message_id : null);165      if (manualQrMsgId2) {166        Bot.setProperty("qr_msg_id_" + userId, manualQrMsgId2, "string");167        User.setProperty("qr_msg_id_" + userId, manualQrMsgId2, "string");168      }169      Bot.setProperty("qr_order_id_" + userId, manualOrderId2, "string");170      User.setProperty("qr_order_id_" + userId, manualOrderId2, "string");171      User.setProperty("pending_order_id", manualOrderId2, "string");172    } catch (e) {}173 174    if (callbackId) {175      try { Api.answerCallbackQuery({ callback_query_id: String(callbackId) }); } catch (e) {}176    }177    return; // 🚫 STOP — Fampay API bilkul call nahi hui178  }179 180  HTTP.get({181    url: "https://fampay.anujbots.xyz/qr.php?upi=" + encodeURIComponent(upi_id) +182         "&amount=" + encodeURIComponent(needToPay.toFixed(2)),183    success: "/onQR",184    error: "/onApiError"185  });186 187  if (callbackId) {188    Api.answerCallbackQuery({189      callback_query_id: String(callbackId),190      text: "⏳ Generating QR...",191      show_alert: false192    });193  }194 195} catch (e) {196  var errChatId = (typeof chat !== "undefined" && chat && chat.chatid) ? chat.chatid : null;197  if (errChatId) {198    try { Api.sendMessage({ chat_id: errChatId, text: "❌ <b>Error:</b> <code>" + e.message + "</code>", parse_mode: "HTML" }); } catch (fatal) {}199  }200}