Files
apuc f6c61ff8da Document the API in Swagger with tags, parameters and examples
- Add OpenAPI tags for the seven API groups and a full description
  (auth, error envelope, pagination, idempotency) in SPECTACULAR_SETTINGS
- Annotate every endpoint with @extend_schema: summary, description,
  query parameters, request/response examples and error responses
- Add shared schema helpers in apps/common/schema.py: ErrorEnvelope,
  error_responses(), pagination and catalog filter parameters
- Document JWT login and token refresh that simplejwt ships without docs
- Add ReDoc at /api/redoc/ next to Swagger UI at /api/docs/
- Add export_api_docs management command rendering the schema into a
  standalone HTML reference (no CDN) and commit docs/api-reference.html
- Describe the documentation entry points in docs/architecture.md

Schema validates cleanly: 41 operations, 0 warnings.
2026-11-22 22:06:21 +03:00

79 lines
3.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from drf_spectacular.utils import (
OpenApiExample,
extend_schema,
inline_serializer,
)
from rest_framework import serializers
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
from apps.common.schema import error_responses
from .serializers import PaymentWebhookSerializer
from .services import handle_yookassa_webhook
TAGS = ["Платежи"]
class YooKassaWebhookView(APIView):
"""Receives ЮKassa notifications.
TODO: verify the source IP / signature before applying the event.
"""
permission_classes = [AllowAny]
authentication_classes: list = []
serializer_class = PaymentWebhookSerializer
@extend_schema(
tags=TAGS,
summary="Уведомление ЮKassa",
description=(
"Служебный метод: его вызывает платёжный провайдер, а не клиент. "
"Применяет событие к платежу и заказу.\n\n"
"Поддерживаемые события: `payment.succeeded`, `payment.canceled`, "
"`refund.succeeded`. После успешной оплаты статус оплаты заказа "
"пересчитывается по сумме всех успешных платежей — заказ может быть "
"оплачен частично.\n\n"
"Неизвестный платёж не считается ошибкой: ответ `200` с `detail: ignored`, "
"чтобы провайдер не повторял доставку бесконечно."
),
request=PaymentWebhookSerializer,
responses={
200: inline_serializer(
name="PaymentWebhookResponse",
fields={
"detail": serializers.CharField(
help_text="`ok` — событие применено, `ignored` — платёж не найден."
)
},
),
**error_responses(400),
},
examples=[
OpenApiExample(
"Оплата прошла",
value={
"event": "payment.succeeded",
"object": {
"id": "2f1a9c74-000f-5000-9000-1a2b3c4d5e6f",
"status": "succeeded",
"amount": {"value": "21583.00", "currency": "RUB"},
},
},
request_only=True,
),
OpenApiExample(
"Событие применено",
value={"detail": "ok"},
response_only=True,
),
],
)
def post(self, request):
payment = handle_yookassa_webhook(request.data)
if payment is None:
return Response({"detail": "ignored"})
return Response({"detail": "ok"})