Add subscription link field to user model

- Add subscription_link column to users table (nullable, unique)
- Add SUBSCRIPTION_URL to config settings
- Update user creation to include subscription link from Remnawave
- Add support subscription ticket creation with formatted message
- Add "update link" button to main menu
- Refactor support subscription formatting to include user details
This commit is contained in:
2026-04-09 21:09:29 +07:00
parent 2bb12f2ff8
commit 60de871e0c
13 changed files with 408 additions and 114 deletions

View File

@@ -1,7 +1,9 @@
import logging
from typing import Optional
from aiogram import Router, F
from aiogram.types import CallbackQuery
from aiogram.fsm.context import FSMContext
from sqlalchemy.ext.asyncio import AsyncSession
from keyboards.client import (
devices_selector,
@@ -12,22 +14,26 @@ from keyboards.client import (
from misc.utils import (
calculate_price,
convert_int_to_duration,
format_support_subscription,
)
from schemas.di import DependenciesDTO
from schemas.subscriptions import SubscriptionPlan
from services.user_service import UserServiceException
from states.buy import SubscriptionStorage
from texts import (
CALLBACK_FALLBACK,
CHECKOUT_PAYMENT_CHOICE,
CONTEXT_REINITIATED,
GENERAL_PROCESSING,
NOTHING_PLACEHOLDER,
STANDARD_FALLBACK,
SUBSCRIPTION_DEVICE_SELECTOR,
SUBSCRIPTION_DURATION_SELECTOR,
SUPPORT_MSG_SENT,
)
from config import settings
router = Router()
logger = logging.getLogger(__name__)
@router.callback_query(F.data == "buy")
@@ -160,6 +166,36 @@ async def proceed_to_checkout(cb: CallbackQuery, state: FSMContext):
return
await cb.message.edit_text(
CHECKOUT_PAYMENT_CHOICE.format(code=format_support_subscription(ctx)),
CHECKOUT_PAYMENT_CHOICE,
reply_markup=payment_gateways,
) # FIXME: temp solution that's incredibly stupid
await state.set_state(SubscriptionStorage.checkout)
await state.set_data({"ctx": ctx})
@router.callback_query(F.data == "checkout")
async def checkout_support(
cb: CallbackQuery, state: FSMContext, session: AsyncSession, deps: DependenciesDTO
):
data = await state.get_data()
await state.clear()
ctx: Optional[SubscriptionPlan] = data.get("ctx")
if not ctx:
await cb.message.edit_text(STANDARD_FALLBACK, reply_markup=return_to_menu)
return
await cb.message.edit_text(GENERAL_PROCESSING)
try:
await deps.user_service.create_subscription_ticket(
session, cb.from_user, ctx, cb.bot
)
await cb.message.edit_text(SUPPORT_MSG_SENT)
except UserServiceException:
await cb.message.edit_text(STANDARD_FALLBACK)
raise
except Exception:
await cb.message.edit_text(STANDARD_FALLBACK)
logger.exception("Exception occured while trying to forward a msg to support")
raise