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`.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-11-12 17:27:43 +03:00
parent 943c6ae1b1
commit b03757508b
2 changed files with 5 additions and 10 deletions

View file

@ -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"<str:uuid>/callback/<str:gateway>/", CallbackAPIView.as_view()),
path(r"<str:uuid>/callback/", CallbackAPIView.as_view()),
]

View file

@ -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()}"}