mirror of
https://github.com/BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot.git
synced 2026-03-01 07:42:30 +00:00
Merge pull request #1901 from Fr1ngg/bedolaga/fix-402-error-in-subscription-renewal-endpoint
Fix renewal mixed payment logic
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user