diff --git a/bot.py b/bot.py index 75f607c6..22d0c83a 100644 --- a/bot.py +++ b/bot.py @@ -9,10 +9,10 @@ storage = MemoryStorage() dp = Dispatcher(bot=bot, storage=storage) router = Router() -from handlers import commands, notifications, profile, start +from handlers import commands, notifications, pay, profile, start from handlers.admin import admin, admin_panel, user_editor from handlers.keys import key_management, keys -from handlers.payment import cryprobot_pay, freekassa_pay, yookassa_pay +from handlers.payments import cryprobot_pay, freekassa_pay, yookassa_pay dp.include_router(admin.router) dp.include_router(admin_panel.router) @@ -22,6 +22,7 @@ dp.include_router(start.router) dp.include_router(profile.router) dp.include_router(keys.router) dp.include_router(key_management.router) +dp.include_router(pay.router) if YOOKASSA_ENABLE: dp.include_router(yookassa_pay.router) if FREEKASSA_ENABLE: diff --git a/handlers/donate.py b/handlers/donate.py new file mode 100644 index 00000000..e69de29b diff --git a/handlers/keys/keys.py b/handlers/keys/keys.py index 1ad8819d..f9979126 100644 --- a/handlers/keys/keys.py +++ b/handlers/keys/keys.py @@ -574,11 +574,14 @@ async def process_callback_renew_plan(callback_query: types.CallbackQuery): balance = await get_balance(tg_id) if balance < cost: + replenish_button = types.InlineKeyboardButton( + text="Пополнить баланс", callback_data="pay" + ) view_profile = types.InlineKeyboardButton( text="👤 Мой профиль", callback_data="view_profile" ) keyboard = types.InlineKeyboardMarkup( - inline_keyboard=[[view_profile]] + inline_keyboard=[[replenish_button], [view_profile]] ) await bot.send_message( diff --git a/handlers/notifications.py b/handlers/notifications.py index 3ee57d13..339022c4 100644 --- a/handlers/notifications.py +++ b/handlers/notifications.py @@ -104,6 +104,12 @@ async def notify_10h_keys( callback_data=f'renew_key|{record["client_id"]}', ) ], + [ + types.InlineKeyboardButton( + text="💳 Пополнить баланс", + callback_data="pay", + ) + ], [ types.InlineKeyboardButton( text="👤 Мой профиль", callback_data="view_profile" @@ -176,6 +182,12 @@ async def notify_24h_keys( callback_data=f'renew_key|{record["client_id"]}', ) ], + [ + types.InlineKeyboardButton( + text="💳 Пополнить баланс", + callback_data="pay", + ) + ], [ types.InlineKeyboardButton( text="👤 Мой профиль", callback_data="view_profile" diff --git a/handlers/pay.py b/handlers/pay.py new file mode 100644 index 00000000..eac3673b --- /dev/null +++ b/handlers/pay.py @@ -0,0 +1,62 @@ +from aiogram import F, Router +from aiogram.types import CallbackQuery, InlineKeyboardButton +from aiogram.utils.keyboard import InlineKeyboardBuilder + +from config import CRYPTO_BOT_ENABLE, FREEKASSA_ENABLE, STARS_ENABLE, YOOKASSA_ENABLE +from database import get_trial +from handlers.start import send_welcome_message + +router = Router() + + +@router.callback_query(F.data == "pay") +async def handle_pay(callback_query: CallbackQuery): + await callback_query.message.delete() + builder = InlineKeyboardBuilder() + + if YOOKASSA_ENABLE: + builder.row( + InlineKeyboardButton( + text="💳 Пополнить баланс ЯКассой", + callback_data="pay_yookassa", + ) + ) + if FREEKASSA_ENABLE: + builder.row( + InlineKeyboardButton( + text="💳 Пополнить баланс Freekassa", + callback_data="pay_freekassa", + ) + ) + if CRYPTO_BOT_ENABLE: + builder.row( + InlineKeyboardButton( + text="💳 Пополнить баланс CryptoBot", + callback_data="pay_cryptobot", + ) + ) + if STARS_ENABLE: + builder.row( + InlineKeyboardButton( + text="💳 Пополнить баланс Звездами", + callback_data="pay_stars", + ) + ) + + builder.row(InlineKeyboardButton(text="⬅️ Назад", callback_data="view_profile")) + + await callback_query.message.answer( + "Выберите удобный вариант оплаты", + parse_mode="HTML", + reply_markup=builder.as_markup(), + ) + + await callback_query.answer() + + +@router.callback_query(F.data == "back_to_menu") +async def handle_back_to_menu(callback_query: CallbackQuery): + await callback_query.message.delete() + trial_status = await get_trial(callback_query.from_user.id) + await send_welcome_message(callback_query.from_user.id, trial_status) + await callback_query.answer() diff --git a/handlers/payment/cryprobot_pay.py b/handlers/payments/cryprobot_pay.py similarity index 100% rename from handlers/payment/cryprobot_pay.py rename to handlers/payments/cryprobot_pay.py diff --git a/handlers/payment/freekassa_pay.py b/handlers/payments/freekassa_pay.py similarity index 100% rename from handlers/payment/freekassa_pay.py rename to handlers/payments/freekassa_pay.py diff --git a/handlers/payment/stars_pay.py b/handlers/payments/stars_pay.py similarity index 100% rename from handlers/payment/stars_pay.py rename to handlers/payments/stars_pay.py diff --git a/handlers/payment/yookassa_pay.py b/handlers/payments/yookassa_pay.py similarity index 100% rename from handlers/payment/yookassa_pay.py rename to handlers/payments/yookassa_pay.py diff --git a/handlers/profile.py b/handlers/profile.py index 0f168a73..ce92152f 100644 --- a/handlers/profile.py +++ b/handlers/profile.py @@ -7,7 +7,7 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder from loguru import logger from bot import bot -from config import CHANNEL_URL, CRYPTO_BOT_ENABLE, FREEKASSA_ENABLE, STARS_ENABLE, YOOKASSA_ENABLE +from config import CHANNEL_URL from database import get_balance, get_key_count, get_referral_stats from handlers.texts import get_referral_link, invite_message_send, profile_message_send @@ -41,34 +41,12 @@ async def process_callback_view_profile( InlineKeyboardButton(text="➕ Устройство", callback_data="create_key"), InlineKeyboardButton(text="📱 Мои устр-ва", callback_data="view_keys"), ) - if YOOKASSA_ENABLE: - builder.row( - InlineKeyboardButton( - text="💳 Пополнить баланс ЯКассой", - callback_data="pay_yookassa", - ) - ) - if FREEKASSA_ENABLE: - builder.row( - InlineKeyboardButton( - text="💳 Пополнить баланс Freekassa", - callback_data="pay_freekassa", - ) - ) - if CRYPTO_BOT_ENABLE: - builder.row( - InlineKeyboardButton( - text="💳 Пополнить баланс CryptoBot", - callback_data="pay_cryptobot", - ) - ) - if STARS_ENABLE: - builder.row( - InlineKeyboardButton( - text="💳 Пополнить баланс Звездами", - callback_data="pay_stars", - ) + builder.row( + InlineKeyboardButton( + text="💳 Пополнить баланс", + callback_data="pay", ) + ) builder.row( InlineKeyboardButton(text="👥 Пригласить", callback_data="invite"), InlineKeyboardButton(text="📘 Инструкции", callback_data="instructions"), diff --git a/main.py b/main.py index 00e6b6fe..710ebb45 100644 --- a/main.py +++ b/main.py @@ -11,9 +11,9 @@ from config import CRYPTO_BOT_ENABLE, FREEKASSA_ENABLE, SUB_PATH, WEBAPP_HOST, W from database import init_db from handlers.keys.subscriptions import handle_subscription from handlers.notifications import notify_expiring_keys -from handlers.payment.cryprobot_pay import cryptobot_webhook -from handlers.payment.freekassa_pay import freekassa_webhook -from handlers.payment.yookassa_pay import yookassa_webhook +from handlers.payments.cryprobot_pay import cryptobot_webhook +from handlers.payments.freekassa_pay import freekassa_webhook +from handlers.payments.yookassa_pay import yookassa_webhook async def periodic_notifications():