Merge pull request #2512 from BEDOLAGA-DEV/dev

Update cloudpayments.py
This commit is contained in:
Egor
2026-02-03 03:23:48 +03:00
committed by GitHub
+25 -1
View File
@@ -85,9 +85,11 @@ class CloudPaymentsPaymentMixin:
)
except CloudPaymentsAPIError as error:
logger.error('Ошибка создания CloudPayments платежа: %s', error)
self._schedule_error_notification(error, f'CloudPayments payment creation API error: user_id={user_id}')
return None
except Exception as error:
logger.exception('Непредвиденная ошибка при создании CloudPayments платежа: %s', error)
self._schedule_error_notification(error, f'CloudPayments payment creation exception: user_id={user_id}')
return None
metadata = {
@@ -109,6 +111,10 @@ class CloudPaymentsPaymentMixin:
if not local_payment:
logger.error('Не удалось создать локальную запись CloudPayments платежа')
error = ValueError('Failed to create local CloudPayments payment record')
self._schedule_error_notification(
error, f'CloudPayments payment creation error: user_id={user_id}, invoice_id={invoice_id}'
)
return None
logger.info(
@@ -149,6 +155,8 @@ class CloudPaymentsPaymentMixin:
if not invoice_id:
logger.error('CloudPayments webhook без invoice_id')
error = ValueError('CloudPayments webhook missing invoice_id')
self._schedule_error_notification(error, 'CloudPayments webhook error: missing invoice_id')
return False
payment_module = import_module('app.services.payment_service')
@@ -169,6 +177,10 @@ class CloudPaymentsPaymentMixin:
if not user_id:
logger.error('Не удалось определить user_id из account_id: %s', account_id)
error = ValueError(f'CloudPayments cannot determine user_id from account_id: {account_id}')
self._schedule_error_notification(
error, f'CloudPayments webhook error: cannot determine user, invoice_id={invoice_id}'
)
return False
# Get user by ID
@@ -177,6 +189,10 @@ class CloudPaymentsPaymentMixin:
user = await get_user_by_id(db, user_id)
if not user:
logger.error('Пользователь не найден: id=%s', user_id)
error = ValueError(f'User not found: {user_id}')
self._schedule_error_notification(
error, f'CloudPayments webhook error: user not found, invoice_id={invoice_id}'
)
return False
# Create payment record
@@ -191,6 +207,10 @@ class CloudPaymentsPaymentMixin:
if not payment:
logger.error('Не удалось создать запись платежа')
error = ValueError('Failed to create CloudPayments payment record from webhook')
self._schedule_error_notification(
error, f'CloudPayments webhook error: failed to create payment, invoice_id={invoice_id}'
)
return False
# Check if already processed
@@ -221,10 +241,14 @@ class CloudPaymentsPaymentMixin:
if not user:
logger.error('Пользователь не найден: id=%s', payment.user_id)
error = ValueError(f'User not found: {payment.user_id}')
self._schedule_error_notification(
error, f'CloudPayments finalize error: user not found, invoice_id={invoice_id}'
)
return False
# Add balance
await add_user_balance(db, user.id, amount_kopeks)
await add_user_balance(db, user, amount_kopeks)
# Create transaction record
from app.database.crud.transaction import create_transaction