mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 15:53:57 +00:00
Add UpdateUserWalletView and CustomUserByWalletBalanceSerializer for wallet balance updates
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 2m12s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 2m12s
This commit is contained in:
@ -9,3 +9,17 @@ class PaymentSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Payment
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class UpdatePaymentSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Payment
|
||||
fields = [
|
||||
"paid",
|
||||
"paid_at",
|
||||
"method",
|
||||
]
|
||||
|
||||
paid = serializers.BooleanField(required=True, allow_null=True)
|
||||
paid_at = serializers.DateTimeField(required=True, allow_null=True)
|
||||
method = serializers.ChoiceField(choices=Payment.PAYMENT_TYPES, required=True)
|
||||
|
@ -1,9 +1,19 @@
|
||||
# billing/urls.py
|
||||
from django.urls import path
|
||||
from .views import ListCreatePaymentView, VerifyPaymentView, PaymentDetailAPIView
|
||||
from .views import (
|
||||
ListCreatePaymentView,
|
||||
VerifyPaymentView,
|
||||
PaymentDetailAPIView,
|
||||
UpdatePaymentAPIView,
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path("payment/", ListCreatePaymentView.as_view(), name="create-payment"),
|
||||
path("payment/<str:pk>/", PaymentDetailAPIView.as_view(), name="retrieve-payment"),
|
||||
path(
|
||||
"payment/<str:pk>/update/",
|
||||
UpdatePaymentAPIView.as_view(),
|
||||
name="update-payment",
|
||||
),
|
||||
path("verify-payment/", VerifyPaymentView.as_view(), name="verify-payment"),
|
||||
]
|
||||
|
@ -10,7 +10,7 @@ from rest_framework.response import Response
|
||||
from api.mixins import StaffEditorPermissionMixin
|
||||
|
||||
from .models import Device, Payment
|
||||
from .serializers import PaymentSerializer
|
||||
from .serializers import PaymentSerializer, UpdatePaymentSerializer
|
||||
|
||||
|
||||
class InsufficientFundsError(Exception):
|
||||
@ -75,6 +75,21 @@ class PaymentDetailAPIView(StaffEditorPermissionMixin, generics.RetrieveAPIView)
|
||||
lookup_field = "pk"
|
||||
|
||||
|
||||
class UpdatePaymentAPIView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
||||
queryset = Payment.objects.select_related("user").all()
|
||||
serializer_class = UpdatePaymentSerializer
|
||||
lookup_field = "pk"
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
devices = instance.devices.all()
|
||||
serializer = self.get_serializer(instance, data=request.data, partial=False)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
self.perform_update(serializer)
|
||||
devices.update(is_active=True, expiry_date=instance.expires_at)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
||||
serializer_class = PaymentSerializer
|
||||
queryset = Payment.objects.all()
|
||||
|
Reference in New Issue
Block a user