From b03757508b905a1825bdab645b18cf9b6a08d0d7 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Wed, 12 Nov 2025 17:27:43 +0300 Subject: [PATCH] Features: 1) Update callback URL to exclude gateway parameter; 2) Process callback using associated transaction's gateway integration class; Fixes: 1) Remove unused import for `UnknownGatewayError`; Extra: 1) Cleanup unreachable code and obsolete comments in `CallbackAPIView`. --- engine/payments/urls.py | 2 +- engine/payments/views.py | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/engine/payments/urls.py b/engine/payments/urls.py index 02abddf3..b3837941 100644 --- a/engine/payments/urls.py +++ b/engine/payments/urls.py @@ -12,5 +12,5 @@ payment_router.register(prefix=r"transactions", viewset=TransactionViewSet, base urlpatterns = [ path(r"", include(payment_router.urls)), path(r"deposit/", DepositView.as_view()), - path(r"/callback//", CallbackAPIView.as_view()), + path(r"/callback/", CallbackAPIView.as_view()), ] diff --git a/engine/payments/views.py b/engine/payments/views.py index dde5012c..989c48c4 100644 --- a/engine/payments/views.py +++ b/engine/payments/views.py @@ -9,7 +9,6 @@ from rest_framework.response import Response from rest_framework.views import APIView from engine.payments.docs.drf.views import DEPOSIT_SCHEMA -from engine.payments.gateways import UnknownGatewayError from engine.payments.models import Transaction from engine.payments.serializers import DepositSerializer, TransactionProcessSerializer @@ -72,14 +71,10 @@ class CallbackAPIView(APIView): def post(self, request: Request, *args: list[Any], **kwargs: dict[Any, Any]) -> Response: try: - gateway = kwargs.get("gateway", "") - # noinspection PyUnreachableCode - match gateway: - case "gateway": - # Gateway.process_callback(request.data) - return Response(status=status.HTTP_200_OK) - case _: - raise UnknownGatewayError(f"Couldn't match '{gateway}' any gateway") + transaction = Transaction.objects.get(uuid=kwargs.get("uuid")) + gateway = transaction.gateway.get_integration_class_object() + gateway.process_callback(request.data) + return Response(status=status.HTTP_202_ACCEPTED) except Exception as e: return Response( status=status.HTTP_500_INTERNAL_SERVER_ERROR, data={"error": f"{e}; {traceback.format_exc()}"}