diff --git a/app/handlers/subscription.py b/app/handlers/subscription.py
index 58ade4a1..f3defc9b 100644
--- a/app/handlers/subscription.py
+++ b/app/handlers/subscription.py
@@ -34,7 +34,8 @@ from app.keyboards.inline import (
get_manage_countries_keyboard,
get_device_selection_keyboard, get_connection_guide_keyboard,
get_app_selection_keyboard, get_specific_app_keyboard,
- get_subscription_settings_keyboard, get_extend_subscription_keyboard_with_prices
+ get_subscription_settings_keyboard, get_extend_subscription_keyboard_with_prices,
+ get_insufficient_balance_keyboard
)
from app.localization.texts import get_texts
from app.services.remnawave_service import RemnaWaveService
@@ -1796,9 +1797,10 @@ async def confirm_purchase(
logger.info(f" ИТОГО: {final_price/100}₽")
if db_user.balance_kopeks < final_price:
+ missing_kopeks = final_price - db_user.balance_kopeks
await callback.message.edit_text(
- texts.INSUFFICIENT_BALANCE,
- reply_markup=get_back_keyboard(db_user.language)
+ texts.INSUFFICIENT_BALANCE.format(amount=texts.format_price(missing_kopeks)),
+ reply_markup=get_insufficient_balance_keyboard(db_user.language),
)
await callback.answer()
return
@@ -1810,9 +1812,10 @@ async def confirm_purchase(
)
if not success:
+ missing_kopeks = final_price - db_user.balance_kopeks
await callback.message.edit_text(
- texts.INSUFFICIENT_BALANCE,
- reply_markup=get_back_keyboard(db_user.language)
+ texts.INSUFFICIENT_BALANCE.format(amount=texts.format_price(missing_kopeks)),
+ reply_markup=get_insufficient_balance_keyboard(db_user.language),
)
await callback.answer()
return
diff --git a/app/keyboards/inline.py b/app/keyboards/inline.py
index 047038ce..7b421dca 100644
--- a/app/keyboards/inline.py
+++ b/app/keyboards/inline.py
@@ -104,6 +104,19 @@ def get_back_keyboard(language: str = "ru") -> InlineKeyboardMarkup:
])
+def get_insufficient_balance_keyboard(language: str = "ru") -> InlineKeyboardMarkup:
+ texts = get_texts(language)
+ return InlineKeyboardMarkup(inline_keyboard=[
+ [
+ InlineKeyboardButton(
+ text=texts.GO_TO_BALANCE_TOP_UP,
+ callback_data="balance_topup",
+ )
+ ],
+ [InlineKeyboardButton(text=texts.BACK, callback_data="back_to_menu")],
+ ])
+
+
def get_subscription_keyboard(
language: str = "ru",
has_subscription: bool = False,
@@ -415,15 +428,7 @@ def get_balance_keyboard(language: str = "ru") -> InlineKeyboardMarkup:
def get_payment_methods_keyboard(amount_kopeks: int, language: str = "ru") -> InlineKeyboardMarkup:
texts = get_texts(language)
keyboard = []
-
- if settings.TELEGRAM_STARS_ENABLED:
- keyboard.append([
- InlineKeyboardButton(
- text="⭐ Telegram Stars",
- callback_data="topup_stars"
- )
- ])
-
+
if settings.is_yookassa_enabled():
keyboard.append([
InlineKeyboardButton(
@@ -435,11 +440,19 @@ def get_payment_methods_keyboard(amount_kopeks: int, language: str = "ru") -> In
if settings.TRIBUTE_ENABLED:
keyboard.append([
InlineKeyboardButton(
- text="💎 Банковская карта (Tribute)",
+ text="💳 Банковская карта (Tribute)",
callback_data="topup_tribute"
)
])
-
+
+ if settings.TELEGRAM_STARS_ENABLED:
+ keyboard.append([
+ InlineKeyboardButton(
+ text="⭐ Telegram Stars",
+ callback_data="topup_stars"
+ )
+ ])
+
keyboard.append([
InlineKeyboardButton(
text="🛠️ Через поддержку",
diff --git a/app/localization/texts.py b/app/localization/texts.py
index d04e6716..30fafb78 100644
--- a/app/localization/texts.py
+++ b/app/localization/texts.py
@@ -204,7 +204,11 @@ class RussianTexts(Texts):
Подтвердить покупку?
"""
- INSUFFICIENT_BALANCE = "❌ Недостаточно средств на балансе. Пополните баланс и попробуйте снова."
+ INSUFFICIENT_BALANCE = """❌ Недостаточно средств на балансе.
+
+ Пополните баланс на {amount} и попробуйте снова.
+ """
+ GO_TO_BALANCE_TOP_UP = "💳 Перейти к пополнению баланса"
SUBSCRIPTION_PURCHASED = "🎉 Подписка успешно приобретена!"
BALANCE_INFO = """
@@ -443,10 +447,14 @@ To get started, select interface language:
CONTINUE = "➡️ Continue"
YES = "✅ Yes"
NO = "❌ No"
-
+
MENU_BALANCE = "💰 Balance"
MENU_SUBSCRIPTION = "📱 Subscription"
MENU_TRIAL = "🎁 Trial subscription"
+ INSUFFICIENT_BALANCE = """❌ Insufficient balance. " \
+
+ Top up {amount} and try again."""
+ GO_TO_BALANCE_TOP_UP = "💳 Go to balance top up"
LANGUAGES = {
diff --git a/app/services/referral_service.py b/app/services/referral_service.py
index 2639653f..1a4c59c9 100644
--- a/app/services/referral_service.py
+++ b/app/services/referral_service.py
@@ -63,7 +63,8 @@ async def process_referral_registration(
f"👥 Новый реферал!\n\n"
f"По вашей ссылке зарегистрировался пользователь {new_user.full_name}!\n\n"
f"💰 Когда он пополнит баланс от {settings.format_price(settings.REFERRAL_MINIMUM_TOPUP_KOPEKS)}, "
- f"вы получите {settings.format_price(settings.REFERRAL_INVITER_BONUS_KOPEKS)}\n\n"
+ f"вы получите минимум {settings.format_price(settings.REFERRAL_INVITER_BONUS_KOPEKS)} или "
+ f"{settings.REFERRAL_COMMISSION_PERCENT}% от суммы (что больше).\n\n"
f"📈 С каждого последующего пополнения вы будете получать {settings.REFERRAL_COMMISSION_PERCENT}% комиссии."
)
await send_referral_notification(bot, referrer.telegram_id, inviter_notification)
@@ -131,27 +132,30 @@ async def process_referral_topup(
)
await send_referral_notification(bot, user.telegram_id, bonus_notification)
- if settings.REFERRAL_INVITER_BONUS_KOPEKS > 0:
+ commission_amount = int(topup_amount_kopeks * settings.REFERRAL_COMMISSION_PERCENT / 100)
+ inviter_bonus = max(settings.REFERRAL_INVITER_BONUS_KOPEKS, commission_amount)
+
+ if inviter_bonus > 0:
await add_user_balance(
- db, referrer, settings.REFERRAL_INVITER_BONUS_KOPEKS,
+ db, referrer, inviter_bonus,
f"Бонус за первое пополнение реферала {user.full_name}",
bot=bot
)
-
+
await create_referral_earning(
db=db,
user_id=referrer.id,
- referral_id=user.id,
- amount_kopeks=settings.REFERRAL_INVITER_BONUS_KOPEKS,
+ referral_id=user.id,
+ amount_kopeks=inviter_bonus,
reason="referral_first_topup"
)
- logger.info(f"💰 Реферер {referrer.telegram_id} получил бонус {settings.REFERRAL_INVITER_BONUS_KOPEKS/100}₽")
-
+ logger.info(f"💰 Реферер {referrer.telegram_id} получил бонус {inviter_bonus/100}₽")
+
if bot:
inviter_bonus_notification = (
f"💰 Реферальная награда!\n\n"
f"Ваш реферал {user.full_name} сделал первое пополнение!\n\n"
- f"🎁 Вы получили награду: {settings.format_price(settings.REFERRAL_INVITER_BONUS_KOPEKS)}\n\n"
+ f"🎁 Вы получили награду: {settings.format_price(inviter_bonus)}\n\n"
f"📈 Теперь с каждого его пополнения вы будете получать {settings.REFERRAL_COMMISSION_PERCENT}% комиссии."
)
await send_referral_notification(bot, referrer.telegram_id, inviter_bonus_notification)