Create payments.py
Browse files- chatbot/plugins/payments.py +55 -0
chatbot/plugins/payments.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import os
|
3 |
+
from pyrogram import *
|
4 |
+
from pyrogram.types import *
|
5 |
+
from database import db
|
6 |
+
from datetime import datetime as dt, timedelta
|
7 |
+
|
8 |
+
@Client.on_callback_query(filters.regex(r"^get_premium$"))
|
9 |
+
async def get_premiums(client, callback):
|
10 |
+
keyboard = InlineKeyboardMarkup(
|
11 |
+
[
|
12 |
+
[
|
13 |
+
InlineKeyboardButton("$4.99 Monthly", callback_data="buy_premium_monthly"),
|
14 |
+
InlineKeyboardButton("$49.99 Yearly", callback_data="buy_premium_monthly"),
|
15 |
+
],
|
16 |
+
[
|
17 |
+
InlineKeyboardButton(f"β Closed", callback_data="closedd")
|
18 |
+
]
|
19 |
+
]
|
20 |
+
)
|
21 |
+
return await callback.edit_message_reply_markup(reply_markup=keyboard)
|
22 |
+
|
23 |
+
@Client.on_callback_query(filters.regex(r"^buy_premium_(monthly|yearly)$"))
|
24 |
+
async def premium_purchase(client, callback):
|
25 |
+
plan = callback.matches[0].group(1)
|
26 |
+
user_id = callback.from_user.id
|
27 |
+
if user_id != 6477856957:
|
28 |
+
return await callback.answer("Only Developer test")
|
29 |
+
|
30 |
+
if plan == "monthly":
|
31 |
+
expiry = dt.now() + timedelta(days=30)
|
32 |
+
price = "$4.99"
|
33 |
+
else:
|
34 |
+
expiry = dt.now() + timedelta(days=365)
|
35 |
+
price = "$49.99"
|
36 |
+
|
37 |
+
await db.user_premium.update_one(
|
38 |
+
{"user_id": user_id},
|
39 |
+
{
|
40 |
+
"$set": {
|
41 |
+
"is_premium": True,
|
42 |
+
"premium_expiry": expiry,
|
43 |
+
"subscription_plan": plan
|
44 |
+
},
|
45 |
+
"$inc": {"credits_used": -50}
|
46 |
+
},
|
47 |
+
upsert=True
|
48 |
+
)
|
49 |
+
await callback.message.edit_text(
|
50 |
+
f"π Premium {plan.capitalize()} Activated!\n"
|
51 |
+
f"β Expires: {expiry.strftime('%Y-%m-%d')}\n"
|
52 |
+
f"β Daily credits: 50 images\n\n"
|
53 |
+
f"Thanks for your support!",
|
54 |
+
reply_markup=None
|
55 |
+
)
|