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/_onBuyQR.js
javascript Β· 212 lines
1/**#command2name: /onBuyQR3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12/**#command13name: /onBuyQR14answer: 15keyboard: 16parse_mode: markdown17aliases: 18allow_only_group: false19need_reply: false20case_insensitive: false21is_web: 022#command**/23 24try {25 if (!content) { 26 Api.sendMessage({ 27 chat_id: chat.chatid, 28 text: "β Error: No response from payment server. Please try again later.", 29 parse_mode: "HTML" 30 }); 31 return; 32 }33 34 var res;35 try {36 res = (typeof content === "object") ? content : JSON.parse(content);37 } catch (parseErr) {38 Api.sendMessage({39 chat_id: chat.chatid,40 text: "β <b>QR Parse Failed</b>\n<code>" + String(content).substring(0, 500) + "</code>",41 parse_mode: "HTML"42 });43 return;44 }45 46 if (res && res.order_id && (res.qr_url || res.checkout_url || res.upi_intent)) {47 res = { status: "success", data: { order_id: res.order_id, qr_url: res.qr_url, checkout_url: res.checkout_url, upi_id: res.upi_id, upi_intent: res.upi_intent, amount: res.amount || res.payable_amount, expires_at_ist: res.expires_at_ist || res.expires_at || "5 Minutes" } };48 }49 50 if (!res || res.status !== "success" || !res.data) {51 Api.sendMessage({52 chat_id: chat.chatid,53 text: "<tg-emoji emoji-id='6219547832169273793'>β</tg-emoji><b>QR Generation Failed</b>\n<code>" + JSON.stringify(res).substring(0, 500) + "</code>",54 parse_mode: "HTML"55 });56 return;57 }58 59 var order_id = res.data.order_id || res.data.orderid;60 var gatewayQr = res.data.qr_url || res.data.qrurl;61 var upiId = String(res.data.upi_id || res.data.vpa || res.data.upi || "").trim();62 var upiIntent = String(res.data.upi_intent || res.data.upiIntent || "").trim();63 var expire = res.data.expires_at_ist || res.data.expiresatist || "5 Minutes";64 var userId = user.telegramid;65 66 var price = Number(User.getProperty("buy_price") || 0);67 var userBal = Number(Libs.ResourcesLib.userRes("balance").value() || 0);68 var bonusBal = Number(Bot.getProperty("balance" + userId) || 0);69 var totalUserBal = userBal + bonusBal;70 71 var requestedNeedpay = Number(User.getProperty("buy_needpay") || (price > totalUserBal ? price - totalUserBal : 0));72 var needpay = Number(res.data.payable_amount || res.data.amount || requestedNeedpay);73 if (!isFinite(needpay) || needpay <= 0) needpay = requestedNeedpay;74 User.setProperty("buy_expected_amount", needpay, "number");75 // Lock the exact amount against this gateway order; verification must match it.76 Bot.setProperty("pay_order_amount_" + order_id, Number(needpay), "number");77 User.setProperty("pay_order_amount_" + order_id, Number(needpay), "number");78 var prodName = User.getProperty("buy_prod_name") || "Product";79 80 // PhonePe can reject some gateway-hosted QR images even though the same UPI81 // payment works in other apps. Build a standard UPI QR from the gateway82 // order's own VPA + exact amount, embedding the order id in the transaction83 // note so the gateway can still match the payment during verification.84 // Telegram sometimes rejects a gateway-hosted image with DOCUMENT_INVALID.85 // When the gateway provides an exact UPI intent, generate a standard PNG QR86 // from that intent first; it still carries the gateway transaction reference.87 var qr = "";88 if (upiIntent) {89 qr = "https://api.qrserver.com/v1/create-qr-code/?size=700x700&margin=10&data=" + encodeURIComponent(upiIntent);90 } else {91 qr = gatewayQr;92 }93 if (!qr && upiId && needpay > 0) {94 var upiUri = "upi://pay?pa=" + encodeURIComponent(upiId) +95 "&am=" + encodeURIComponent(needpay.toFixed(2)) +96 "&cu=INR&tr=" + encodeURIComponent(String(order_id)) +97 "&tn=" + encodeURIComponent(String(order_id));98 qr = "https://api.qrserver.com/v1/create-qr-code/?size=700x700&margin=10&data=" + encodeURIComponent(upiUri);99 }100 if (!qr) {101 Api.sendMessage({ chat_id: chat.chatid, text: "β <b>QR URL nahi mila.</b> Payment gateway response incomplete hai.", parse_mode: "HTML" });102 return;103 }104 105 try {106 var genMsgid = Bot.getProperty("gen_msg_id_" + userId);107 if (genMsgid) {108 Api.deleteMessage({ chat_id: chat.chatid, message_id: genMsgid });109 Bot.setProperty("gen_msg_id_" + userId, null, "string");110 }111 } catch (e) {}112 113 var gatewayMsg = 114 "<tg-emoji emoji-id='6267225207560214192'>β οΈ</tg-emoji><b>PAYMENT GATEWAY</b>\n\n" +115 "<tg-emoji emoji-id='6147767796097884213'>π·οΈ</tg-emoji><b>Product:</b> " + prodName + "\n" +116 "<tg-emoji emoji-id='6041705726206808304'>π°</tg-emoji><b>Price:</b> βΉ" + price.toFixed(2) + "\n" +117 "<tg-emoji emoji-id='5348392971207194994'>π³</tg-emoji><b>Balance:</b> βΉ" + totalUserBal.toFixed(2) + "\n" +118 "<tg-emoji emoji-id='619491118249881916'>π₯</tg-emoji><b>Pay Now:</b> βΉ" + needpay.toFixed(2) + "\n" +119 "<tg-emoji emoji-id='6266866272848321043'>β³</tg-emoji><b>Expire Time:</b> <code>" + expire + "</code>\n\n" +120 "<tg-emoji emoji-id='5330237710655306682'>β‘</tg-emoji><b>Scan QR & pay exact amount</b>\n";121 122 var inlineButtons = [123 [124 {125 text: "I have paid",126 callback_data: "/check_buy " + order_id,127 style: "success",128 icon_custom_emoji_id: "5330237710655306682"129 },130 {131 text: "Cancel Order",132 callback_data: "/cancel_buy " + order_id,133 style: "danger",134 icon_custom_emoji_id: "6219547832169273793"135 }136 ]137 ];138 139 var sentQrMsg;140 try {141 sentQrMsg = Api.sendPhoto({142 chat_id: chat.chatid,143 photo: qr,144 caption: gatewayMsg,145 parse_mode: "HTML",146 reply_markup: JSON.stringify({ inline_keyboard: inlineButtons })147 });148 } catch (photoErr) {149 // Final fallback: if the gateway/intent URL was rejected, build a simple150 // standards-based UPI QR from the returned VPA and exact amount.151 var fallbackQr = "";152 if (upiId && needpay > 0) {153 var fallbackUpiUri = "upi://pay?pa=" + encodeURIComponent(upiId) +154 "&am=" + encodeURIComponent(needpay.toFixed(2)) +155 "&cu=INR&tr=" + encodeURIComponent(String(order_id)) +156 "&tn=" + encodeURIComponent(String(order_id));157 fallbackQr = "https://api.qrserver.com/v1/create-qr-code/?size=700x700&margin=10&data=" + encodeURIComponent(fallbackUpiUri);158 }159 if (fallbackQr && fallbackQr !== qr) {160 try {161 sentQrMsg = Api.sendPhoto({162 chat_id: chat.chatid,163 photo: fallbackQr,164 caption: gatewayMsg,165 parse_mode: "HTML",166 reply_markup: JSON.stringify({ inline_keyboard: inlineButtons })167 });168 } catch (fallbackErr) {169 Api.sendMessage({170 chat_id: chat.chatid,171 text: "β <b>QR send failed.</b> Payment order create ho gaya hai, lekin QR image Telegram ko accept nahi hui. Thodi der baad retry karein.",172 parse_mode: "HTML"173 });174 return;175 }176 } else {177 Api.sendMessage({178 chat_id: chat.chatid,179 text: "β <b>QR send failed.</b> Payment order create ho gaya hai, lekin usable QR URL nahi mila.",180 parse_mode: "HTML"181 });182 return;183 }184 }185 186 try {187 if (sentQrMsg) {188 var qrMsgId = sentQrMsg.result ? sentQrMsg.result.message_id : sentQrMsg.message_id;189 if (qrMsgId) {190 Bot.setProperty("buy_qr_msg_id_" + userId, qrMsgId, "string");191 User.setProperty("buy_qr_msg_id_" + userId, qrMsgId, "string");192 User.setProperty("buy_pending_order_id", order_id, "string");193 User.setProperty("buy_expected_amount", needpay, "number");194 }195 }196 // Automatic Gram UPI Gateway verification for purchases; user does not need to tap "I have paid".197 try {198 Bot.run({199 command: "/check_buy",200 run_after: 3,201 label: "gram_buy_verify_" + order_id,202 options: { verify_attempt: 0, is_background: true }203 });204 } catch (autoBuyVerifyErr) {}205 } catch (e) {}206} catch (err) {207 Api.sendMessage({208 chat_id: chat.chatid,209 text: "β οΈ <b>System Error:</b> <code>" + (err && err.message ? err.message : String(err)) + "</code>",210 parse_mode: "HTML"211 });212}