From fadea753148e2d5faa97716984e0b8b3235d9c06 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 14 Nov 2025 01:30:31 +0300 Subject: [PATCH] Fix renewal mixed payment logic --- app/webapi/routes/miniapp.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/app/webapi/routes/miniapp.py b/app/webapi/routes/miniapp.py index 3fb902ec..64f4c43c 100644 --- a/app/webapi/routes/miniapp.py +++ b/app/webapi/routes/miniapp.py @@ -4564,18 +4564,7 @@ async def submit_subscription_renewal_endpoint( missing_amount = calculate_missing_amount(balance_kopeks, final_total) description = f"Продление подписки на {period_days} дней" - if not method or missing_amount <= 0: - if final_total > 0 and balance_kopeks < final_total: - missing = final_total - balance_kopeks - raise HTTPException( - status.HTTP_402_PAYMENT_REQUIRED, - detail={ - "code": "insufficient_funds", - "message": "Not enough funds to renew the subscription", - "missing_amount_kopeks": missing, - }, - ) - + if missing_amount <= 0: try: result = await renewal_service.finalize( db, @@ -4611,6 +4600,26 @@ async def submit_subscription_renewal_endpoint( renewed_until=updated_subscription.end_date, ) + if not method: + if final_total > 0 and balance_kopeks < final_total: + missing = final_total - balance_kopeks + raise HTTPException( + status.HTTP_402_PAYMENT_REQUIRED, + detail={ + "code": "insufficient_funds", + "message": "Not enough funds to renew the subscription", + "missing_amount_kopeks": missing, + }, + ) + + raise HTTPException( + status.HTTP_400_BAD_REQUEST, + detail={ + "code": "payment_method_required", + "message": "Payment method is required when balance is insufficient", + }, + ) + supported_methods = {"cryptobot"} if method not in supported_methods: raise HTTPException(