Skip to content

Commit

Permalink
faet: add transactions listview.
Browse files Browse the repository at this point in the history
  • Loading branch information
nika-alaverdashvili committed Nov 5, 2024
1 parent e332217 commit 310dddc
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
8 changes: 7 additions & 1 deletion locale/ka/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -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 ""
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
5 changes: 5 additions & 0 deletions payments/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"
16 changes: 16 additions & 0 deletions payments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
2 changes: 2 additions & 0 deletions payments/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ConnectStripeAccountView,
CreateCheckoutSession,
DepositBalanceView,
PaymentListView,
SellerPayoutView,
TransferFundsView,
stripe_account_refresh,
Expand Down Expand Up @@ -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"),
Expand Down
24 changes: 23 additions & 1 deletion payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +26,7 @@
from .serializers import (
CheckoutSessionSerializer,
DepositSerializer,
PaymentSerializer,
PayoutRequestSerializer,
TransferFundsSerializer,
)
Expand Down Expand Up @@ -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

0 comments on commit 310dddc

Please sign in to comment.