Merge pull request #256 from JustYay/dev
HOTFIX "Консистеность касс V2"
This commit is contained in:
@@ -135,7 +135,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="Ошибка: данные повреждены.",
|
||||
reply_markup=types.InlineKeyboardMarkup(),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -150,7 +149,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="Некорректная сумма.",
|
||||
reply_markup=types.InlineKeyboardMarkup(),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -175,7 +173,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text=DEFAULT_PAYMENT_MESSAGE.format(amount=amount),
|
||||
reply_markup=confirm_keyboard,
|
||||
force_text=True,
|
||||
)
|
||||
logger.info(f"Payment link sent to user {callback_query.message.chat.id}.")
|
||||
|
||||
@@ -280,7 +277,6 @@ async def process_custom_amount_selection(callback_query: types.CallbackQuery, s
|
||||
target_message=callback_query.message,
|
||||
text=ENTER_SUM,
|
||||
reply_markup=builder.as_markup(),
|
||||
force_text=True,
|
||||
)
|
||||
|
||||
await state.set_state(ReplenishBalanceState.waiting_for_payment_confirmation_freekassa)
|
||||
|
||||
@@ -14,7 +14,7 @@ from logger import logger
|
||||
from ..constants import ALLOWED_TEMP_PAYMENT_STATES
|
||||
|
||||
from .service import (
|
||||
HELEKET_PAYMENT_METHODS,
|
||||
HELEKET_METHODS,
|
||||
generate_heleket_payment_link,
|
||||
process_callback_pay_heleket,
|
||||
router as service_router,
|
||||
@@ -75,7 +75,7 @@ async def handle_custom_amount_input_heleket(
|
||||
)
|
||||
return
|
||||
|
||||
enabled_methods = [m for m in HELEKET_PAYMENT_METHODS if m["enable"]]
|
||||
enabled_methods = [m for m in HELEKET_METHODS.values() if m["enable"]]
|
||||
if not enabled_methods:
|
||||
await edit_or_send_message(
|
||||
target_message=message,
|
||||
|
||||
@@ -64,17 +64,9 @@ class ReplenishBalanceHeleket(StatesGroup):
|
||||
entering_custom_amount = State()
|
||||
|
||||
|
||||
PROVIDERS = get_providers(PROVIDERS_ENABLED)
|
||||
HELEKET_PAYMENT_METHODS = [
|
||||
{
|
||||
"enable": bool(PROVIDERS.get("HELEKET", {}).get("enabled")),
|
||||
"currency": (PROVIDERS.get("HELEKET", {}).get("currency") or "USD"),
|
||||
"to_currency": None,
|
||||
"name": "crypto",
|
||||
"button": HELEKET,
|
||||
"desc": HELEKET_CRYPTO_DESCRIPTION,
|
||||
},
|
||||
]
|
||||
HELEKET_METHODS = {
|
||||
"crypto": {"enable": PROVIDERS_ENABLED.get("HELEKET", False), "currency": "USD", "to_currency": None, "button": HELEKET, "desc": HELEKET_CRYPTO_DESCRIPTION},
|
||||
}
|
||||
|
||||
|
||||
async def process_callback_pay_heleket(
|
||||
@@ -86,18 +78,15 @@ async def process_callback_pay_heleket(
|
||||
await state.clear()
|
||||
|
||||
if not method_name:
|
||||
enabled_methods = [m["name"] for m in HELEKET_PAYMENT_METHODS if m["enable"]]
|
||||
enabled_methods = [name for name, m in HELEKET_METHODS.items() if m["enable"]]
|
||||
if len(enabled_methods) == 1:
|
||||
method_name = enabled_methods[0]
|
||||
|
||||
if method_name:
|
||||
method = next((m for m in HELEKET_PAYMENT_METHODS if m["name"] == method_name and m["enable"]), None)
|
||||
if not method:
|
||||
try:
|
||||
await callback_query.message.delete()
|
||||
except Exception:
|
||||
pass
|
||||
await callback_query.message.answer(
|
||||
method = HELEKET_METHODS.get(method_name)
|
||||
if not method or not method["enable"]:
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text="Ошибка: выбранный способ оплаты недоступен.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
)
|
||||
@@ -115,40 +104,36 @@ async def process_callback_pay_heleket(
|
||||
opts=opts
|
||||
)
|
||||
|
||||
try:
|
||||
await callback_query.message.delete()
|
||||
except Exception:
|
||||
pass
|
||||
new_msg = await callback_query.message.answer(
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text=method["desc"],
|
||||
reply_markup=builder,
|
||||
)
|
||||
|
||||
await state.update_data(
|
||||
heleket_method=method_name,
|
||||
message_id=new_msg.message_id,
|
||||
chat_id=new_msg.chat.id,
|
||||
message_id=callback_query.message.message_id,
|
||||
chat_id=callback_query.message.chat.id,
|
||||
)
|
||||
await state.set_state(ReplenishBalanceHeleket.choosing_amount)
|
||||
return
|
||||
|
||||
builder = InlineKeyboardBuilder()
|
||||
for method in HELEKET_PAYMENT_METHODS:
|
||||
for name, method in HELEKET_METHODS.items():
|
||||
if method["enable"]:
|
||||
builder.row(
|
||||
InlineKeyboardButton(text=method["button"], callback_data=f"heleket_method|{method['name']}")
|
||||
InlineKeyboardButton(text=method["button"], callback_data=f"heleket_method|{name}")
|
||||
)
|
||||
builder.row(InlineKeyboardButton(text=BACK, callback_data="balance"))
|
||||
|
||||
try:
|
||||
await callback_query.message.delete()
|
||||
except Exception:
|
||||
pass
|
||||
new_msg = await callback_query.message.answer(
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text="Выберите способ оплаты через Heleket:",
|
||||
reply_markup=builder.as_markup(),
|
||||
)
|
||||
await state.update_data(message_id=new_msg.message_id, chat_id=new_msg.chat.id)
|
||||
await state.update_data(
|
||||
message_id=callback_query.message.message_id,
|
||||
chat_id=callback_query.message.chat.id,
|
||||
)
|
||||
await state.set_state(ReplenishBalanceHeleket.choosing_method)
|
||||
|
||||
except Exception as e:
|
||||
@@ -159,14 +144,13 @@ async def process_callback_pay_heleket(
|
||||
@router.callback_query(F.data.startswith("heleket_method|"))
|
||||
async def process_method_selection(callback_query: types.CallbackQuery, state: FSMContext, session: AsyncSession):
|
||||
method_name = callback_query.data.split("|")[1]
|
||||
method = next((m for m in HELEKET_PAYMENT_METHODS if m["name"] == method_name), None)
|
||||
method = HELEKET_METHODS.get(method_name)
|
||||
|
||||
if not method or not method["enable"]:
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text="Ошибка: выбранный способ оплаты недоступен.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -189,7 +173,6 @@ async def process_method_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text=method["desc"],
|
||||
reply_markup=builder,
|
||||
force_text=True,
|
||||
)
|
||||
await state.update_data(message_id=callback_query.message.message_id, chat_id=callback_query.message.chat.id)
|
||||
await state.set_state(ReplenishBalanceHeleket.choosing_amount)
|
||||
@@ -211,7 +194,6 @@ async def process_custom_amount_button(callback_query: types.CallbackQuery, stat
|
||||
target_message=callback_query.message,
|
||||
text=f"Пожалуйста, введите сумму пополнения в {currency_text}.",
|
||||
reply_markup=builder.as_markup(),
|
||||
force_text=True,
|
||||
)
|
||||
await state.set_state(ReplenishBalanceHeleket.entering_custom_amount)
|
||||
|
||||
@@ -220,14 +202,13 @@ async def process_custom_amount_button(callback_query: types.CallbackQuery, stat
|
||||
async def handle_custom_amount_input(message: types.Message, state: FSMContext, session: AsyncSession):
|
||||
data = await state.get_data()
|
||||
method_name = data.get("heleket_method")
|
||||
method = next((m for m in HELEKET_PAYMENT_METHODS if m["name"] == method_name), None)
|
||||
method = HELEKET_METHODS.get(method_name)
|
||||
|
||||
if not method or not method["enable"]:
|
||||
await edit_or_send_message(
|
||||
target_message=message,
|
||||
text="Ошибка: выбранный способ оплаты недоступен.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -247,7 +228,6 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext,
|
||||
target_message=message,
|
||||
text=f"❌ Минимальная сумма для оплаты криптовалютой — {currency_symbol}{min_amount}.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
except Exception:
|
||||
@@ -255,7 +235,6 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext,
|
||||
target_message=message,
|
||||
text="❌ Некорректная сумма. Введите целое число больше 0.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -273,7 +252,6 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext,
|
||||
target_message=message,
|
||||
text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -286,7 +264,6 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext,
|
||||
target_message=message,
|
||||
text=HELEKET_PAYMENT_MESSAGE.format(amount=amount_text),
|
||||
reply_markup=confirm_keyboard,
|
||||
force_text=True,
|
||||
)
|
||||
|
||||
await state.set_state(ReplenishBalanceHeleket.waiting_for_payment_confirmation)
|
||||
@@ -300,19 +277,17 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="Некорректная сумма.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
method_name = "crypto"
|
||||
method = next((m for m in HELEKET_PAYMENT_METHODS if m["name"] == method_name), None)
|
||||
method = HELEKET_METHODS.get(method_name)
|
||||
|
||||
if not method or not method["enable"]:
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text="Ошибка: выбранный способ оплаты недоступен.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -321,7 +296,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="❌ Минимальная сумма для оплаты криптовалютой — 10₽ (≈0.1$).",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -333,7 +307,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -347,7 +320,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text=HELEKET_PAYMENT_MESSAGE.format(amount=amount_text),
|
||||
reply_markup=confirm_keyboard,
|
||||
force_text=True,
|
||||
)
|
||||
|
||||
await state.set_state(ReplenishBalanceHeleket.waiting_for_payment_confirmation)
|
||||
@@ -371,17 +343,6 @@ async def generate_heleket_payment_link(amount: int, tg_id: int, method: dict) -
|
||||
rate = await get_rub_rate(pay_cur, session=session)
|
||||
payment_amount = (Decimal(str(amount)) * rate).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
|
||||
|
||||
async with async_session_maker() as dbs:
|
||||
await add_payment(
|
||||
session=dbs,
|
||||
tg_id=tg_id,
|
||||
amount=float(amount),
|
||||
payment_system="HELEKET",
|
||||
status="pending",
|
||||
currency="RUB",
|
||||
payment_id=unique_order_id,
|
||||
)
|
||||
|
||||
data = {
|
||||
"amount": str(payment_amount),
|
||||
"currency": method["currency"],
|
||||
@@ -412,6 +373,16 @@ async def generate_heleket_payment_link(amount: int, tg_id: int, method: dict) -
|
||||
if resp_json.get("state") == 0:
|
||||
payment_url = resp_json.get("result", {}).get("url")
|
||||
if payment_url:
|
||||
async with async_session_maker() as dbs:
|
||||
await add_payment(
|
||||
session=dbs,
|
||||
tg_id=tg_id,
|
||||
amount=float(amount),
|
||||
payment_system="HELEKET",
|
||||
status="pending",
|
||||
currency="RUB",
|
||||
payment_id=unique_order_id,
|
||||
)
|
||||
logger.info(f"Heleket payment URL created for user {tg_id}")
|
||||
return payment_url
|
||||
else:
|
||||
|
||||
@@ -124,26 +124,12 @@ async def process_heleket_webhook(data: dict) -> bool:
|
||||
payment = await get_payment_by_payment_id(session, order_id)
|
||||
if payment:
|
||||
if payment.get("status") == "success":
|
||||
logger.info(
|
||||
f"Heleket: платёж {order_id} уже обработан"
|
||||
)
|
||||
logger.info(f"Heleket: платёж {order_id} уже обработан")
|
||||
return True
|
||||
ok = await update_payment_status(
|
||||
session=session,
|
||||
internal_id=int(payment["id"]),
|
||||
new_status="success",
|
||||
)
|
||||
ok = await update_payment_status(session=session, internal_id=int(payment["id"]), new_status="success")
|
||||
if not ok:
|
||||
logger.error(
|
||||
f"Heleket: не удалось обновить статус "
|
||||
f"платежа {order_id}"
|
||||
)
|
||||
logger.error(f"Heleket: не удалось обновить статус платежа {order_id}")
|
||||
return False
|
||||
await update_balance(session, tg_id, balance_amount)
|
||||
await send_payment_success_notification(
|
||||
tg_id, balance_amount, session
|
||||
)
|
||||
await session.commit()
|
||||
else:
|
||||
await add_payment(
|
||||
session=session,
|
||||
@@ -155,11 +141,9 @@ async def process_heleket_webhook(data: dict) -> bool:
|
||||
payment_id=order_id,
|
||||
metadata=None,
|
||||
)
|
||||
await update_balance(session, tg_id, balance_amount)
|
||||
await send_payment_success_notification(
|
||||
tg_id, balance_amount, session
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
await update_balance(session, tg_id, balance_amount)
|
||||
await send_payment_success_notification(tg_id, balance_amount, session)
|
||||
logger.info(
|
||||
f"Heleket: платёж {order_id} для пользователя {tg_id} "
|
||||
f"успешно обработан, баланс пополнен на {balance_amount} RUB"
|
||||
|
||||
@@ -14,7 +14,7 @@ from logger import logger
|
||||
from ..constants import ALLOWED_TEMP_PAYMENT_STATES
|
||||
|
||||
from .service import (
|
||||
KASSAI_PAYMENT_METHODS,
|
||||
KASSAI_METHODS,
|
||||
generate_kassai_payment_link,
|
||||
process_callback_pay_kassai,
|
||||
router as service_router,
|
||||
@@ -104,15 +104,8 @@ async def _handle_custom_amount_input_kassai(
|
||||
)
|
||||
return
|
||||
|
||||
method = next(
|
||||
(
|
||||
m
|
||||
for m in KASSAI_PAYMENT_METHODS
|
||||
if m["name"] == method_name and m["enable"]
|
||||
),
|
||||
None,
|
||||
)
|
||||
if not method:
|
||||
method = KASSAI_METHODS.get(method_name)
|
||||
if not method or not method["enable"]:
|
||||
method_label = "картами" if method_name == "cards" else "через СБП"
|
||||
await edit_or_send_message(
|
||||
target_message=message,
|
||||
|
||||
@@ -20,6 +20,7 @@ from config import (
|
||||
KASSAI_SUCCESS_URL,
|
||||
PROVIDERS_ENABLED,
|
||||
)
|
||||
from database import add_payment, async_session_maker
|
||||
from database.models import User
|
||||
from handlers.buttons import BACK, KASSAI_CARDS, KASSAI_SBP, PAY_2
|
||||
from handlers.payments.currency_rates import (
|
||||
@@ -63,23 +64,10 @@ class ReplenishBalanceKassaiState(StatesGroup):
|
||||
entering_custom_amount = State()
|
||||
|
||||
|
||||
PROVIDERS = get_providers(PROVIDERS_ENABLED)
|
||||
KASSAI_PAYMENT_METHODS = [
|
||||
{
|
||||
"enable": bool(PROVIDERS.get("KASSAI_CARDS", {}).get("enabled")),
|
||||
"method": 36,
|
||||
"name": "cards",
|
||||
"button": KASSAI_CARDS,
|
||||
"desc": KASSAI_CARDS_DESCRIPTION,
|
||||
},
|
||||
{
|
||||
"enable": bool(PROVIDERS.get("KASSAI_SBP", {}).get("enabled")),
|
||||
"method": 44,
|
||||
"name": "sbp",
|
||||
"button": KASSAI_SBP,
|
||||
"desc": KASSAI_SBP_DESCRIPTION,
|
||||
},
|
||||
]
|
||||
KASSAI_METHODS = {
|
||||
"cards": {"enable": PROVIDERS_ENABLED.get("KASSAI_CARDS", False), "method": 36, "button": KASSAI_CARDS, "desc": KASSAI_CARDS_DESCRIPTION},
|
||||
"sbp": {"enable": PROVIDERS_ENABLED.get("KASSAI_SBP", False), "method": 44, "button": KASSAI_SBP, "desc": KASSAI_SBP_DESCRIPTION},
|
||||
}
|
||||
|
||||
|
||||
@router.callback_query(F.data == "pay_kassai")
|
||||
@@ -96,20 +84,10 @@ async def process_callback_pay_kassai(
|
||||
await state.clear()
|
||||
|
||||
if method_name:
|
||||
method = next(
|
||||
(
|
||||
m
|
||||
for m in KASSAI_PAYMENT_METHODS
|
||||
if m["name"] == method_name and m["enable"]
|
||||
),
|
||||
None,
|
||||
)
|
||||
if not method:
|
||||
try:
|
||||
await callback_query.message.delete()
|
||||
except Exception:
|
||||
pass
|
||||
await callback_query.message.answer(
|
||||
method = KASSAI_METHODS.get(method_name)
|
||||
if not method or not method["enable"]:
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text="Ошибка: выбранный способ оплаты недоступен.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
)
|
||||
@@ -127,43 +105,38 @@ async def process_callback_pay_kassai(
|
||||
opts=opts,
|
||||
)
|
||||
|
||||
try:
|
||||
await callback_query.message.delete()
|
||||
except Exception:
|
||||
pass
|
||||
new_msg = await callback_query.message.answer(
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text=method["desc"],
|
||||
reply_markup=builder,
|
||||
)
|
||||
await state.update_data(
|
||||
kassai_method=method_name,
|
||||
message_id=new_msg.message_id,
|
||||
chat_id=new_msg.chat.id,
|
||||
message_id=callback_query.message.message_id,
|
||||
chat_id=callback_query.message.chat.id,
|
||||
)
|
||||
await state.set_state(ReplenishBalanceKassaiState.choosing_amount)
|
||||
return
|
||||
|
||||
builder = InlineKeyboardBuilder()
|
||||
for method in KASSAI_PAYMENT_METHODS:
|
||||
for name, method in KASSAI_METHODS.items():
|
||||
if method["enable"]:
|
||||
builder.row(
|
||||
InlineKeyboardButton(
|
||||
text=method["button"],
|
||||
callback_data=f"kassai_method|{method['name']}",
|
||||
callback_data=f"kassai_method|{name}",
|
||||
)
|
||||
)
|
||||
builder.row(InlineKeyboardButton(text=BACK, callback_data="balance"))
|
||||
|
||||
try:
|
||||
await callback_query.message.delete()
|
||||
except Exception:
|
||||
pass
|
||||
new_msg = await callback_query.message.answer(
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text="Выберите способ оплаты через KassaAI:",
|
||||
reply_markup=builder.as_markup(),
|
||||
)
|
||||
await state.update_data(
|
||||
message_id=new_msg.message_id, chat_id=new_msg.chat.id
|
||||
message_id=callback_query.message.message_id,
|
||||
chat_id=callback_query.message.chat.id,
|
||||
)
|
||||
await state.set_state(ReplenishBalanceKassaiState.choosing_method)
|
||||
|
||||
@@ -181,14 +154,13 @@ async def process_callback_pay_kassai(
|
||||
@router.callback_query(F.data.startswith("kassai_method|"))
|
||||
async def process_method_selection(callback_query: types.CallbackQuery, state: FSMContext, session: AsyncSession):
|
||||
method_name = callback_query.data.split("|")[1]
|
||||
method = next((m for m in KASSAI_PAYMENT_METHODS if m["name"] == method_name), None)
|
||||
method = KASSAI_METHODS.get(method_name)
|
||||
|
||||
if not method or not method["enable"]:
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text="Ошибка: выбранный способ оплаты недоступен.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -211,7 +183,6 @@ async def process_method_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text=method["desc"],
|
||||
reply_markup=builder,
|
||||
force_text=True,
|
||||
)
|
||||
await state.update_data(message_id=callback_query.message.message_id, chat_id=callback_query.message.chat.id)
|
||||
await state.set_state(ReplenishBalanceKassaiState.choosing_amount)
|
||||
@@ -233,7 +204,6 @@ async def process_custom_amount_button(callback_query: types.CallbackQuery, stat
|
||||
target_message=callback_query.message,
|
||||
text=f"Пожалуйста, введите сумму пополнения в {currency_text}.",
|
||||
reply_markup=builder.as_markup(),
|
||||
force_text=True,
|
||||
)
|
||||
await state.set_state(ReplenishBalanceKassaiState.entering_custom_amount)
|
||||
|
||||
@@ -242,14 +212,13 @@ async def process_custom_amount_button(callback_query: types.CallbackQuery, stat
|
||||
async def handle_custom_amount_input(message: types.Message, state: FSMContext, session: AsyncSession):
|
||||
data = await state.get_data()
|
||||
method_name = data.get("kassai_method")
|
||||
method = next((m for m in KASSAI_PAYMENT_METHODS if m["name"] == method_name), None)
|
||||
method = KASSAI_METHODS.get(method_name)
|
||||
|
||||
if not method or not method["enable"]:
|
||||
await edit_or_send_message(
|
||||
target_message=message,
|
||||
text="Ошибка: выбранный способ оплаты недоступен.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -269,7 +238,6 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext,
|
||||
target_message=message,
|
||||
text=f"❌ Минимальная сумма для оплаты картой — {currency_symbol}{min_amount}.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
elif method_name == "sbp":
|
||||
@@ -280,7 +248,6 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext,
|
||||
target_message=message,
|
||||
text=f"❌ Минимальная сумма для оплаты через СБП — {currency_symbol}{min_amount}.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
except Exception:
|
||||
@@ -288,7 +255,6 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext,
|
||||
target_message=message,
|
||||
text="❌ Некорректная сумма. Введите целое число больше 0.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -306,7 +272,6 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext,
|
||||
target_message=message,
|
||||
text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -319,7 +284,6 @@ async def handle_custom_amount_input(message: types.Message, state: FSMContext,
|
||||
target_message=message,
|
||||
text=KASSAI_PAYMENT_MESSAGE.format(amount=amount_text),
|
||||
reply_markup=confirm_keyboard,
|
||||
force_text=True,
|
||||
)
|
||||
|
||||
await state.set_state(ReplenishBalanceKassaiState.waiting_for_payment_confirmation)
|
||||
@@ -333,19 +297,17 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="Некорректная сумма.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
method_name = "cards" if callback_query.data.startswith("kassai_cards") else "sbp"
|
||||
method = next((m for m in KASSAI_PAYMENT_METHODS if m["name"] == method_name), None)
|
||||
method = KASSAI_METHODS.get(method_name)
|
||||
|
||||
if not method or not method["enable"]:
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text="Ошибка: выбранный способ оплаты недоступен.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -354,7 +316,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="❌ Минимальная сумма для оплаты картой — 50₽.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
elif method_name == "sbp" and amount < 10:
|
||||
@@ -362,7 +323,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="❌ Минимальная сумма для оплаты через СБП — 10₽.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -374,7 +334,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="❌ Произошла ошибка при создании платежа. Попробуйте позже или выберите другой способ оплаты.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -388,7 +347,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text=KASSAI_PAYMENT_MESSAGE.format(amount=amount_text),
|
||||
reply_markup=confirm_keyboard,
|
||||
force_text=True,
|
||||
)
|
||||
|
||||
await state.set_state(ReplenishBalanceKassaiState.waiting_for_payment_confirmation)
|
||||
@@ -434,6 +392,16 @@ async def generate_kassai_payment_link(amount: int, tg_id: int, method: dict) ->
|
||||
if resp_json.get("type") == "success":
|
||||
payment_url = resp_json.get("location")
|
||||
if payment_url:
|
||||
async with async_session_maker() as dbs:
|
||||
await add_payment(
|
||||
session=dbs,
|
||||
tg_id=tg_id,
|
||||
amount=float(amount),
|
||||
payment_system="KASSAI",
|
||||
status="pending",
|
||||
currency="RUB",
|
||||
payment_id=unique_payment_id,
|
||||
)
|
||||
logger.info(f"KassaAI payment URL created for user {tg_id}")
|
||||
return payment_url
|
||||
logger.error(f"KassaAI: No location in response: {resp_json}")
|
||||
|
||||
@@ -89,26 +89,12 @@ async def kassai_webhook(request: web.Request):
|
||||
payment = await get_payment_by_payment_id(session, order_id)
|
||||
if payment:
|
||||
if payment.get("status") == "success":
|
||||
logger.info(
|
||||
f"KassaAI: платёж {order_id} уже обработан"
|
||||
)
|
||||
logger.info(f"KassaAI: платёж {order_id} уже обработан")
|
||||
return web.Response(text=KASSAI_WEBHOOK_RESPONSE)
|
||||
ok = await update_payment_status(
|
||||
session=session,
|
||||
internal_id=int(payment["id"]),
|
||||
new_status="success",
|
||||
)
|
||||
ok = await update_payment_status(session=session, internal_id=int(payment["id"]), new_status="success")
|
||||
if not ok:
|
||||
logger.error(
|
||||
f"KassaAI: не удалось обновить статус "
|
||||
f"платежа {order_id}"
|
||||
)
|
||||
logger.error(f"KassaAI: не удалось обновить статус платежа {order_id}")
|
||||
return web.Response(status=500)
|
||||
await update_balance(session, tg_id, amount)
|
||||
await send_payment_success_notification(
|
||||
tg_id, amount, session
|
||||
)
|
||||
await session.commit()
|
||||
else:
|
||||
await add_payment(
|
||||
session=session,
|
||||
@@ -120,11 +106,9 @@ async def kassai_webhook(request: web.Request):
|
||||
payment_id=order_id,
|
||||
metadata=None,
|
||||
)
|
||||
await update_balance(session, tg_id, amount)
|
||||
await send_payment_success_notification(
|
||||
tg_id, amount, session
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
await update_balance(session, tg_id, amount)
|
||||
await send_payment_success_notification(tg_id, amount, session)
|
||||
logger.info(
|
||||
f"KassaAI: платёж {order_id} успешно обработан, "
|
||||
f"баланс пользователя {tg_id} пополнен на {amount} RUB"
|
||||
|
||||
@@ -61,9 +61,12 @@ async def process_callback_pay_robokassa(callback_query: types.CallbackQuery, st
|
||||
opts=opts,
|
||||
)
|
||||
|
||||
await callback_query.message.delete()
|
||||
m = await callback_query.message.answer(text="Выберите сумму пополнения:", reply_markup=markup)
|
||||
await state.update_data(message_id=m.message_id, chat_id=m.chat.id)
|
||||
await edit_or_send_message(
|
||||
target_message=callback_query.message,
|
||||
text="Выберите сумму пополнения:",
|
||||
reply_markup=markup,
|
||||
)
|
||||
await state.update_data(message_id=callback_query.message.message_id, chat_id=callback_query.message.chat.id)
|
||||
await state.set_state(ReplenishBalanceState.choosing_amount_robokassa)
|
||||
|
||||
|
||||
@@ -75,7 +78,6 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text="Некорректная сумма.",
|
||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=[]),
|
||||
force_text=True,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -95,14 +97,13 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F
|
||||
target_message=callback_query.message,
|
||||
text=DEFAULT_PAYMENT_MESSAGE.format(amount=amount_text),
|
||||
reply_markup=kb,
|
||||
force_text=True,
|
||||
)
|
||||
|
||||
|
||||
@router.callback_query(F.data == "enter_custom_amount_robokassa")
|
||||
async def process_custom_amount_selection(callback_query: types.CallbackQuery, state: FSMContext):
|
||||
b = back_keyboard("pay_robokassa")
|
||||
await edit_or_send_message(target_message=callback_query.message, text=ENTER_SUM, reply_markup=b, force_text=True)
|
||||
await edit_or_send_message(target_message=callback_query.message, text=ENTER_SUM, reply_markup=b)
|
||||
await state.set_state(ReplenishBalanceState.waiting_for_payment_confirmation_robokassa)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user