From 1eb60dc0c23fc54b12e26ea5d4b54c1d9179e84b Mon Sep 17 00:00:00 2001 From: Vladless Date: Mon, 18 Nov 2024 22:40:59 +0300 Subject: [PATCH] renew/delete --- handlers/keys/keys.py | 20 ++++++++++++++------ handlers/payments/robokassa_pay.py | 7 +------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/handlers/keys/keys.py b/handlers/keys/keys.py index 8b2db79b..227637dd 100644 --- a/handlers/keys/keys.py +++ b/handlers/keys/keys.py @@ -408,7 +408,7 @@ async def process_callback_delete_key(callback_query: types.CallbackQuery): @router.callback_query(F.data.startswith("renew_key|")) async def process_callback_renew_key(callback_query: types.CallbackQuery): tg_id = callback_query.from_user.id - client_id = callback_query.data.split("|")[1] + key_name = callback_query.data.split("|")[1] try: try: @@ -421,11 +421,18 @@ async def process_callback_renew_key(callback_query: types.CallbackQuery): conn = await asyncpg.connect(DATABASE_URL) try: record = await conn.fetchrow( - "SELECT email, expiry_time FROM keys WHERE client_id = $1", client_id + """ + SELECT client_id, expiry_time + FROM keys + WHERE email = $1 + """, + key_name, ) if record: + client_id = record["client_id"] expiry_time = record["expiry_time"] + keyboard = types.InlineKeyboardMarkup( inline_keyboard=[ [ @@ -461,6 +468,7 @@ async def process_callback_renew_key(callback_query: types.CallbackQuery): ) balance = await get_balance(tg_id) + response_message = PLAN_SELECTION_MSG.format( balance=balance, expiry_date=datetime.utcfromtimestamp(expiry_time / 1000).strftime( @@ -474,8 +482,8 @@ async def process_callback_renew_key(callback_query: types.CallbackQuery): reply_markup=keyboard, parse_mode="HTML", ) - else: + # Если ключ не найден response_message = "Ключ не найден." await bot.send_message( chat_id=tg_id, text=response_message, parse_mode="HTML" @@ -497,17 +505,17 @@ async def process_callback_renew_key(callback_query: types.CallbackQuery): @router.callback_query(F.data.startswith("confirm_delete|")) async def process_callback_confirm_delete(callback_query: types.CallbackQuery): tg_id = callback_query.from_user.id - client_id = callback_query.data.split("|")[1] + email = callback_query.data.split("|")[1] try: conn = await asyncpg.connect(DATABASE_URL) try: record = await conn.fetchrow( - "SELECT email FROM keys WHERE client_id = $1", client_id + "SELECT client_id FROM keys WHERE email = $1", email ) if record: - email = record["email"] + client_id = record["client_id"] response_message = "Ключ успешно удален." back_button = types.InlineKeyboardButton( text="Назад", callback_data="view_keys" diff --git a/handlers/payments/robokassa_pay.py b/handlers/payments/robokassa_pay.py index 79e61ae0..181e7f64 100644 --- a/handlers/payments/robokassa_pay.py +++ b/handlers/payments/robokassa_pay.py @@ -295,12 +295,7 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext): await state.update_data(amount=amount) - payment_url = generate_payment_link( - amount, - inv_id, - "Пополнение баланса", - tg_id - ) + payment_url = generate_payment_link(amount, inv_id, "Пополнение баланса", tg_id) logger.info(f"Generated payment link for user {tg_id}: {payment_url}")