somethjijngs
This commit is contained in:
@@ -3,14 +3,25 @@ from aiogram import Router, F
|
|||||||
from aiogram.types import CallbackQuery
|
from aiogram.types import CallbackQuery
|
||||||
from aiogram.fsm.context import FSMContext
|
from aiogram.fsm.context import FSMContext
|
||||||
|
|
||||||
from keyboards.client import devices_selector, duration_selector
|
from keyboards.client import (
|
||||||
from misc.utils import calculate_price, convert_int_to_duration
|
devices_selector,
|
||||||
|
duration_selector,
|
||||||
|
return_to_menu,
|
||||||
|
payment_gateways,
|
||||||
|
)
|
||||||
|
from misc.utils import (
|
||||||
|
calculate_price,
|
||||||
|
convert_int_to_duration,
|
||||||
|
format_support_subscription,
|
||||||
|
)
|
||||||
from schemas.subscriptions import SubscriptionPlan
|
from schemas.subscriptions import SubscriptionPlan
|
||||||
from states.buy import SubscriptionStorage
|
from states.buy import SubscriptionStorage
|
||||||
from texts import (
|
from texts import (
|
||||||
CALLBACK_FALLBACK,
|
CALLBACK_FALLBACK,
|
||||||
|
CHECKOUT_PAYMENT_CHOICE,
|
||||||
CONTEXT_REINITIATED,
|
CONTEXT_REINITIATED,
|
||||||
NOTHING_PLACEHOLDER,
|
NOTHING_PLACEHOLDER,
|
||||||
|
STANDARD_FALLBACK,
|
||||||
SUBSCRIPTION_DEVICE_SELECTOR,
|
SUBSCRIPTION_DEVICE_SELECTOR,
|
||||||
SUBSCRIPTION_DURATION_SELECTOR,
|
SUBSCRIPTION_DURATION_SELECTOR,
|
||||||
)
|
)
|
||||||
@@ -58,18 +69,13 @@ async def toggle_whitelists(cb: CallbackQuery, state: FSMContext):
|
|||||||
data = await state.get_data()
|
data = await state.get_data()
|
||||||
await state.clear()
|
await state.clear()
|
||||||
|
|
||||||
ctx: Optional[SubscriptionPlan] = data.get("ctx")
|
ctx: Optional[SubscriptionPlan] = data.get("ctx", SubscriptionPlan())
|
||||||
if not ctx:
|
|
||||||
await state.set_state(SubscriptionPlan())
|
|
||||||
await state.set_data({"ctx": ctx})
|
|
||||||
await cb.answer(CALLBACK_FALLBACK)
|
|
||||||
return
|
|
||||||
ctx.whitelists = (
|
ctx.whitelists = (
|
||||||
not ctx.whitelists or ctx.devices >= settings.whitelist_device_threshold
|
not ctx.whitelists or ctx.devices >= settings.whitelist_device_threshold
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await cb.message.edit_reply_markup(
|
await cb.message.edit_text(
|
||||||
SUBSCRIPTION_DEVICE_SELECTOR.format(price=calculate_price(ctx)),
|
SUBSCRIPTION_DEVICE_SELECTOR.format(price=calculate_price(ctx)),
|
||||||
reply_markup=devices_selector(
|
reply_markup=devices_selector(
|
||||||
current=ctx.devices, whitelists=ctx.whitelists
|
current=ctx.devices, whitelists=ctx.whitelists
|
||||||
@@ -91,8 +97,6 @@ async def select_duration_init(cb: CallbackQuery, state: FSMContext):
|
|||||||
|
|
||||||
ctx: Optional[SubscriptionPlan] = data.get("ctx")
|
ctx: Optional[SubscriptionPlan] = data.get("ctx")
|
||||||
if not ctx:
|
if not ctx:
|
||||||
await state.set_state(SubscriptionPlan())
|
|
||||||
await state.set_data({"ctx": ctx})
|
|
||||||
await cb.answer(CALLBACK_FALLBACK)
|
await cb.answer(CALLBACK_FALLBACK)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -121,8 +125,6 @@ async def select_duration(cb: CallbackQuery, state: FSMContext):
|
|||||||
|
|
||||||
ctx: Optional[SubscriptionPlan] = data.get("ctx")
|
ctx: Optional[SubscriptionPlan] = data.get("ctx")
|
||||||
if not ctx:
|
if not ctx:
|
||||||
await state.set_state()
|
|
||||||
await state.set_data({"ctx": ctx})
|
|
||||||
await cb.answer(CONTEXT_REINITIATED)
|
await cb.answer(CONTEXT_REINITIATED)
|
||||||
ctx = SubscriptionPlan()
|
ctx = SubscriptionPlan()
|
||||||
|
|
||||||
@@ -149,5 +151,15 @@ async def select_duration(cb: CallbackQuery, state: FSMContext):
|
|||||||
|
|
||||||
@router.callback_query(SubscriptionStorage.duration, F.data == "confirm")
|
@router.callback_query(SubscriptionStorage.duration, F.data == "confirm")
|
||||||
async def proceed_to_checkout(cb: CallbackQuery, state: FSMContext):
|
async def proceed_to_checkout(cb: CallbackQuery, state: FSMContext):
|
||||||
await cb.answer("yay!!!! fuck off.")
|
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(
|
||||||
|
CHECKOUT_PAYMENT_CHOICE.format(code=format_support_subscription(ctx)),
|
||||||
|
reply_markup=payment_gateways,
|
||||||
|
) # FIXME: temp solution that's incredibly stupid
|
||||||
|
|||||||
@@ -51,11 +51,13 @@ async def received_message(
|
|||||||
F.message_thread_id.is_not(None),
|
F.message_thread_id.is_not(None),
|
||||||
F.from_user.is_bot == False, # noqa: E712
|
F.from_user.is_bot == False, # noqa: E712
|
||||||
~Command("close"),
|
~Command("close"),
|
||||||
|
F.text,
|
||||||
)
|
)
|
||||||
async def handle_admin_message(
|
async def handle_admin_message(
|
||||||
msg: Message, state: FSMContext, session: AsyncSession, deps: DependenciesDTO
|
msg: Message, state: FSMContext, session: AsyncSession, deps: DependenciesDTO
|
||||||
):
|
):
|
||||||
await state.clear()
|
await state.clear()
|
||||||
|
print(str(msg))
|
||||||
|
|
||||||
await deps.user_service.support_answer(session, msg)
|
await deps.user_service.support_answer(session, msg)
|
||||||
|
|
||||||
|
|||||||
@@ -86,3 +86,11 @@ def duration_selector(
|
|||||||
builder.row(_return_btn(back_cb))
|
builder.row(_return_btn(back_cb))
|
||||||
|
|
||||||
return builder.as_markup()
|
return builder.as_markup()
|
||||||
|
|
||||||
|
|
||||||
|
payment_gateways: InlineKeyboardMarkup = InlineKeyboardBuilder(
|
||||||
|
[
|
||||||
|
[InlineKeyboardButton(text="✍️ Поддержка", callback_data="support")],
|
||||||
|
[_return_to_menu_btn],
|
||||||
|
]
|
||||||
|
).as_markup()
|
||||||
|
|||||||
@@ -169,3 +169,18 @@ def calculate_price(subscription: SubscriptionPlan):
|
|||||||
else 0
|
else 0
|
||||||
)
|
)
|
||||||
) * convert_duration_to_int(subscription.duration)
|
) * convert_duration_to_int(subscription.duration)
|
||||||
|
|
||||||
|
|
||||||
|
def format_support_subscription(subscription: SubscriptionPlan) -> str:
|
||||||
|
whitelist_description = "ВЫКЛ"
|
||||||
|
if subscription.devices >= settings.whitelist_device_threshold:
|
||||||
|
whitelist_description = "ВКЛ (Бесплатно)"
|
||||||
|
elif subscription.whitelists:
|
||||||
|
whitelist_description = "ВКЛ (Платно)"
|
||||||
|
|
||||||
|
return (
|
||||||
|
f"Подписка на {convert_duration_to_int(subscription.duration)} месяцев.\n"
|
||||||
|
f"Количество устройств: {subscription.devices}\n"
|
||||||
|
f"Белые списки: {whitelist_description}\n\n"
|
||||||
|
f"Итого: {calculate_price(subscription)}₽"
|
||||||
|
)
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ class UserService:
|
|||||||
await self.ticket_repository.update_ticket_status(
|
await self.ticket_repository.update_ticket_status(
|
||||||
session, ticket, TicketStatus.CLOSED
|
session, ticket, TicketStatus.CLOSED
|
||||||
)
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
rw_user = await get_user_by_telegram_id(rw, user.id)
|
rw_user = await get_user_by_telegram_id(rw, user.id)
|
||||||
creator = TicketCreator(id=user.id, username=msg.from_user.username)
|
creator = TicketCreator(id=user.id, username=msg.from_user.username)
|
||||||
|
|||||||
7
texts.py
7
texts.py
@@ -38,6 +38,13 @@ STANDARD_FALLBACK = (
|
|||||||
"<b>❌ Что-то пошло не так</b>, прожмите /start и повторите попытку позже."
|
"<b>❌ Что-то пошло не так</b>, прожмите /start и повторите попытку позже."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TEMP_SUPPORT_FORM = (
|
||||||
|
"обратитесь в поддержку, прикрепив текст ниже:\n\n" "<code>\n" "{code}\n" "</code>"
|
||||||
|
)
|
||||||
|
CHECKOUT_PAYMENT_CHOICE = (
|
||||||
|
"в поддержку чирканите епта там всё обьяснят\n" + TEMP_SUPPORT_FORM
|
||||||
|
)
|
||||||
|
|
||||||
CALLBACK_FALLBACK = "❌ Что-то пошло не так"
|
CALLBACK_FALLBACK = "❌ Что-то пошло не так"
|
||||||
CONTEXT_REINITIATED = "🔴 Контекст данного взаимодействия сброшен. Данные могут отличаться от указанных вами."
|
CONTEXT_REINITIATED = "🔴 Контекст данного взаимодействия сброшен. Данные могут отличаться от указанных вами."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user