diff --git a/bot/handlers/user/payment.py b/bot/handlers/user/payment.py index ac01da8..76e7c2a 100644 --- a/bot/handlers/user/payment.py +++ b/bot/handlers/user/payment.py @@ -135,7 +135,10 @@ async def process_successful_payment(session: AsyncSession, bot: Bot, user_lang = db_user.language_code if db_user and db_user.language_code else settings.DEFAULT_LANGUAGE _ = lambda key, **kwargs: i18n.gettext(user_lang, key, **kwargs) - success_message = "" + config_link = activation_details.get("subscription_url") or _( + "config_link_not_available" + ) + if applied_referee_bonus_days_from_referral and final_end_date_for_user: inviter_name_display = _("friend_placeholder") if db_user and db_user.referred_by_id: @@ -146,42 +149,36 @@ async def process_successful_payment(session: AsyncSession, bot: Bot, elif inviter and inviter.username: inviter_name_display = f"@{inviter.username}" - success_message = _( - "payment_successful_with_referral_bonus", + details_message = _( + "payment_successful_with_referral_bonus_full", months=subscription_months, base_end_date=base_subscription_end_date.strftime('%Y-%m-%d'), bonus_days=applied_referee_bonus_days_from_referral, final_end_date=final_end_date_for_user.strftime('%Y-%m-%d'), - inviter_name=inviter_name_display) + inviter_name=inviter_name_display, + config_link=config_link, + ) elif applied_promo_bonus_days > 0 and final_end_date_for_user: - success_message = _( - "payment_successful_with_promo", + details_message = _( + "payment_successful_with_promo_full", months=subscription_months, bonus_days=applied_promo_bonus_days, - end_date=final_end_date_for_user.strftime('%Y-%m-%d')) + end_date=final_end_date_for_user.strftime('%Y-%m-%d'), + config_link=config_link, + ) elif final_end_date_for_user: - success_message = _( - "payment_successful", + details_message = _( + "payment_successful_full", months=subscription_months, - end_date=final_end_date_for_user.strftime('%Y-%m-%d')) + end_date=final_end_date_for_user.strftime('%Y-%m-%d'), + config_link=config_link, + ) else: logging.error( f"Critical error: final_end_date_for_user is None for user {user_id} after successful payment logic." ) - success_message = _("payment_successful_error_details") + details_message = _("payment_successful_error_details") - config_link = activation_details.get("subscription_url") or _( - "config_link_not_available" - ) - details_message = ( - success_message - + "\n\n" - + _( - "payment_successful_full", - end_date=final_end_date_for_user.strftime("%d.%m.%Y %H:%M:%S"), - config_link=config_link, - ) - ) details_markup = get_connect_and_main_keyboard( user_lang, i18n, settings, config_link ) diff --git a/bot/services/stars_service.py b/bot/services/stars_service.py index 840ec0f..524547b 100644 --- a/bot/services/stars_service.py +++ b/bot/services/stars_service.py @@ -11,6 +11,7 @@ from .subscription_service import SubscriptionService from .referral_service import ReferralService from bot.middlewares.i18n import JsonI18n from .notification_service import notify_admin_new_payment +from bot.keyboards.inline.user_keyboards import get_connect_and_main_keyboard class StarsService: @@ -108,6 +109,10 @@ class StarsService: i18n: JsonI18n = i18n_data.get("i18n_instance") _ = lambda k, **kw: i18n.gettext(current_lang, k, **kw) if i18n else k + config_link = activation_details.get("subscription_url") or _( + "config_link_not_available" + ) + if applied_days: inviter_name_display = _("friend_placeholder") db_user = await user_dal.get_user_by_id(session, message.from_user.id) @@ -118,18 +123,32 @@ class StarsService: elif inviter and inviter.username: inviter_name_display = f"@{inviter.username}" success_msg = _( - "payment_successful_with_referral_bonus", + "payment_successful_with_referral_bonus_full", months=months, base_end_date=activation_details["end_date"].strftime('%Y-%m-%d'), bonus_days=applied_days, final_end_date=final_end.strftime('%Y-%m-%d'), inviter_name=inviter_name_display, + config_link=config_link, ) else: - success_msg = _("payment_successful", months=months, - end_date=final_end.strftime('%Y-%m-%d')) + success_msg = _( + "payment_successful_full", + months=months, + end_date=final_end.strftime('%Y-%m-%d'), + config_link=config_link, + ) + markup = get_connect_and_main_keyboard( + current_lang, i18n, self.settings, config_link + ) try: - await self.bot.send_message(message.from_user.id, success_msg) + await self.bot.send_message( + message.from_user.id, + success_msg, + reply_markup=markup, + parse_mode="HTML", + disable_web_page_preview=True, + ) except Exception as e_send: logging.error( f"Failed to send stars payment success message: {e_send}") diff --git a/bot/services/tribute_service.py b/bot/services/tribute_service.py index 4424878..1d991b2 100644 --- a/bot/services/tribute_service.py +++ b/bot/services/tribute_service.py @@ -14,6 +14,7 @@ from bot.services.subscription_service import SubscriptionService from bot.services.panel_api_service import PanelApiService from bot.services.referral_service import ReferralService from .notification_service import notify_admin_new_payment +from bot.keyboards.inline.user_keyboards import get_connect_and_main_keyboard from db.dal import payment_dal, user_dal, subscription_dal @@ -137,6 +138,10 @@ class TributeService: final_end = activation_details.get('end_date') if final_end: + config_link = activation_details.get("subscription_url") or _( + "config_link_not_available" + ) + if applied_ref_days: inviter_name_display = _('friend_placeholder') if db_user and db_user.referred_by_id: @@ -146,19 +151,33 @@ class TributeService: elif inviter and inviter.username: inviter_name_display = f"@{inviter.username}" success_msg = _( - "payment_successful_with_referral_bonus", + "payment_successful_with_referral_bonus_full", months=months, base_end_date=activation_details["end_date"].strftime('%Y-%m-%d'), bonus_days=applied_ref_days, final_end_date=final_end.strftime('%Y-%m-%d'), - inviter_name=inviter_name_display) + inviter_name=inviter_name_display, + config_link=config_link, + ) else: success_msg = _( - "payment_successful", months=months, - end_date=final_end.strftime('%Y-%m-%d')) + "payment_successful_full", + months=months, + end_date=final_end.strftime('%Y-%m-%d'), + config_link=config_link, + ) + markup = get_connect_and_main_keyboard( + lang, i18n, settings, config_link + ) try: - await bot.send_message(user_id, success_msg) + await bot.send_message( + user_id, + success_msg, + reply_markup=markup, + parse_mode="HTML", + disable_web_page_preview=True, + ) except Exception as e: logging.error( f"Failed to send Tribute payment success message to user {user_id}: {e}") diff --git a/locales/en.json b/locales/en.json index 5bb4be4..a4bab78 100644 --- a/locales/en.json +++ b/locales/en.json @@ -36,11 +36,10 @@ "error_payment_gateway_link_failed": "Failed to get payment link. Please contact support.", "payment_link_message": "To pay for {months} mo. subscription, click the button below:", "error_payment_gateway": "Payment gateway error. Please try again later or contact support.", - "payment_successful": "✅ Payment successful!\nYour {months}-month subscription is active until {end_date}.", - "payment_successful_with_promo": "✅ Payment successful!\nYour {months}-month subscription (with promo bonus +{bonus_days} days) is active until {end_date}.", - "payment_successful_with_referral_bonus": "✅ Payment successful!\nYour {months}-month subscription (base end date: {base_end_date}) has been extended by {bonus_days} bonus days for referral from {inviter_name} and is now active until {final_end_date}.", "payment_successful_error_details": "✅ Payment succeeded, but an error occurred displaying details. Your subscription is active. Contact support if anything is wrong.", - "payment_successful_full": "Thank you for your purchase!\n\nSubscription paid until: {end_date}\n\nConnection key:\n{config_link}\n\nTo connect, open the link and follow the instructions 👇", + "payment_successful_full": "✅ Payment successful!\nYour {months}-month subscription is active until {end_date}.\n\nConnection key:\n{config_link}\n\nTo connect, open the link and follow the instructions 👇", + "payment_successful_with_promo_full": "✅ Payment successful!\nYour {months}-month subscription (with promo bonus +{bonus_days} days) is active until {end_date}.\n\nConnection key:\n{config_link}\n\nTo connect, open the link and follow the instructions 👇", + "payment_successful_with_referral_bonus_full": "✅ Payment successful!\nYour {months}-month subscription (base end date: {base_end_date}) has been extended by {bonus_days} bonus days for referral from {inviter_name} and is now active until {final_end_date}.\n\nConnection key:\n{config_link}\n\nTo connect, open the link and follow the instructions 👇", "payment_failed": "❌ Payment failed or was cancelled. Please try again or contact support.", "error_processing_your_payment": "An error occurred processing your payment after success. Please contact support with the details.", @@ -58,8 +57,7 @@ "promo_code_not_found": "Promo code {code} not found, expired, or already used the maximum number of times.", "promo_code_already_used_by_user": "You have already used promo code {code}.", "promo_code_no_active_subscription": "You must have an active subscription to apply this promo code.", - "promo_code_applied_success": "✅ Promo code {code} applied successfully!\nYour subscription is extended by {bonus_days} days and is now active until {new_end_date}.", - "promo_code_applied_success_full": "✅ Promo code applied successfully!\n\nSubscription active until: {end_date}\n\nConnection key:\n{config_link}\n\nTo connect, open the link and follow the instructions 👇", + "promo_code_applied_success_full": "✅ Promo code applied successfully!\nSubscription active until {end_date}.\n\nConnection key:\n{config_link}\n\nTo connect, open the link and follow the instructions 👇", "error_applying_promo_bonus": "Failed to apply promo bonus. Please try again later or contact support.", "promo_input_cancelled_short": "Promo code entry cancelled.", diff --git a/locales/ru.json b/locales/ru.json index 97b3cae..787edef 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -36,11 +36,10 @@ "error_payment_gateway_link_failed": "Не удалось получить ссылку на оплату. Пожалуйста, свяжитесь с поддержкой.", "payment_link_message": "Для оплаты подписки на {months} мес., нажмите кнопку ниже:", "error_payment_gateway": "Ошибка платежного шлюза. Попробуйте позже или свяжитесь с поддержкой.", - "payment_successful": "✅ Оплата прошла успешно!\nВаша подписка на {months} мес. активна до {end_date}.", - "payment_successful_with_promo": "✅ Оплата прошла успешно!\nВаша подписка на {months} мес. (с учетом промокода на +{bonus_days} дней) активна до {end_date}.", - "payment_successful_with_referral_bonus": "✅ Оплата прошла успешно!\nВаша подписка на {months} мес. (базовая дата окончания: {base_end_date}) продлена на {bonus_days} бонусных дней за приглашение от {inviter_name} и теперь активна до {final_end_date}.", "payment_successful_error_details": "✅ Оплата прошла успешно, но возникла ошибка при отображении деталей. Ваша подписка активна. Свяжитесь с поддержкой, если что-то не так.", - "payment_successful_full": "Спасибо за покупку!\n\nПодписка оплачена до: {end_date}\n\nКлюч подключения:\n{config_link}\n\nЧтобы подключиться, перейдите по ссылке и следуйте инструкции 👇", + "payment_successful_full": "✅ Оплата прошла успешно!\nВаша подписка на {months} мес. активна до {end_date}.\n\nКлюч подключения:\n{config_link}\n\nЧтобы подключиться, перейдите по ссылке и следуйте инструкции 👇", + "payment_successful_with_promo_full": "✅ Оплата прошла успешно!\nВаша подписка на {months} мес. (с учетом промокода на +{bonus_days} дней) активна до {end_date}.\n\nКлюч подключения:\n{config_link}\n\nЧтобы подключиться, перейдите по ссылке и следуйте инструкции 👇", + "payment_successful_with_referral_bonus_full": "✅ Оплата прошла успешно!\nВаша подписка на {months} мес. (базовая дата окончания: {base_end_date}) продлена на {bonus_days} бонусных дней за приглашение от {inviter_name} и теперь активна до {final_end_date}.\n\nКлюч подключения:\n{config_link}\n\nЧтобы подключиться, перейдите по ссылке и следуйте инструкции 👇", "payment_failed": "❌ Оплата не удалась или была отменена. Пожалуйста, попробуйте еще раз или свяжитесь с поддержкой.", "error_processing_your_payment": "Произошла ошибка при обработке вашего платежа после его успеха. Пожалуйста, свяжитесь с поддержкой, указав детали.", @@ -58,8 +57,7 @@ "promo_code_not_found": "Промокод {code} не найден, истек или уже использован максимальное количество раз.", "promo_code_already_used_by_user": "Вы уже активировали промокод {code}.", "promo_code_no_active_subscription": "Для активации этого промокода у вас должна быть активная подписка.", - "promo_code_applied_success": "✅ Промокод {code} успешно применен!\nВаша подписка продлена на {bonus_days} дней и теперь активна до {new_end_date}.", - "promo_code_applied_success_full": "✅ Промокод успешно применен!\n\nПодписка активна до: {end_date}\n\nКлюч подключения:\n{config_link}\n\nЧтобы подключиться, перейдите по ссылке и следуйте инструкции 👇", + "promo_code_applied_success_full": "✅ Промокод успешно применен!\nПодписка активна до {end_date}.\n\nКлюч подключения:\n{config_link}\n\nЧтобы подключиться, перейдите по ссылке и следуйте инструкции 👇", "error_applying_promo_bonus": "Не удалось применить бонус по промокоду. Пожалуйста, попробуйте позже или свяжитесь с поддержкой.", "promo_input_cancelled_short": "Ввод промокода отменен.",