From 5f64e0ab10db661eaee2f42e56f33aa10825713b Mon Sep 17 00:00:00 2001 From: naiv Date: Sat, 16 Dec 2023 02:50:23 +0200 Subject: [PATCH 01/11] updated endpoints for stripe success and cancel urls --- books_fixture.json | 8 ----- payment_service/migrations/0001_initial.py | 12 ++++---- ...alter_payment_money_to_be_paid_and_more.py | 29 ------------------- payment_service/models.py | 2 +- payment_service/services.py | 13 ++++----- 5 files changed, 13 insertions(+), 51 deletions(-) delete mode 100644 payment_service/migrations/0002_alter_payment_money_to_be_paid_and_more.py diff --git a/books_fixture.json b/books_fixture.json index e0981fe..6bba622 100644 --- a/books_fixture.json +++ b/books_fixture.json @@ -299,14 +299,6 @@ "model": "session" } }, - { - "model": "contenttypes.contenttype", - "pk": 7, - "fields": { - "app_label": "book_service", - "model": "book" - } - }, { "model": "book_service.book", "pk": 1, diff --git a/payment_service/migrations/0001_initial.py b/payment_service/migrations/0001_initial.py index 02397c4..a3aec5c 100644 --- a/payment_service/migrations/0001_initial.py +++ b/payment_service/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.8 on 2023-12-15 14:54 +# Generated by Django 4.2.8 on 2023-12-15 22:44 from django.db import migrations, models import django.db.models.deletion @@ -8,7 +8,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("borrowing_service", "0001_initial"), + ("borrowing_service", "0002_initial"), ] operations = [ @@ -40,11 +40,13 @@ class Migration(migrations.Migration): max_length=40, ), ), - ("session_url", models.URLField()), - ("session_id", models.CharField(max_length=255)), + ("session_url", models.URLField(blank=True, null=True)), + ("session_id", models.CharField(blank=True, max_length=255, null=True)), ( "money_to_be_paid", - models.DecimalField(decimal_places=2, max_digits=10000), + models.DecimalField( + blank=True, decimal_places=2, max_digits=15, null=True + ), ), ( "borrowing", diff --git a/payment_service/migrations/0002_alter_payment_money_to_be_paid_and_more.py b/payment_service/migrations/0002_alter_payment_money_to_be_paid_and_more.py deleted file mode 100644 index 2a95b57..0000000 --- a/payment_service/migrations/0002_alter_payment_money_to_be_paid_and_more.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 4.2.8 on 2023-12-15 16:06 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("payment_service", "0001_initial"), - ] - - operations = [ - migrations.AlterField( - model_name="payment", - name="money_to_be_paid", - field=models.DecimalField( - blank=True, decimal_places=2, max_digits=10000, null=True - ), - ), - migrations.AlterField( - model_name="payment", - name="session_id", - field=models.CharField(blank=True, max_length=255, null=True), - ), - migrations.AlterField( - model_name="payment", - name="session_url", - field=models.URLField(blank=True, null=True), - ), - ] diff --git a/payment_service/models.py b/payment_service/models.py index ae292f3..0f55cc6 100644 --- a/payment_service/models.py +++ b/payment_service/models.py @@ -28,5 +28,5 @@ class PaymentTypes(models.TextChoices): session_url = models.URLField(null=True, blank=True) session_id = models.CharField(max_length=255, null=True, blank=True) money_to_be_paid = models.DecimalField( - max_digits=10000, decimal_places=2, null=True, blank=True + max_digits=15, decimal_places=2, null=True, blank=True ) diff --git a/payment_service/services.py b/payment_service/services.py index dbabc42..b02fadc 100644 --- a/payment_service/services.py +++ b/payment_service/services.py @@ -1,12 +1,8 @@ from __future__ import annotations -from datetime import datetime - import stripe -from decimal import Decimal -from django.urls import reverse_lazy, reverse -from stripe.checkout import Session +from django.urls import reverse from borrowing_service.models import Borrowing from core import settings @@ -39,9 +35,10 @@ def get_checkout_session(borrowing: Borrowing, payment_id: int) -> Session: else: payment_amount = calculate_payment_amount(borrowing) - success_url = reverse("payment_service:success", args=[payment_id]) - cancel_url = reverse("payment_service:cancel", args=[payment_id]) - return Session.create( + success_url = reverse("payment_service:payments-payment-successful", args=[payment_id]) + cancel_url = reverse("payment_service:payments-payment-canceled", args=[payment_id]) + stripe.api_key = settings.STRIPE_SECRET_KEY + return stripe.checkout.Session.create( payment_method_types=["card"], line_items=[ { From a857365b192a9a1861b1da1f06b534479bdc578f Mon Sep 17 00:00:00 2001 From: naiv Date: Sat, 16 Dec 2023 04:36:04 +0200 Subject: [PATCH 02/11] updated payment model and rerun migrations --- .../0002_alter_payment_session_url.py | 18 ++++++++++++++++++ payment_service/models.py | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 payment_service/migrations/0002_alter_payment_session_url.py diff --git a/payment_service/migrations/0002_alter_payment_session_url.py b/payment_service/migrations/0002_alter_payment_session_url.py new file mode 100644 index 0000000..3e2dee5 --- /dev/null +++ b/payment_service/migrations/0002_alter_payment_session_url.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.4 on 2023-12-16 01:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('payment_service', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='payment', + name='session_url', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/payment_service/models.py b/payment_service/models.py index 0f55cc6..c0d5626 100644 --- a/payment_service/models.py +++ b/payment_service/models.py @@ -7,6 +7,7 @@ class Payment(models.Model): class PaymentStatus(models.TextChoices): PENDING = "PENDING", _("pending") PAID = "PAID", _("paid") + EXPIRED = "EXPIRED", _("expired") class PaymentTypes(models.TextChoices): PAYMENT = "PAYMENT", _("payment") @@ -25,7 +26,7 @@ class PaymentTypes(models.TextChoices): borrowing = models.ForeignKey( Borrowing, on_delete=models.CASCADE, related_name="payments" ) - session_url = models.URLField(null=True, blank=True) + session_url = models.TextField(null=True, blank=True) session_id = models.CharField(max_length=255, null=True, blank=True) money_to_be_paid = models.DecimalField( max_digits=15, decimal_places=2, null=True, blank=True From 88005e53a070a944c8ee2400dd3f4e5028690e04 Mon Sep 17 00:00:00 2001 From: naiv Date: Sat, 16 Dec 2023 04:36:30 +0200 Subject: [PATCH 03/11] created helper function for checking id checkout session is expired --- payment_service/tasks.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 payment_service/tasks.py diff --git a/payment_service/tasks.py b/payment_service/tasks.py new file mode 100644 index 0000000..d9804b1 --- /dev/null +++ b/payment_service/tasks.py @@ -0,0 +1,26 @@ +import stripe +from celery import shared_task + +from payment_service.models import Payment + + +def check_if_session_expired(session_id: str) -> bool: + """Check is session status is expired""" + session = stripe.checkout.Session.retrieve(session_id) + status = session.get("payment_intent", {}).get("status") + if status == "expired": + return True + return False + + +@shared_task +def verify_session_status() -> None: + """Verify if pending sessions did not expire""" + print("checking for expired checkouts") + + payments = Payment.objects.filter(status=Payment.PaymentStatus.PENDING) + + for payment in payments: + if check_if_session_expired(payment.session_id): + payment.status = Payment.PaymentStatus.EXPIRED + payment.save() From 032148ed4d80842e86834b442f510b1e383482cb Mon Sep 17 00:00:00 2001 From: naiv Date: Sat, 16 Dec 2023 04:39:07 +0200 Subject: [PATCH 04/11] moved DOMAIN variable to .evn to simplify process of domain update --- .env.sample | 1 + core/settings.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/.env.sample b/.env.sample index 0678aec..1d07f17 100644 --- a/.env.sample +++ b/.env.sample @@ -5,3 +5,4 @@ POSTGRES_DB=POSTGRES_DB POSTGRES_USER=POSTGRES_USER POSTGRES_PASSWORD=POSTGRES_PASSWORD RABBIT_URL=RABBIT_URL +DOMAIN=http://localhost:8080 diff --git a/core/settings.py b/core/settings.py index f65678a..2eea76c 100644 --- a/core/settings.py +++ b/core/settings.py @@ -155,5 +155,15 @@ #CELERY BEAT CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler" +# Celery schedule for checking is checkout schedule expired +CELERY_SCHEDULE = { + "check-payment-session-expiry": { + "task": "payment_service.tasks.verify_session_status", + "schedule": 60.0, + }, +} + STRIPE_SECRET_KEY = os.environ.get("STRIPE_SECRET_KEY") STRIPE_PUBLISHABLE_KEY = os.environ.get("STRIPE_PUBLISHABLE_KEY") + +DOMAIN = os.environ["DOMAIN"] From 356a5959b50c664ea2b38e008880ef43a407d1e1 Mon Sep 17 00:00:00 2001 From: naiv Date: Sat, 16 Dec 2023 04:40:01 +0200 Subject: [PATCH 05/11] added logic to not allow users with pending payments to borrow book --- borrowing_service/serializers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/borrowing_service/serializers.py b/borrowing_service/serializers.py index 3ba7a5e..cf661b2 100644 --- a/borrowing_service/serializers.py +++ b/borrowing_service/serializers.py @@ -1,8 +1,10 @@ from django.db import transaction +from django.db.models import Q from rest_framework import serializers from rest_framework.exceptions import ValidationError from borrowing_service.models import Borrowing +from payment_service.models import Payment from payment_service.serializers import ( PaymentSerializer, PaymentListSerializer @@ -33,10 +35,18 @@ class Meta: def create(self, validated_data): user = validated_data.get("user") borrowed_book = validated_data.get("book") + if borrowed_book.inventory == 0: raise ValidationError("Sorry no books available!") - if user.borrowings.filter(is_active=True).count(): - raise ValidationError("You must return your active borrowing!") + + pending_payments = Payment.objects.filter( + Q(borrowing__user_id=user.id) & Q(status=Payment.PaymentStatus.PENDING) + ).count() + if pending_payments: + raise ValidationError( + "You must complete your pending payments before borrowing new book!" + ) + borrowed_book.inventory -= 1 borrowed_book.save() borrowing = Borrowing.objects.create( From 1ca569261fcfc41fd3957480ced759a6ceb526ea Mon Sep 17 00:00:00 2001 From: naiv Date: Sat, 16 Dec 2023 04:41:01 +0200 Subject: [PATCH 06/11] fixed issue with checkout session creation --- payment_service/services.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/payment_service/services.py b/payment_service/services.py index b02fadc..631d91f 100644 --- a/payment_service/services.py +++ b/payment_service/services.py @@ -1,8 +1,10 @@ from __future__ import annotations import stripe +from celery import shared_task from django.urls import reverse +from stripe.checkout import Session from borrowing_service.models import Borrowing from core import settings @@ -38,7 +40,7 @@ def get_checkout_session(borrowing: Borrowing, payment_id: int) -> Session: success_url = reverse("payment_service:payments-payment-successful", args=[payment_id]) cancel_url = reverse("payment_service:payments-payment-canceled", args=[payment_id]) stripe.api_key = settings.STRIPE_SECRET_KEY - return stripe.checkout.Session.create( + return Session.create( payment_method_types=["card"], line_items=[ { @@ -51,8 +53,8 @@ def get_checkout_session(borrowing: Borrowing, payment_id: int) -> Session: }, ], mode="payment", - success_url=success_url, - cancel_url=cancel_url, + success_url=settings.DOMAIN + success_url, + cancel_url=settings.DOMAIN + cancel_url, ) From a93a7ba9078a731e71c985ece09c8be5d4d95110 Mon Sep 17 00:00:00 2001 From: naiv Date: Sat, 16 Dec 2023 04:41:59 +0200 Subject: [PATCH 07/11] updated success endpoint handler and added renew checkout session endpoint handler --- payment_service/views.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/payment_service/views.py b/payment_service/views.py index 216c122..614f463 100644 --- a/payment_service/views.py +++ b/payment_service/views.py @@ -11,6 +11,7 @@ ) from payment_service.models import Payment +from payment_service.services import get_checkout_session stripe.api_key = settings.STRIPE_SECRET_KEY @@ -33,6 +34,15 @@ def get_serializer_class(self): @action(methods=["GET"], url_path="success", detail=True) def payment_successful(self, request, pk: None): payment = self.get_object() + session = stripe.checkout.Session.retrieve(payment.session_id) + status = session.get("payment_intent", {}).get("status") + if status != "succeeded": + return Response( + {"status": "fail", + "message": "Payment failed, please complete payment " + "within 24 hours from book borrowing time!"}, + status=400, + ) payment.status = "paid" payment.save() return Response( @@ -46,6 +56,19 @@ def payment_successful(self, request, pk: None): @action(methods=["GET"], url_path="cancel", detail=True) def payment_canceled(self, request, pk: None): return Response( - {"status": "fail", "message": "Payment was canceled"}, + {"status": "fail", + "message": "Payment was canceled. Please complete payment " + "within 24 hours from book borrowing time!"}, status=400, ) + + @action(methods=["POST"], url_path="renew-session", detail=True) + def renew_checkout(self, request, pk: None): + payment = self.get_object() + new_session = get_checkout_session(payment.borrowing, payment.id) + + if new_session.status != "open": + raise stripe.error.StripeError + + payment.session_id = new_session.id + payment.url = new_session.url From 442901dc8428461c5745c94da98b0995fe898c46 Mon Sep 17 00:00:00 2001 From: naiv Date: Sat, 16 Dec 2023 04:54:22 +0200 Subject: [PATCH 08/11] fixed flake8 errors --- borrowing_service/serializers.py | 6 ++++-- payment_service/serializers.py | 1 - payment_service/services.py | 11 ++++++++--- payment_service/views.py | 1 - 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/borrowing_service/serializers.py b/borrowing_service/serializers.py index cf661b2..34bb358 100644 --- a/borrowing_service/serializers.py +++ b/borrowing_service/serializers.py @@ -40,11 +40,13 @@ def create(self, validated_data): raise ValidationError("Sorry no books available!") pending_payments = Payment.objects.filter( - Q(borrowing__user_id=user.id) & Q(status=Payment.PaymentStatus.PENDING) + Q(borrowing__user_id=user.id) + & Q(status=Payment.PaymentStatus.PENDING) ).count() if pending_payments: raise ValidationError( - "You must complete your pending payments before borrowing new book!" + "You must complete your pending payments " + "before borrowing new book!" ) borrowed_book.inventory -= 1 diff --git a/payment_service/serializers.py b/payment_service/serializers.py index f58069c..ae60cb2 100644 --- a/payment_service/serializers.py +++ b/payment_service/serializers.py @@ -1,5 +1,4 @@ from rest_framework import serializers -from rest_framework.serializers import ModelSerializer from payment_service.models import Payment diff --git a/payment_service/services.py b/payment_service/services.py index 631d91f..e238640 100644 --- a/payment_service/services.py +++ b/payment_service/services.py @@ -1,7 +1,6 @@ from __future__ import annotations import stripe -from celery import shared_task from django.urls import reverse from stripe.checkout import Session @@ -37,8 +36,14 @@ def get_checkout_session(borrowing: Borrowing, payment_id: int) -> Session: else: payment_amount = calculate_payment_amount(borrowing) - success_url = reverse("payment_service:payments-payment-successful", args=[payment_id]) - cancel_url = reverse("payment_service:payments-payment-canceled", args=[payment_id]) + success_url = reverse( + "payment_service:payments-payment-successful", + args=[payment_id] + ) + cancel_url = reverse( + "payment_service:payments-payment-canceled", + args=[payment_id] + ) stripe.api_key = settings.STRIPE_SECRET_KEY return Session.create( payment_method_types=["card"], diff --git a/payment_service/views.py b/payment_service/views.py index 614f463..8b993d6 100644 --- a/payment_service/views.py +++ b/payment_service/views.py @@ -3,7 +3,6 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.decorators import action -from django.shortcuts import get_object_or_404 from rest_framework import viewsets from payment_service.serializers import ( PaymentListSerializer, From 5b02845cba7236fe5df38ebccfba49b56e2a8181 Mon Sep 17 00:00:00 2001 From: naiv Date: Sat, 16 Dec 2023 12:49:29 +0200 Subject: [PATCH 09/11] updated celery scheduled tasks for checking if session is expired --- core/celery.py | 16 ++++++++++------ core/settings.py | 10 +--------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/core/celery.py b/core/celery.py index 9ed4164..c1a625a 100644 --- a/core/celery.py +++ b/core/celery.py @@ -26,12 +26,16 @@ app.config_from_object(settings, namespace="CELERY") # Celery Beat Settings -# app.conf.beat_schedule = { -# "check-overdue-task": { -# "task": "borrowing_service.tasks.check_overdue_task", -# "schedule": crontab(minute="*/1"), -# } -# } +app.conf.beat_schedule = { + "check-overdue-task": { + "task": "borrowing_service.tasks.check_overdue_task", + "schedule": crontab(minute="*/1"), + }, + "check-payment-session-expiry": { + "task": "payment_service.tasks.verify_session_status", + "schedule": crontab(minute="*/1"), + }, +} # Load task modules from all registered Django apps. app.autodiscover_tasks() diff --git a/core/settings.py b/core/settings.py index 2eea76c..c2d6545 100644 --- a/core/settings.py +++ b/core/settings.py @@ -150,19 +150,11 @@ "ROTATE_REFRESH_TOKENS": False, } -CELERY_BROKER_URL=os.environ["RABBIT_URL"] +CELERY_BROKER_URL = os.environ["RABBIT_URL"] #CELERY BEAT CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler" -# Celery schedule for checking is checkout schedule expired -CELERY_SCHEDULE = { - "check-payment-session-expiry": { - "task": "payment_service.tasks.verify_session_status", - "schedule": 60.0, - }, -} - STRIPE_SECRET_KEY = os.environ.get("STRIPE_SECRET_KEY") STRIPE_PUBLISHABLE_KEY = os.environ.get("STRIPE_PUBLISHABLE_KEY") From b1d26db2ca1d4eb08f16777bc63d80f35617bd1d Mon Sep 17 00:00:00 2001 From: naiv Date: Sun, 17 Dec 2023 03:58:34 +0200 Subject: [PATCH 10/11] added drf-spectacular and configured documentations --- book_service/views.py | 18 ++++++++++++++++++ borrowing_service/views.py | 14 ++++++++++++++ core/settings.py | 11 ++++++++++- core/urls.py | 11 ++++++++++- payment_service/tasks.py | 2 -- payment_service/views.py | 3 +++ requirements.txt | 2 +- 7 files changed, 56 insertions(+), 5 deletions(-) diff --git a/book_service/views.py b/book_service/views.py index f950684..98c686c 100644 --- a/book_service/views.py +++ b/book_service/views.py @@ -1,3 +1,4 @@ +from drf_spectacular.utils import extend_schema, OpenApiParameter from rest_framework import viewsets from book_service.models import Book @@ -27,3 +28,20 @@ def get_queryset(self): self.queryset = self.queryset.filter(author__icontains=author) return self.queryset + + @extend_schema( + parameters=[ + OpenApiParameter( + name="title", + type={"type": "string", "items": {"type": "string"}}, + description="Filter books by title (ex. ?title=the)" + ), + OpenApiParameter( + name="author", + type={"type": "string", "items": {"type": "string"}}, + description="Filter books by author (ex. ?author=Rob)" + ) + ] + ) + def list(self, request, *args, **kwargs): + return super().list(request, args, kwargs) diff --git a/borrowing_service/views.py b/borrowing_service/views.py index 211f737..043ff2c 100644 --- a/borrowing_service/views.py +++ b/borrowing_service/views.py @@ -1,5 +1,6 @@ from django.utils import timezone from django.db import transaction +from drf_spectacular.utils import extend_schema, OpenApiParameter from rest_framework import viewsets, mixins from rest_framework.decorators import api_view, permission_classes from rest_framework.permissions import IsAuthenticated @@ -54,11 +55,24 @@ def get_serializer_class(self): def perform_create(self, serializer): serializer.save(user=self.request.user) + @extend_schema( + parameters=[ + OpenApiParameter( + name="is_active", + type={"type": "string", "items": {"type": "string"}}, + description="Filter by borrowing status (ex. ?is_active=True)" + ) + ] + ) + def list(self, request, *args, **kwargs): + return super().list(request, args, kwargs) + @api_view(["POST"]) @permission_classes([IsAuthenticated]) @transaction.atomic def borrowing_return(request, pk): + """Endpoint for returning book""" borrowing = Borrowing.objects.get(pk=pk) if request.method == "POST": diff --git a/core/settings.py b/core/settings.py index c2d6545..1365aca 100644 --- a/core/settings.py +++ b/core/settings.py @@ -48,7 +48,8 @@ "customer", "book_service", "borrowing_service", - "payment_service" + "payment_service", + "drf_spectacular" ] MIDDLEWARE = [ @@ -142,6 +143,14 @@ "DEFAULT_AUTHENTICATION_CLASSES": ( "rest_framework_simplejwt.authentication.JWTAuthentication", ), + "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", +} + +SPECTACULAR_SETTINGS = { + "TITLE": "Your Project API", + "DESCRIPTION": "Your project description", + "VERSION": "1.0.0", + "SERVE_INCLUDE_SCHEMA": False, } SIMPLE_JWT = { diff --git a/core/urls.py b/core/urls.py index e01a50c..7c4a677 100644 --- a/core/urls.py +++ b/core/urls.py @@ -16,6 +16,11 @@ """ from django.contrib import admin from django.urls import path, include +from drf_spectacular.views import ( + SpectacularAPIView, + SpectacularSwaggerView, + SpectacularRedocView +) urlpatterns = [ path("admin/", admin.site.urls), @@ -30,5 +35,9 @@ path("api/users/", include("customer.urls", namespace="customer")), path("api/payment_service/", - include("payment_service.urls", namespace="payment_service")) + include("payment_service.urls", namespace="payment_service")), + + path("api/doc/", SpectacularAPIView.as_view(), name="schema"), + path("api/doc/swagger/", SpectacularSwaggerView.as_view(url_name="schema"), name="swagger"), + path("api/doc/redoc/", SpectacularRedocView.as_view(url_name="schema"), name="redoc"), ] diff --git a/payment_service/tasks.py b/payment_service/tasks.py index d9804b1..5e1aab8 100644 --- a/payment_service/tasks.py +++ b/payment_service/tasks.py @@ -16,8 +16,6 @@ def check_if_session_expired(session_id: str) -> bool: @shared_task def verify_session_status() -> None: """Verify if pending sessions did not expire""" - print("checking for expired checkouts") - payments = Payment.objects.filter(status=Payment.PaymentStatus.PENDING) for payment in payments: diff --git a/payment_service/views.py b/payment_service/views.py index 8b993d6..b74f691 100644 --- a/payment_service/views.py +++ b/payment_service/views.py @@ -32,6 +32,7 @@ def get_serializer_class(self): @action(methods=["GET"], url_path="success", detail=True) def payment_successful(self, request, pk: None): + """Endpoint for redirection after successful payment""" payment = self.get_object() session = stripe.checkout.Session.retrieve(payment.session_id) status = session.get("payment_intent", {}).get("status") @@ -54,6 +55,7 @@ def payment_successful(self, request, pk: None): @action(methods=["GET"], url_path="cancel", detail=True) def payment_canceled(self, request, pk: None): + """Endpoint for redirection after payment was canceled or failed""" return Response( {"status": "fail", "message": "Payment was canceled. Please complete payment " @@ -63,6 +65,7 @@ def payment_canceled(self, request, pk: None): @action(methods=["POST"], url_path="renew-session", detail=True) def renew_checkout(self, request, pk: None): + """Endpoint for renewing checkout session if it expired""" payment = self.get_object() new_session = get_checkout_session(payment.borrowing, payment.id) diff --git a/requirements.txt b/requirements.txt index af77829..3ac5963 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,7 @@ django-debug-toolbar==3.4.0 django-timezone-field==6.1.0 djangorestframework==3.13.1 djangorestframework-simplejwt==5.2.0 -drf-spectacular==0.22.1 +drf-spectacular==0.27.0 flake8==5.0.4 flake8-quotes==3.3.1 flake8-variables-names==0.0.5 From 0d300d9b5daf8d4849e278526787e778067e47ee Mon Sep 17 00:00:00 2001 From: naiv Date: Sun, 17 Dec 2023 04:01:18 +0200 Subject: [PATCH 11/11] corrected flake8 --- core/urls.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/urls.py b/core/urls.py index 7c4a677..3057efc 100644 --- a/core/urls.py +++ b/core/urls.py @@ -38,6 +38,8 @@ include("payment_service.urls", namespace="payment_service")), path("api/doc/", SpectacularAPIView.as_view(), name="schema"), - path("api/doc/swagger/", SpectacularSwaggerView.as_view(url_name="schema"), name="swagger"), - path("api/doc/redoc/", SpectacularRedocView.as_view(url_name="schema"), name="redoc"), + path("api/doc/swagger/", + SpectacularSwaggerView.as_view(url_name="schema"), name="swagger"), + path("api/doc/redoc/", + SpectacularRedocView.as_view(url_name="schema"), name="redoc"), ]