From 33d573daa1c593ecbcc32bd23fd819bc779b8b1f Mon Sep 17 00:00:00 2001 From: Boris Kovalskii <36034823+JustYay@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:52:01 +0000 Subject: [PATCH] =?UTF-8?q?FIX=20"=D0=A1=D0=BE=D0=BE=D0=B1=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=20=D0=BC=D0=B8=D0=BD=D0=B8=D0=BC?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=20=D0=B1=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=D1=81=D0=B5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/payments/heleket/handlers.py | 9 ++- handlers/payments/heleket/service.py | 90 +++++++++++---------------- handlers/payments/kassai/handlers.py | 20 +++++- handlers/payments/kassai/service.py | 61 ++++++++++++++++-- 4 files changed, 120 insertions(+), 60 deletions(-) diff --git a/handlers/payments/heleket/handlers.py b/handlers/payments/heleket/handlers.py index 830e97f8..29c1e2fd 100644 --- a/handlers/payments/heleket/handlers.py +++ b/handlers/payments/heleket/handlers.py @@ -47,7 +47,7 @@ async def handle_custom_amount_input_heleket( return if amount < 10: - await edit_or_send_message(target_message=message, text="❌ Минимальная сумма для оплаты криптовалютой — 10 рублей.") + await edit_or_send_message(target_message=message, text="❌ Минимальная сумма для оплаты криптовалютой — 10₽ (≈0.1$).") return enabled_methods = [m for m in HELEKET_PAYMENT_METHODS if m["enable"]] @@ -58,6 +58,13 @@ async def handle_custom_amount_input_heleket( try: payment_url = await generate_heleket_payment_link(amount, tg_id, method) + + if not payment_url or payment_url == "https://heleket.com/": + await edit_or_send_message( + target_message=message, + text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.", + ) + return markup = InlineKeyboardMarkup( inline_keyboard=[ diff --git a/handlers/payments/heleket/service.py b/handlers/payments/heleket/service.py index d9c84d4a..8bb3c95d 100644 --- a/handlers/payments/heleket/service.py +++ b/handlers/payments/heleket/service.py @@ -11,6 +11,7 @@ from aiogram.fsm.state import State, StatesGroup from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup from aiogram.utils.keyboard import InlineKeyboardBuilder from sqlalchemy.ext.asyncio import AsyncSession +from handlers.payments.currency_rates import format_for_user from config import ( HELEKET_API_KEY, @@ -21,7 +22,7 @@ from config import ( PROVIDERS_ENABLED, ) from handlers.payments.providers import get_providers -from ..currency_rates import get_rub_rate +from handlers.payments.currency_rates import get_rub_rate from handlers.buttons import BACK, HELEKET, PAY_2 from handlers.texts import ENTER_SUM, HELEKET_CRYPTO_DESCRIPTION, HELEKET_PAYMENT_MESSAGE from handlers.payments.keyboards import build_amounts_keyboard, payment_options_for_user, parse_amount_from_callback, pay_keyboard @@ -229,7 +230,7 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext, if user_amount < min_amount: await edit_or_send_message( target_message=message, - text=f"Минимальная сумма для оплаты криптовалютой — {currency_symbol}{min_amount}.", + text=f"❌ Минимальная сумма для оплаты криптовалютой — {currency_symbol}{min_amount}.", reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), force_text=True, ) @@ -237,7 +238,7 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext, except Exception: await edit_or_send_message( target_message=message, - text="Некорректная сумма. Введите целое число больше 0.", + text="❌ Некорректная сумма. Введите целое число больше 0.", reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), force_text=True, ) @@ -253,6 +254,15 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext, await state.update_data(amount=amount_rub) payment_url = await generate_heleket_payment_link(amount_rub, message.chat.id, method) + if not payment_url or payment_url == "https://heleket.com/": + await edit_or_send_message( + target_message=message, + text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.", + reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), + force_text=True, + ) + return + confirm_keyboard = pay_keyboard(payment_url, pay_text=PAY_2, back_cb="balance") from ..currency_rates import format_for_user @@ -269,56 +279,8 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext, await state.set_state(ReplenishBalanceHeleket.waiting_for_payment_confirmation) -async def process_fast_flow_heleket( - callback_query: types.CallbackQuery, - state: FSMContext, - session: AsyncSession, - amount: int, - method_name: str = "crypto", -): - method = next((m for m in HELEKET_PAYMENT_METHODS if m["name"] == method_name and m["enable"]), None) - if not method: - await edit_or_send_message( - target_message=callback_query.message, - text="Ошибка: выбранный способ оплаты недоступен.", - reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), - force_text=True, - ) - return - - if amount <= 0: - await edit_or_send_message( - target_message=callback_query.message, - text="Некорректная сумма.", - reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), - force_text=True, - ) - return - if amount < 10: - await edit_or_send_message( - target_message=callback_query.message, - text="Минимальная сумма для оплаты криптовалютой — 10 рублей.", - reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), - force_text=True, - ) - return - - await state.update_data(heleket_method=method_name, amount=amount) - payment_url = await generate_heleket_payment_link(amount, callback_query.message.chat.id, method) - - confirm_keyboard = pay_keyboard(payment_url, pay_text=PAY_2, back_cb="balance") - - await edit_or_send_message( - target_message=callback_query.message, - text=HELEKET_PAYMENT_MESSAGE.format(amount=amount), - reply_markup=confirm_keyboard, - force_text=True, - ) - await state.set_state(ReplenishBalanceHeleket.waiting_for_payment_confirmation) - - @router.callback_query(F.data.startswith("heleket_crypto_amount|")) -async def process_amount_selection(callback_query: types.CallbackQuery, state: FSMContext): +async def process_amount_selection(callback_query: types.CallbackQuery, state: FSMContext, session: AsyncSession): amount = parse_amount_from_callback(callback_query.data, prefixes=["heleket_crypto"]) if amount is None: await edit_or_send_message( @@ -341,14 +303,36 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F ) return + if amount < 10: + await edit_or_send_message( + target_message=callback_query.message, + text="❌ Минимальная сумма для оплаты криптовалютой — 10₽ (≈0.1$).", + reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), + force_text=True, + ) + return + await state.update_data(amount=amount) payment_url = await generate_heleket_payment_link(amount, callback_query.message.chat.id, method) + if not payment_url or payment_url == "https://heleket.com/": + await edit_or_send_message( + target_message=callback_query.message, + text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.", + reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), + force_text=True, + ) + return + confirm_keyboard = pay_keyboard(payment_url, pay_text=PAY_2, back_cb="balance") + tg_id = callback_query.from_user.id + language_code = await get_user_language(session, tg_id) + amount_text = await format_for_user(session, tg_id, float(amount), language_code) + await edit_or_send_message( target_message=callback_query.message, - text=HELEKET_PAYMENT_MESSAGE.format(amount=amount), + text=HELEKET_PAYMENT_MESSAGE.format(amount=amount_text), reply_markup=confirm_keyboard, force_text=True, ) diff --git a/handlers/payments/kassai/handlers.py b/handlers/payments/kassai/handlers.py index 44e9833f..c4759a55 100644 --- a/handlers/payments/kassai/handlers.py +++ b/handlers/payments/kassai/handlers.py @@ -51,6 +51,10 @@ async def handle_custom_amount_input_kassai_cards( await edit_or_send_message(target_message=message, text="❌ Не удалось определить сумму оплаты.") return + if amount < 50: + await edit_or_send_message(target_message=message, text="❌ Минимальная сумма для оплаты картой — 50₽.") + return + method = next((m for m in KASSAI_PAYMENT_METHODS if m["name"] == "cards" and m["enable"]), None) if not method: await edit_or_send_message(target_message=message, text="❌ Оплата картами KassaAI временно недоступна.") @@ -58,6 +62,13 @@ async def handle_custom_amount_input_kassai_cards( try: payment_url = await generate_kassai_payment_link(amount, tg_id, method) + + if not payment_url or payment_url == "https://fk.life/": + await edit_or_send_message( + target_message=message, + text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.", + ) + return markup = InlineKeyboardMarkup( inline_keyboard=[ @@ -108,7 +119,7 @@ async def handle_custom_amount_input_kassai_sbp( return if amount < 10: - await edit_or_send_message(target_message=message, text="❌ Минимальная сумма для оплаты через СБП — 10 рублей.") + await edit_or_send_message(target_message=message, text="❌ Минимальная сумма для оплаты через СБП — 10₽.") return method = next((m for m in KASSAI_PAYMENT_METHODS if m["name"] == "sbp" and m["enable"]), None) @@ -118,6 +129,13 @@ async def handle_custom_amount_input_kassai_sbp( try: payment_url = await generate_kassai_payment_link(amount, tg_id, method) + + if not payment_url or payment_url == "https://fk.life/": + await edit_or_send_message( + target_message=message, + text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.", + ) + return markup = InlineKeyboardMarkup( inline_keyboard=[ diff --git a/handlers/payments/kassai/service.py b/handlers/payments/kassai/service.py index 55efd253..cb1ac35f 100644 --- a/handlers/payments/kassai/service.py +++ b/handlers/payments/kassai/service.py @@ -9,6 +9,7 @@ from aiogram.fsm.state import State, StatesGroup from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup from aiogram.utils.keyboard import InlineKeyboardBuilder from sqlalchemy.ext.asyncio import AsyncSession +from handlers.payments.currency_rates import format_for_user from config import ( KASSAI_API_KEY, @@ -224,13 +225,24 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext, if user_amount <= 0: raise ValueError - if method_name == "sbp": + if method_name == "cards": + min_amount = 1 if currency == "USD" else 50 + currency_symbol = "$" if currency == "USD" else "₽" + if user_amount < min_amount: + await edit_or_send_message( + target_message=message, + text=f"❌ Минимальная сумма для оплаты картой — {currency_symbol}{min_amount}.", + reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), + force_text=True, + ) + return + elif method_name == "sbp": min_amount = 1 if currency == "USD" else 10 currency_symbol = "$" if currency == "USD" else "₽" if user_amount < min_amount: await edit_or_send_message( target_message=message, - text=f"Минимальная сумма для оплаты через СБП — {currency_symbol}{min_amount}.", + text=f"❌ Минимальная сумма для оплаты через СБП — {currency_symbol}{min_amount}.", reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), force_text=True, ) @@ -238,7 +250,7 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext, except Exception: await edit_or_send_message( target_message=message, - text="Некорректная сумма. Введите целое число больше 0.", + text="❌ Некорректная сумма. Введите целое число больше 0.", reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), force_text=True, ) @@ -254,6 +266,15 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext, await state.update_data(amount=amount_rub) payment_url = await generate_kassai_payment_link(amount_rub, message.chat.id, method) + if not payment_url or payment_url == "https://fk.life/": + await edit_or_send_message( + target_message=message, + text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.", + reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), + force_text=True, + ) + return + confirm_keyboard = pay_keyboard(payment_url, pay_text=PAY_2, back_cb="balance") tg_id = message.from_user.id @@ -270,7 +291,7 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext, @router.callback_query(F.data.startswith("kassai_cards_amount|") | F.data.startswith("kassai_sbp_amount|")) -async def process_amount_selection(callback_query: types.CallbackQuery, state: FSMContext): +async def process_amount_selection(callback_query: types.CallbackQuery, state: FSMContext, session: AsyncSession): amount = parse_amount_from_callback(callback_query.data, prefixes=["kassai_cards", "kassai_sbp"]) if amount is None: await edit_or_send_message( @@ -293,14 +314,44 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F ) return + if method_name == "cards" and amount < 50: + await edit_or_send_message( + target_message=callback_query.message, + text="❌ Минимальная сумма для оплаты картой — 50₽.", + reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), + force_text=True, + ) + return + elif method_name == "sbp" and amount < 10: + await edit_or_send_message( + target_message=callback_query.message, + text="❌ Минимальная сумма для оплаты через СБП — 10₽.", + reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), + force_text=True, + ) + return + await state.update_data(amount=amount) payment_url = await generate_kassai_payment_link(amount, callback_query.message.chat.id, method) + if not payment_url or payment_url == "https://fk.life/": + await edit_or_send_message( + target_message=callback_query.message, + text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.", + reply_markup=InlineKeyboardMarkup(inline_keyboard=[]), + force_text=True, + ) + return + confirm_keyboard = pay_keyboard(payment_url, pay_text=PAY_2, back_cb="balance") + tg_id = callback_query.from_user.id + language_code = await get_user_language(session, tg_id) + amount_text = await format_for_user(session, tg_id, float(amount), language_code) + await edit_or_send_message( target_message=callback_query.message, - text=KASSAI_PAYMENT_MESSAGE.format(amount=amount), + text=KASSAI_PAYMENT_MESSAGE.format(amount=amount_text), reply_markup=confirm_keyboard, force_text=True, )