fix: 3 bugs — notification type, referral with channel sub, BOT_USERNAME

1. Admin notification showed "renewal" instead of "first purchase" for new
   users because has_had_paid_subscription was set before notification.
   All 21 call sites now pass explicit purchase_type.

2. Partner referral not counted when mandatory channel subscription enabled.
   required_sub_channel_check saved campaign_id but not referrer_id from
   campaign.partner_user_id. Also removed duplicate DB query.

3. BOT_USERNAME auto-detection moved before web server start to close
   race window on /cabinet/branding/telegram-widget endpoint.
This commit is contained in:
Fringg
2026-03-10 21:18:58 +03:00
parent 541f64d5bc
commit 3c96c2affd
13 changed files with 40 additions and 18 deletions
+5 -1
View File
@@ -295,6 +295,11 @@ async def main():
bot, dp = await setup_bot()
stage.log('Кеш и FSM подготовлены')
bot_user = await bot.get_me()
if bot_user.username and not settings.BOT_USERNAME:
settings.BOT_USERNAME = bot_user.username
logger.info('BOT_USERNAME auto-detected', bot_username=bot_user.username)
monitoring_service.bot = bot
maintenance_service.set_bot(bot)
broadcast_service.set_bot(bot)
@@ -516,7 +521,6 @@ async def main():
success_message='Токен внешней админки готов',
) as stage:
try:
bot_user = await bot.get_me()
token = await ensure_external_admin_token(
bot_user.username,
bot_user.id,