diff --git a/locale/ka/LC_MESSAGES/django.po b/locale/ka/LC_MESSAGES/django.po index 82ad6d2..a120a6d 100755 --- a/locale/ka/LC_MESSAGES/django.po +++ b/locale/ka/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-11-05 11:14+0400\n" +"POT-Creation-Date: 2024-11-05 12:33+0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -48,6 +48,12 @@ msgstr "" "თქვენ არ გაქვთ ამ მოქმედების შესრულების უფლება, მომხმარებელი უნდა იყოს " "მყიდველი." +#: apis/permissions.py:77 +#, fuzzy +#| msgid "You do not have permission to perform this action." +msgid "You do not have permission to access this payment." +msgstr "თქვენ არ გაქვთ ამ მოქმედების შესრულების უფლება." + #: apis/serializers.py:75 apis/serializers.py:310 apis/serializers.py:902 #: apis/serializers.py:921 apis/serializers.py:1085 msgid "" diff --git a/payments/migrations/0005_alter_payment_options_alter_balance_currency.py b/payments/migrations/0005_alter_payment_options_alter_balance_currency.py new file mode 100644 index 0000000..f5c9408 --- /dev/null +++ b/payments/migrations/0005_alter_payment_options_alter_balance_currency.py @@ -0,0 +1,26 @@ +# Generated by Django 5.0.4 on 2024-11-05 08:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("payments", "0004_alter_balance_currency"), + ] + + operations = [ + migrations.AlterModelOptions( + name="payment", + options={"ordering": ["-created_at"]}, + ), + migrations.AlterField( + model_name="balance", + name="currency", + field=models.CharField( + choices=[("GEL", "GEL"), ("USD", "USD"), ("EUR", "EUR")], + default="GEL", + max_length=3, + ), + ), + ] diff --git a/payments/models/payment.py b/payments/models/payment.py index 67d3039..40df060 100644 --- a/payments/models/payment.py +++ b/payments/models/payment.py @@ -38,5 +38,10 @@ class Status(models.TextChoices): created_at = models.DateTimeField(auto_now_add=True, verbose_name="Created At") updated_at = models.DateTimeField(auto_now=True, verbose_name="Updated At") + class Meta: + ordering = [ + "-created_at", + ] + def __str__(self): return f"Payment {self.stripe_session_id} - {self.get_status_display()}" diff --git a/payments/serializers.py b/payments/serializers.py index 832fcd4..5b0e8cc 100644 --- a/payments/serializers.py +++ b/payments/serializers.py @@ -59,3 +59,19 @@ def validate_amount(self, value): if value <= Decimal("0.00"): raise serializers.ValidationError("Amount must be greater than zero.") return value + + +class PaymentSerializer(serializers.ModelSerializer): + class Meta: + model = Payment + fields = [ + "id", + "customer", + "auction_id", + "stripe_session_id", + "amount", + "currency", + "status", + "created_at", + "updated_at", + ] diff --git a/payments/urls.py b/payments/urls.py index b4de5f1..eae044b 100644 --- a/payments/urls.py +++ b/payments/urls.py @@ -5,6 +5,7 @@ ConnectStripeAccountView, CreateCheckoutSession, DepositBalanceView, + PaymentListView, SellerPayoutView, TransferFundsView, stripe_account_refresh, @@ -34,6 +35,7 @@ path("stripe-refresh/", stripe_account_refresh, name="stripe_account_refresh"), path("transfer/", TransferFundsView.as_view(), name="transfer-funds"), path("payout/", SellerPayoutView.as_view(), name="seller_payout"), + path("paymants/", PaymentListView.as_view(), name="payment_list"), # Webhook Endpoints for handling stripe responses! path("webhook/", stripe_webhook, name="deposit_webhook"), path("connect/webhook/", stripe_connect_webhook, name="connect_webhook"), diff --git a/payments/views.py b/payments/views.py index 2374ba5..f80979d 100755 --- a/payments/views.py +++ b/payments/views.py @@ -3,9 +3,11 @@ from django.db import transaction from django.shortcuts import get_object_or_404, redirect from django.urls import reverse +from django.utils.translation import gettext_lazy as _ from drf_spectacular.utils import extend_schema from rest_framework import status -from rest_framework.exceptions import ValidationError +from rest_framework.exceptions import NotFound, ValidationError +from rest_framework.generics import ListAPIView from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView @@ -24,6 +26,7 @@ from .serializers import ( CheckoutSessionSerializer, DepositSerializer, + PaymentSerializer, PayoutRequestSerializer, TransferFundsSerializer, ) @@ -563,3 +566,22 @@ def stripe_account_refresh(request): Redirects the user back to the ConnectStripeAccountView to start a new session. """ return redirect(reverse("connect_stripe_account")) + + +@extend_schema( + tags=["Payment"], +) +class PaymentListView(ListAPIView): + permission_classes = [IsAuthenticated] + serializer_class = PaymentSerializer + + def get_queryset(self): + queryset = Payment.objects.filter(customer=self.request.user).order_by( + "-created_at" + ) + + # Raise 404 if there are no payments + if not queryset.exists(): + raise NotFound(detail=_("No payments found for this user.")) + + return queryset