fix back button in stars

This commit is contained in:
Vladless
2026-03-02 17:48:09 +03:00
parent 33a6da852e
commit d3dc53e9d5
2 changed files with 51 additions and 3 deletions
+34 -2
View File
@@ -250,6 +250,38 @@ async def try_fast_payment_flow(
return True
@router.callback_query(F.data == "fastflow_back")
async def fastflow_back(callback_query: CallbackQuery, state: FSMContext, session: Any):
"""Возврат из экрана выбора суммы в потоке /buy к выбору способа оплаты (без перехода на экран баланса)."""
amount_not_found_text = "Сумма не найдена"
data = await state.get_data()
temp_key = data.get("temp_key")
temp_payload = data.get("temp_payload")
required_amount = data.get("required_amount")
if not temp_key or not isinstance(temp_payload, dict) or required_amount is None:
await edit_or_send_message(
target_message=callback_query.message,
text=amount_not_found_text,
reply_markup=InlineKeyboardBuilder()
.row(InlineKeyboardButton(text=btn.MAIN_MENU, callback_data="profile"))
.as_markup(),
)
await callback_query.answer()
return
await try_fast_payment_flow(
callback_query,
session,
state,
tg_id=callback_query.from_user.id,
temp_key=str(temp_key),
temp_payload=dict(temp_payload),
required_amount=int(required_amount),
)
await callback_query.answer()
@router.callback_query(F.data == "fastflow_coupon_back")
async def fastflow_coupon_back(callback_query: CallbackQuery, state: FSMContext, session: Any):
amount_not_found_text = "Сумма не найдена"
@@ -390,11 +422,11 @@ async def fastflow_apply_coupon(message: Message, state: FSMContext, session: An
required_amount_new = int(max(0, ceil(float(new_price) - float(balance_now))))
percent_value = int(getattr(coupon, "percent", 0) or 0)
await create_coupon_usage(session, coupon.id, message.from_user.id)
await update_coupon_usage_count(session, coupon.id)
percent_value = int(getattr(coupon, "percent", 0) or 0)
temp_payload_updated = dict(temp_payload)
temp_payload_updated["required_amount"] = int(required_amount_new)
if "selected_price_rub" in temp_payload_updated:
+17 -1
View File
@@ -179,7 +179,23 @@ async def handle_pay_currency(callback_query: CallbackQuery, state: FSMContext,
@router.callback_query(F.data == "balance")
async def balance_handler(callback_query: CallbackQuery, session: AsyncSession):
async def balance_handler(callback_query: CallbackQuery, state: FSMContext, session: AsyncSession):
data = await state.get_data()
if data.get("temp_key") and data.get("required_amount") is not None:
from handlers.payments.fast_payment_flow import try_fast_payment_flow
await try_fast_payment_flow(
callback_query,
session,
state,
tg_id=callback_query.from_user.id,
temp_key=str(data["temp_key"]),
temp_payload=dict(data.get("temp_payload") or {}),
required_amount=int(data["required_amount"]),
)
await callback_query.answer()
return
stmt = select(User.balance).where(User.tg_id == callback_query.from_user.id)
result = await session.execute(stmt)
balance_rub = result.scalar_one_or_none() or 0.0