suvo_/Example8BotPublic · Bot Template

AIThis bot implements a UPI payment gateway integration for Telegram, allowing users to pay ₹1 via UPI to unlock VIP access. The /start command checks if the user is already VIP and shows a payment button if not. The /pay command creates a payment session via an external UPI gateway API, displays a QR code and payment details, while /check_payment verifies the transaction status with signature validation before granting VIP membership. The bot uses HTTP requests, user properties for session tracking, and rich message formatting for payment UI.

Commerceupipaymentgatewayvipsubscriptionqr-code
ProfileTelegram
3 commands1 envUpdated 4d agoCreated Aug 5, 2026
Back to folder

commands/_check_payment.js

javascript · 90 lines

Raw
1/**#command2name: /check_payment3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12let url = `https://upi-gateway-sstu.onrender.com/api/session/${User.getProperty("session")}`;13let res = await HTTP.get(url);14 15const serverSignature = res.headers["x-signature"];16 17if (res.data.success &&18    serverSignature &&19    res.data.data &&20    !verifyWebhookSignature(21      res.data.data,22      serverSignature,23      process.env.POLLING_SECRET24   )25  )26 {27    Api.answerCallbackQuery({28      callback_query_id: update.callback_query.id,29      text: "Unable to verify transaction securely. Please try again.",30      show_alert: true31    });32    return;33 }34 35if (res.data.success && res.data.data.status === "paid") {36  User.setProperty("isVip", true);37  let m = await Api.sendMessage({38    text: "✅ Payment Successful!\n\n🎉 You got VIP access.",39    message_effect_id: "5046509860389126442"40  });41 42  try {43    Api.answerCallbackQuery({44    callback_query_id: request.id,45    text: "✅ Payment Successful! VIP Activated.",46    show_alert: true47  });48    49    Api.deleteMessage({50      chat_id: chat.id,51      message_id: request.message.message_id52    });53  } catch (er) {}54 55} else {56  Api.answerCallbackQuery({57    callback_query_id: request.id,58    text: res?.data?.message || "❌ Payment not received yet.\nPlease complete the payment first.",59    show_alert: true60  });61}62 63 64function verifyWebhookSignature(payload, signature, secret) {65  const expectedSignature =66    "sha256=" +67    crypto68    .createHmac("sha256", secret)69    .update(typeof payload === "string" ? payload : JSON.stringify(payload))70    .digest("hex");71 72  const received = String(signature || "").trim();73 74  const receivedBuffer = Buffer.from(received, "utf8");75  const expectedBuffer = Buffer.from(expectedSignature, "utf8");76 77  if (receivedBuffer.length !== expectedBuffer.length) {78    /*79    console.log({80      received,81      expectedSignature,82      receivedLength: receivedBuffer.length,83      expectedLength: expectedBuffer.length,84    });85    */86    return false;87  }88 89  return crypto.timingSafeEqual(receivedBuffer, expectedBuffer);90}