Skip to content

Commit

Permalink
Added get payment endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDyakonov committed Jun 15, 2024
1 parent 009711b commit 0d34532
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
17 changes: 17 additions & 0 deletions backend/apps/payments/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from apps.booking.models import Buyer
from rest_framework import serializers

from .models import Order


class BuyerPaymentSerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -15,3 +17,18 @@ class PaymentProcessingSerializer(serializers.Serializer):

class PaymentStatusSerializer(serializers.Serializer):
payment_id = serializers.CharField(required=True)


class PaymentListOutputSerializer(serializers.ModelSerializer):
buyer = BuyerPaymentSerializer(source="cart.buyer", read_only=True)

class Meta:
model = Order
fields = [
"buyer",
"payment_id",
"total",
"created_at",
"payment_status",
"ticket_file",
]
12 changes: 8 additions & 4 deletions backend/apps/payments/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from django.urls import path

from .views import (
BookingsByOrderIdAPIView,
PaymentListView,
PaymentProcessingView,
PaymentStatusView,
send_purchase_email_view,
yookassa_webhook,
BookingsByOrderIdAPIView
)

urlpatterns = [
path("yookassa-webhook/", yookassa_webhook, name="yookassa-webhook"),
path("create/", PaymentProcessingView.as_view()),
path("check/<str:payment_id>/", PaymentStatusView.as_view(), name="payment-status"),
path("order/<str:payment_id>/bookings/", BookingsByOrderIdAPIView.as_view(), name="bookings-by-order"),
path("test-mail/", send_purchase_email_view),
path(
"order/<str:payment_id>/bookings/",
BookingsByOrderIdAPIView.as_view(),
name="bookings-by-order",
),
path("", PaymentListView.as_view(), name="payment-list"),
]
19 changes: 11 additions & 8 deletions backend/apps/payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from rest_framework import generics, status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.views import APIView

from .models import Order
from .serializers import PaymentProcessingSerializer, PaymentStatusSerializer
from .serializers import (
PaymentListOutputSerializer,
PaymentProcessingSerializer,
PaymentStatusSerializer,
)
from .services import YooKassaService


@api_view(["POST"])
def send_purchase_email_view(request):
email = "[email protected]"
order_id = "2dff10a2-000f-5000-8000-1dd9e1fd9832"
send_purchase_email(email, order_id)
return Response({"status": "Email is being sent."})
class PaymentListView(generics.ListAPIView):
serializer_class = PaymentListOutputSerializer
queryset = Order.objects.all()

def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)


class PaymentStatusView(generics.RetrieveAPIView):
Expand Down

0 comments on commit 0d34532

Please sign in to comment.