diff --git a/app/handlers/subscription/purchase.py b/app/handlers/subscription/purchase.py index fa1b8bf2..58bad0b7 100644 --- a/app/handlers/subscription/purchase.py +++ b/app/handlers/subscription/purchase.py @@ -527,18 +527,7 @@ async def start_subscription_purchase( ): texts = get_texts(db_user.language) - # Если включена простая покупка, показываем дополнительную кнопку keyboard = get_subscription_period_keyboard(db_user.language) - - if settings.SIMPLE_SUBSCRIPTION_ENABLED: - # Добавляем кнопку простой подписки в начало клавиатуры - simple_subscription_button = [types.InlineKeyboardButton( - text="⚡ Простая покупка", - callback_data="simple_subscription_purchase" - )] - - # Вставляем кнопку в начало списка кнопок - keyboard.inline_keyboard.insert(0, simple_subscription_button) await callback.message.edit_text( await _build_subscription_period_prompt(db_user, texts, db), diff --git a/app/keyboards/inline.py b/app/keyboards/inline.py index 37e9633b..7d956998 100644 --- a/app/keyboards/inline.py +++ b/app/keyboards/inline.py @@ -257,7 +257,8 @@ def get_main_menu_keyboard( "💰 Баланс: {balance}", ).format(balance=texts.format_price(balance_kopeks)) - keyboard = [] + keyboard: list[list[InlineKeyboardButton]] = [] + paired_buttons: list[InlineKeyboardButton] = [] if has_active_subscription and subscription_is_active: connect_mode = settings.CONNECT_BUTTON_MODE @@ -312,22 +313,24 @@ def get_main_menu_keyboard( happ_row = get_happ_download_button_row(texts) if happ_row: keyboard.append(happ_row) - - keyboard.append([ - InlineKeyboardButton(text=balance_button_text, callback_data="menu_balance"), + paired_buttons.append( InlineKeyboardButton(text=texts.MENU_SUBSCRIPTION, callback_data="menu_subscription") - ]) - else: - keyboard.append([ - InlineKeyboardButton(text=balance_button_text, callback_data="menu_balance") - ]) + ) + + keyboard.append([InlineKeyboardButton(text=balance_button_text, callback_data="menu_balance")]) show_trial = not has_had_paid_subscription and not has_active_subscription show_buy = not has_active_subscription or not subscription_is_active - - subscription_buttons = [] - + simple_purchase_button = None + if settings.SIMPLE_SUBSCRIPTION_ENABLED: + simple_purchase_button = InlineKeyboardButton( + text=texts.MENU_SIMPLE_SUBSCRIPTION, + callback_data="simple_subscription_purchase", + ) + + subscription_buttons: list[InlineKeyboardButton] = [] + if show_trial: subscription_buttons.append( InlineKeyboardButton(text=texts.MENU_TRIAL, callback_data="menu_trial") @@ -337,48 +340,38 @@ def get_main_menu_keyboard( subscription_buttons.append( InlineKeyboardButton(text=texts.MENU_BUY_SUBSCRIPTION, callback_data="menu_buy") ) - - # Добавляем кнопку простой покупки после кнопки "Купить подписку" - if settings.SIMPLE_SUBSCRIPTION_ENABLED: - subscription_buttons.append( - InlineKeyboardButton(text="⚡ Простая покупка", callback_data="simple_subscription_purchase") - ) + if simple_purchase_button: + subscription_buttons.append(simple_purchase_button) + simple_purchase_button = None if subscription_buttons: - if len(subscription_buttons) == 2: - keyboard.append(subscription_buttons) - elif len(subscription_buttons) == 1: - keyboard.append([subscription_buttons[0]]) - elif len(subscription_buttons) > 2: - # Если больше 2 кнопок, добавляем по отдельности - for button in subscription_buttons: - keyboard.append([button]) + paired_buttons.extend(subscription_buttons) + if simple_purchase_button: + paired_buttons.append(simple_purchase_button) if show_resume_checkout or has_saved_cart: - keyboard.append([ + paired_buttons.append( InlineKeyboardButton( text=texts.RETURN_TO_SUBSCRIPTION_CHECKOUT, callback_data="subscription_resume_checkout", ) - ]) + ) if custom_buttons: for button in custom_buttons: if isinstance(button, InlineKeyboardButton): - keyboard.append([button]) + paired_buttons.append(button) # Добавляем кнопки промокода и рефералов, учитывая настройки - additional_buttons = [ + paired_buttons.append( InlineKeyboardButton(text=texts.MENU_PROMOCODE, callback_data="menu_promocode") - ] + ) # Добавляем кнопку рефералов только если программа включена if settings.is_referral_program_enabled(): - additional_buttons.append( + paired_buttons.append( InlineKeyboardButton(text=texts.MENU_REFERRALS, callback_data="menu_referrals") ) - - keyboard.append(additional_buttons) # Support button is configurable (runtime via service) try: @@ -387,21 +380,26 @@ def get_main_menu_keyboard( except Exception: support_enabled = settings.SUPPORT_MENU_ENABLED if support_enabled: - keyboard.append([ + paired_buttons.append( InlineKeyboardButton(text=texts.MENU_SUPPORT, callback_data="menu_support") - ]) + ) - keyboard.append([ + paired_buttons.append( InlineKeyboardButton( text=texts.t("MENU_INFO", "ℹ️ Инфо"), callback_data="menu_info", ) - ]) + ) if settings.is_language_selection_enabled(): - keyboard.append([ + paired_buttons.append( InlineKeyboardButton(text=texts.MENU_LANGUAGE, callback_data="menu_language") - ]) + ) + + for i in range(0, len(paired_buttons), 2): + row = paired_buttons[i : i + 2] + keyboard.append(row) + if settings.DEBUG: print(f"DEBUG KEYBOARD: is_admin={is_admin}, добавляем админ кнопку: {is_admin}") diff --git a/app/localization/locales/en.json b/app/localization/locales/en.json index ce20f3b2..0b8d8e95 100644 --- a/app/localization/locales/en.json +++ b/app/localization/locales/en.json @@ -1349,5 +1349,6 @@ "WELCOME_FALLBACK": "Welcome, {user_name}!", "YES": "✅ Yes", "SIMPLE_SUBSCRIPTION_TRIAL_NOTICE_ACTIVE": "ℹ️ Your trial subscription is active for another {days} days. Purchasing a new plan will extend the validity.", - "SIMPLE_SUBSCRIPTION_TRIAL_NOTICE_TRIAL": "ℹ️ Your trial is still running (expires in {days} days). Buying a paid plan will extend it automatically." + "SIMPLE_SUBSCRIPTION_TRIAL_NOTICE_TRIAL": "ℹ️ Your trial is still running (expires in {days} days). Buying a paid plan will extend it automatically.", + "MENU_SIMPLE_SUBSCRIPTION": "⚡ Quick purchase" } diff --git a/app/localization/locales/ru.json b/app/localization/locales/ru.json index 775273f0..b42a83c4 100644 --- a/app/localization/locales/ru.json +++ b/app/localization/locales/ru.json @@ -1349,5 +1349,6 @@ "WELCOME_FALLBACK": "Добро пожаловать, {user_name}!", "YES": "✅ Да", "SIMPLE_SUBSCRIPTION_TRIAL_NOTICE_ACTIVE": "ℹ️ У вас уже есть активная триальная подписка. Она будет действовать ещё {days} дн. После покупки к сроку добавится оплаченный период.", - "SIMPLE_SUBSCRIPTION_TRIAL_NOTICE_TRIAL": "ℹ️ У вас сейчас триальная подписка. Она истекает через {days} дн. Покупка новой продлит срок автоматически." + "SIMPLE_SUBSCRIPTION_TRIAL_NOTICE_TRIAL": "ℹ️ У вас сейчас триальная подписка. Она истекает через {days} дн. Покупка новой продлит срок автоматически.", + "MENU_SIMPLE_SUBSCRIPTION": "⚡ Простая покупка" }