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:
@@ -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
|
||||
|
||||
@@ -4,9 +4,10 @@ from aiogram.types import CallbackQuery, Message
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from misc.utils import format_subscription_link
|
||||
from schemas.di import DependenciesDTO
|
||||
from keyboards.client import main_menu
|
||||
from texts import build_main_menu_text
|
||||
from keyboards.client import main_menu, return_to_menu
|
||||
from texts import GENERAL_PROCESSING, build_main_menu_text, FAQ_TEXT
|
||||
|
||||
router = Router()
|
||||
|
||||
@@ -27,9 +28,14 @@ async def fetch_referal(
|
||||
return
|
||||
|
||||
referal = data[0]
|
||||
await deps.user_service.add_user(session, user_id=msg.from_user.id, referal=referal)
|
||||
user = await deps.user_service.add_user(
|
||||
session, user_id=msg.from_user.id, referal=referal, rw_sdk=deps.rw_sdk
|
||||
)
|
||||
|
||||
await msg.reply(build_main_menu_text(), reply_markup=main_menu)
|
||||
await msg.reply(
|
||||
build_main_menu_text(format_subscription_link(user.subscription_link)),
|
||||
reply_markup=main_menu,
|
||||
)
|
||||
|
||||
|
||||
@router.message(Command(commands=["start", "cancel"]))
|
||||
@@ -42,13 +48,48 @@ async def standard_start(
|
||||
):
|
||||
await state.clear()
|
||||
|
||||
await deps.user_service.add_user(session, user_id=msg.from_user.id)
|
||||
user = await deps.user_service.add_user(
|
||||
session, user_id=msg.from_user.id, rw_sdk=deps.rw_sdk
|
||||
)
|
||||
|
||||
await msg.reply(build_main_menu_text(), reply_markup=main_menu)
|
||||
await msg.reply(
|
||||
build_main_menu_text(format_subscription_link(user.subscription_link)),
|
||||
reply_markup=main_menu,
|
||||
)
|
||||
|
||||
|
||||
@router.callback_query(F.data == "menu:main")
|
||||
async def main_menu_cb(cb: CallbackQuery, state: FSMContext):
|
||||
async def main_menu_cb(
|
||||
cb: CallbackQuery, state: FSMContext, session: AsyncSession, deps: DependenciesDTO
|
||||
):
|
||||
await state.clear()
|
||||
|
||||
await cb.message.edit_text(build_main_menu_text(), reply_markup=main_menu)
|
||||
user = await deps.user_repository.get_user_by_id(session, cb.from_user.id)
|
||||
await cb.message.edit_text(
|
||||
build_main_menu_text(format_subscription_link(user.subscription_link)),
|
||||
reply_markup=main_menu,
|
||||
)
|
||||
|
||||
|
||||
@router.callback_query(F.data == "update_link")
|
||||
async def update_link(
|
||||
cb: CallbackQuery, state: FSMContext, session: AsyncSession, deps: DependenciesDTO
|
||||
):
|
||||
await state.clear()
|
||||
await cb.message.edit_text(GENERAL_PROCESSING)
|
||||
|
||||
user = await deps.user_service.update_user_link(
|
||||
session, cb.from_user.id, deps.rw_sdk
|
||||
)
|
||||
await cb.answer("✅")
|
||||
await cb.message.edit_text(
|
||||
build_main_menu_text(format_subscription_link(user.subscription_link)),
|
||||
reply_markup=main_menu,
|
||||
)
|
||||
|
||||
|
||||
@router.callback_query(F.data == "faq")
|
||||
async def faq(cb: CallbackQuery, state: FSMContext):
|
||||
await state.clear()
|
||||
|
||||
await cb.message.edit_text(FAQ_TEXT, reply_markup=return_to_menu)
|
||||
|
||||
Reference in New Issue
Block a user