Spaces:
Running
Running
Hermes Agent commited on
Commit ·
fe53333
1
Parent(s): 157e1b7
fix: support valid HTTPS UPI redirect in Telegram buttons to prevent BUTTON_URL_INVALID
Browse files
Thunder/bot/plugins/subscription.py
CHANGED
|
@@ -36,13 +36,15 @@ def get_upi_link(user_id: int) -> str:
|
|
| 36 |
|
| 37 |
|
| 38 |
def get_plan_keyboard(user_id: int, file_id: Optional[str] = None) -> InlineKeyboardMarkup:
|
| 39 |
-
|
|
|
|
| 40 |
buttons = [
|
| 41 |
[
|
| 42 |
-
InlineKeyboardButton(f"💳 Pay ₹{Var.SUB_PRICE} via UPI", url=
|
| 43 |
],
|
| 44 |
[
|
| 45 |
-
InlineKeyboardButton("
|
|
|
|
| 46 |
]
|
| 47 |
]
|
| 48 |
if file_id:
|
|
@@ -57,35 +59,39 @@ def get_plan_keyboard(user_id: int, file_id: Optional[str] = None) -> InlineKeyb
|
|
| 57 |
|
| 58 |
@StreamBot.on_message(filters.command(["plan", "buy", "sub"]) & filters.private)
|
| 59 |
async def plan_command_handler(client: Client, message: Message):
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
|
| 91 |
@StreamBot.on_message(filters.command("addsub") & filters.private)
|
|
@@ -189,17 +195,22 @@ async def close_sub_callback(client: Client, query: CallbackQuery):
|
|
| 189 |
@StreamBot.on_callback_query(filters.regex(r"^sub_pay_(\d+)$"))
|
| 190 |
async def sub_pay_callback(client: Client, query: CallbackQuery):
|
| 191 |
user_id = int(query.matches[0].group(1))
|
| 192 |
-
|
|
|
|
| 193 |
text = (
|
| 194 |
-
"💳 **
|
|
|
|
| 195 |
f"**UPI ID:** `{Var.UPI_ID}`\n"
|
| 196 |
f"**Name:** `{Var.UPI_NAME}`\n"
|
| 197 |
-
f"**
|
| 198 |
-
"
|
|
|
|
|
|
|
|
|
|
| 199 |
)
|
| 200 |
keyboard = InlineKeyboardMarkup([
|
| 201 |
-
[InlineKeyboardButton(f"🚀 Open UPI App (₹{Var.SUB_PRICE})", url=
|
| 202 |
-
[InlineKeyboardButton("📩 Submit
|
| 203 |
[InlineKeyboardButton("⬅️ Back", callback_data=f"plan_info_{user_id}")]
|
| 204 |
])
|
| 205 |
await query.answer()
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
def get_plan_keyboard(user_id: int, file_id: Optional[str] = None) -> InlineKeyboardMarkup:
|
| 39 |
+
base_url = Var.URL.rstrip('/') if Var.URL else "https://jishnupg-filetolink.hf.space"
|
| 40 |
+
pay_url = f"{base_url}/pay?u={user_id}"
|
| 41 |
buttons = [
|
| 42 |
[
|
| 43 |
+
InlineKeyboardButton(f"💳 Pay ₹{Var.SUB_PRICE} via UPI App", url=pay_url)
|
| 44 |
],
|
| 45 |
[
|
| 46 |
+
InlineKeyboardButton("📋 Payment Details", callback_data=f"sub_pay_{user_id}"),
|
| 47 |
+
InlineKeyboardButton("📩 Submit Proof", callback_data=f"proof_{user_id}")
|
| 48 |
]
|
| 49 |
]
|
| 50 |
if file_id:
|
|
|
|
| 59 |
|
| 60 |
@StreamBot.on_message(filters.command(["plan", "buy", "sub"]) & filters.private)
|
| 61 |
async def plan_command_handler(client: Client, message: Message):
|
| 62 |
+
try:
|
| 63 |
+
user_id = message.from_user.id
|
| 64 |
+
user_name = message.from_user.first_name or "User"
|
| 65 |
+
|
| 66 |
+
sub = await db.get_subscription(user_id)
|
| 67 |
+
now = datetime.datetime.now(datetime.timezone.utc)
|
| 68 |
+
|
| 69 |
+
if sub and sub.get("status") == "active" and sub.get("expires_at") and sub["expires_at"] > now:
|
| 70 |
+
expires = sub["expires_at"]
|
| 71 |
+
remaining = max(1, (expires - now).days)
|
| 72 |
+
text = MSG_SUB_PLAN_ACTIVE.format(
|
| 73 |
+
user_name=user_name,
|
| 74 |
+
user_id=user_id,
|
| 75 |
+
expiry_date=expires.strftime("%Y-%m-%d %H:%M UTC"),
|
| 76 |
+
remaining_days=remaining
|
| 77 |
+
)
|
| 78 |
+
keyboard = InlineKeyboardMarkup([
|
| 79 |
+
[InlineKeyboardButton(f"➕ Extend Subscription (₹{Var.SUB_PRICE})", callback_data=f"sub_pay_{user_id}")],
|
| 80 |
+
[InlineKeyboardButton("❌ Close", callback_data="close_sub")]
|
| 81 |
+
])
|
| 82 |
+
else:
|
| 83 |
+
text = MSG_SUB_PLAN_FREE.format(
|
| 84 |
+
price=Var.SUB_PRICE,
|
| 85 |
+
upi_id=Var.UPI_ID
|
| 86 |
+
)
|
| 87 |
+
if not Var.PAYMENT_ENABLED:
|
| 88 |
+
text += "\n\n*(ℹ️ Note: Payment gateway is in preview mode. Set PAYMENT=True to activate live paywall enforcement.)*"
|
| 89 |
+
keyboard = get_plan_keyboard(user_id)
|
| 90 |
+
|
| 91 |
+
await message.reply_text(text, reply_markup=keyboard, quote=True)
|
| 92 |
+
except Exception as e:
|
| 93 |
+
logger.error(f"Error in plan_command_handler: {e}", exc_info=True)
|
| 94 |
+
await message.reply_text(f"⚠️ Error displaying plan: {e}", quote=True)
|
| 95 |
|
| 96 |
|
| 97 |
@StreamBot.on_message(filters.command("addsub") & filters.private)
|
|
|
|
| 195 |
@StreamBot.on_callback_query(filters.regex(r"^sub_pay_(\d+)$"))
|
| 196 |
async def sub_pay_callback(client: Client, query: CallbackQuery):
|
| 197 |
user_id = int(query.matches[0].group(1))
|
| 198 |
+
base_url = Var.URL.rstrip('/') if Var.URL else "https://jishnupg-filetolink.hf.space"
|
| 199 |
+
pay_url = f"{base_url}/pay?u={user_id}"
|
| 200 |
text = (
|
| 201 |
+
"💳 **Flash File UPI Payment Details**\n\n"
|
| 202 |
+
f"**Amount:** `₹{Var.SUB_PRICE}` (30-Day Unlimited Access)\n"
|
| 203 |
f"**UPI ID:** `{Var.UPI_ID}`\n"
|
| 204 |
f"**Name:** `{Var.UPI_NAME}`\n"
|
| 205 |
+
f"**Reference Note:** `FlashFile_Sub_{user_id}`\n\n"
|
| 206 |
+
"**How to Pay:**\n"
|
| 207 |
+
"1. Tap the button below to launch Google Pay / PhonePe / Paytm.\n"
|
| 208 |
+
"2. Or copy the UPI ID above and pay `₹10` in any UPI app.\n"
|
| 209 |
+
"3. Once done, tap **'Submit Proof'** and send your screenshot or UTR."
|
| 210 |
)
|
| 211 |
keyboard = InlineKeyboardMarkup([
|
| 212 |
+
[InlineKeyboardButton(f"🚀 Open UPI App (₹{Var.SUB_PRICE})", url=pay_url)],
|
| 213 |
+
[InlineKeyboardButton("📩 Submit Payment Proof", callback_data=f"proof_{user_id}")],
|
| 214 |
[InlineKeyboardButton("⬅️ Back", callback_data=f"plan_info_{user_id}")]
|
| 215 |
])
|
| 216 |
await query.answer()
|
Thunder/server/stream_routes.py
CHANGED
|
@@ -250,6 +250,38 @@ async def _serve_media_response(
|
|
| 250 |
)
|
| 251 |
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
@routes.get("/", allow_head=True)
|
| 254 |
async def root_redirect(request):
|
| 255 |
return web.json_response({
|
|
|
|
| 250 |
)
|
| 251 |
|
| 252 |
|
| 253 |
+
@routes.get("/pay", allow_head=True)
|
| 254 |
+
async def upi_redirect_handler(request: web.Request):
|
| 255 |
+
u = request.query.get("u", "")
|
| 256 |
+
note = f"FlashFile_Sub_{u}" if u else "FlashFile_Sub"
|
| 257 |
+
upi_uri = f"upi://pay?pa={Var.UPI_ID}&pn={quote(Var.UPI_NAME)}&am={Var.SUB_PRICE}&cu=INR&tn={note}"
|
| 258 |
+
html = f"""<!DOCTYPE html>
|
| 259 |
+
<html>
|
| 260 |
+
<head>
|
| 261 |
+
<meta charset="utf-8">
|
| 262 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 263 |
+
<title>Pay ₹{Var.SUB_PRICE} - Flash File</title>
|
| 264 |
+
<meta http-equiv="refresh" content="0; url={upi_uri}">
|
| 265 |
+
<style>
|
| 266 |
+
body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #0f1115; color: #fff; text-align: center; padding: 40px 20px; }}
|
| 267 |
+
.card {{ max-width: 400px; margin: 0 auto; background: #181a20; border-radius: 16px; padding: 24px; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }}
|
| 268 |
+
h2 {{ margin-top: 0; color: #4ade80; }}
|
| 269 |
+
.btn {{ display: block; background: #2563eb; color: #fff; text-decoration: none; padding: 14px 20px; border-radius: 12px; font-weight: bold; margin: 16px 0; }}
|
| 270 |
+
.upi-box {{ background: #232730; padding: 12px; border-radius: 8px; font-family: monospace; font-size: 16px; margin: 15px 0; user-select: all; }}
|
| 271 |
+
</style>
|
| 272 |
+
</head>
|
| 273 |
+
<body>
|
| 274 |
+
<div class="card">
|
| 275 |
+
<h2>⚡ Flash File Premium</h2>
|
| 276 |
+
<p>Redirecting to your UPI app (Google Pay, PhonePe, Paytm)...</p>
|
| 277 |
+
<a class="btn" href="{upi_uri}">Launch UPI App (₹{Var.SUB_PRICE})</a>
|
| 278 |
+
<p style="color: #94a3b8; font-size: 14px;">Or copy UPI ID manually:</p>
|
| 279 |
+
<div class="upi-box">{Var.UPI_ID}</div>
|
| 280 |
+
</div>
|
| 281 |
+
</body>
|
| 282 |
+
</html>"""
|
| 283 |
+
return web.Response(text=html, content_type="text/html")
|
| 284 |
+
|
| 285 |
@routes.get("/", allow_head=True)
|
| 286 |
async def root_redirect(request):
|
| 287 |
return web.json_response({
|