fix(payments): reuse pending links by provider identity

This commit is contained in:
BADtochka
2026-06-10 03:42:49 +03:00
parent 5c96fcd519
commit 1fca62de75
8 changed files with 198 additions and 47 deletions
+1 -8
View File
@@ -295,24 +295,17 @@ class FreeKassaService(HttpClientMixin):
if not success:
return None
expected_currency = normalize_payment_currency_code(getattr(payment, "currency", None))
for order in response_data.get("orders") or []:
if not isinstance(order, dict):
continue
try:
is_new = int(order.get("status", -1)) == 0
amount_matches = decimal_amounts_equal(
order.get("amount"),
getattr(payment, "amount", None),
)
except (TypeError, ValueError):
continue
if not is_new or not amount_matches:
if not is_new:
continue
if str(order.get("merchant_order_id") or "") != str(payment.payment_id):
continue
if normalize_payment_currency_code(order.get("currency")) != expected_currency:
continue
fk_order_id = str(order.get("fk_order_id") or "").strip()
if fk_order_id:
payment_url = (self.config.PAYMENT_URL or "https://pay.freekassa.net/").rstrip("/")
-6
View File
@@ -426,17 +426,11 @@ class HeleketService(HttpClientMixin):
if str(data.get("order_id") or "") != str(payment.payment_id):
return None
try:
if not decimal_amounts_equal(data.get("amount"), getattr(payment, "amount", None)):
return None
expired_at = int(data.get("expired_at") or 0)
except (TypeError, ValueError):
return None
if expired_at and expired_at <= int(time.time()):
return None
provider_currency = normalize_payment_currency_code(data.get("currency"))
payment_currency = normalize_payment_currency_code(getattr(payment, "currency", None))
if provider_currency != payment_currency:
return None
return (
str(data.get("url") or "").strip()
or str(getattr(payment, "provider_payment_url", None) or "").strip()
-13
View File
@@ -330,19 +330,6 @@ class PlategaService(HttpClientMixin):
if str(data.get("id") or "") != transaction_id:
return None
details = data.get("paymentDetails") or {}
if not isinstance(details, dict):
return None
try:
if not decimal_amounts_equal(details.get("amount"), getattr(payment, "amount", None)):
return None
except (TypeError, ValueError):
return None
provider_currency = normalize_payment_currency_code(details.get("currency"))
payment_currency = normalize_payment_currency_code(getattr(payment, "currency", None))
if provider_currency != payment_currency:
return None
try:
payload = json.loads(str(data.get("payload") or ""))
except (TypeError, ValueError, json.JSONDecodeError):
-10
View File
@@ -38,7 +38,6 @@ from .shared import (
PaymentSuccessRequest,
build_payment_record_payload,
create_webapp_payment_record,
decimal_amounts_equal,
describe_payment,
finalize_successful_payment,
finalize_webapp_link_payment,
@@ -291,15 +290,6 @@ class SeverPayService(HttpClientMixin):
return None
if str(data.get("order_id") or "") != str(payment.payment_id):
return None
try:
if not decimal_amounts_equal(data.get("amount"), getattr(payment, "amount", None)):
return None
except (TypeError, ValueError):
return None
provider_currency = normalize_payment_currency_code(data.get("currency"))
payment_currency = normalize_payment_currency_code(getattr(payment, "currency", None))
if provider_currency != payment_currency:
return None
return payment_url
async def webhook_route(self, request: web.Request) -> web.Response:
+13
View File
@@ -359,6 +359,19 @@ class WataService(HttpClientMixin):
if not success or not isinstance(data, dict):
return None
returned_ids = {
str(data.get("id") or "").strip(),
str(data.get("paymentLinkId") or "").strip(),
str(data.get("payment_link_id") or "").strip(),
}
returned_ids.discard("")
if returned_ids and provider_payment_id not in returned_ids:
return None
order_id = first_value(data, "orderId", "order_id")
if order_id is not None and str(order_id) != str(payment.payment_id):
return None
status = _normalized_wata_status(data) or str(data.get("status") or "").strip().lower()
if status and status not in _WATA_LINK_OPENED_STATUSES:
return None
@@ -63,7 +63,6 @@ from .shared import (
append_hwid_renewal_note,
build_success_message,
create_webapp_payment_record,
decimal_amounts_equal,
format_human_units,
format_number_for_payload,
is_traffic_sale_base,
@@ -2962,12 +2961,6 @@ async def reuse_webapp_payment(ctx: WebAppPaymentContext, payment: Any) -> Optio
return None
if bool(info.get("paid")):
return None
if not decimal_amounts_equal(info.get("amount_value"), getattr(payment, "amount", None)):
return None
provider_currency = normalize_payment_currency_code(info.get("amount_currency"))
payment_currency = normalize_payment_currency_code(getattr(payment, "currency", None))
if provider_currency != payment_currency:
return None
metadata = info.get("metadata") or {}
expected_metadata = {