fix(payments): pedning status in transactions

This commit is contained in:
BADtochka
2026-06-09 16:36:04 +03:00
parent ca88c995b8
commit 5c96fcd519
6 changed files with 93 additions and 10 deletions
-3
View File
@@ -663,7 +663,6 @@ async def pay_platega_callback_handler(
)
transaction_id = first_value(response_data, "transactionId", "id")
redirect_url = first_value(response_data, "redirect", "url", "paymentUrl")
provider_status = str((response_data or {}).get("status") or payment_record.status)
# Platega requires *both* a transaction id and a redirect url to count as a
# usable payment — neither field is sufficient on its own. Skipping the
# persistence step when the redirect is missing matches the pre-refactor
@@ -680,7 +679,6 @@ async def pay_platega_callback_handler(
api_success=success,
payment_url=redirect_url,
provider_payment_id=persistable_id,
new_status=provider_status if persistable_id else None,
log_prefix=_LOG,
)
@@ -766,7 +764,6 @@ async def _create_webapp_payment(ctx: WebAppPaymentContext, variant: str) -> web
first_value(response_data, "redirect", "url", "paymentUrl") if success else None
),
provider_payment_id=first_value(response_data, "transactionId", "id"),
new_status=str((response_data or {}).get("status") or payment.status),
log_prefix="Platega",
)
@@ -356,7 +356,7 @@ async def render_link_or_fail(
payment as ``failed_creation``. Every link-style provider used to inline
this same sequence.
"""
if api_success and provider_payment_id:
if api_success and provider_payment_id and payment_url:
await safe_store_provider_payment_id(
session,
payment,
@@ -39,7 +39,9 @@ async def finalize_webapp_link_payment(
log_prefix="Wata",
)
"""
if api_success and provider_payment_id:
# Reuse logic needs both a provider id and a redirect URL; persisting only
# the id creates orphan records that match find_recent but fail verification.
if api_success and provider_payment_id and payment_url:
try:
await payment_dal.update_provider_payment_and_status(
session,
+3 -4
View File
@@ -1609,7 +1609,7 @@ async def _initiate_yk_payment(
await payment_dal.update_payment_status_by_db_id(
session,
payment_db_id=db_payment_record.payment_id,
new_status=payment_response_yk.get("status", "pending"),
new_status="pending_yookassa",
yk_payment_id=payment_response_yk.get("id"),
)
if selected_method_internal_id is not None:
@@ -1677,12 +1677,11 @@ async def _initiate_yk_payment(
return True
if payment_response_yk and payment_method_id:
status_to_store = payment_response_yk.get("status", "pending")
try:
await payment_dal.update_payment_status_by_db_id(
session,
payment_db_id=db_payment_record.payment_id,
new_status=status_to_store,
new_status="pending_yookassa",
yk_payment_id=payment_response_yk.get("id"),
)
if selected_method_internal_id is not None:
@@ -2934,7 +2933,7 @@ async def create_webapp_payment(ctx: WebAppPaymentContext) -> web.Response:
await payment_dal.update_payment_status_by_db_id(
ctx.session,
payment.payment_id,
response.get("status", "pending"),
"pending_yookassa",
yk_payment_id=response.get("id"),
)
await ctx.session.commit()