|
|
|
|
@ -15,6 +15,12 @@ from .utils import check_version_smaller_than_1_1_12 |
|
|
|
|
|
|
|
|
|
from shared.discord import send_discord_log_message |
|
|
|
|
|
|
|
|
|
from rest_framework.decorators import permission_classes |
|
|
|
|
from rest_framework.permissions import IsAuthenticated |
|
|
|
|
from django.shortcuts import get_object_or_404 |
|
|
|
|
|
|
|
|
|
from ..tournaments.services.payment_service import PaymentService |
|
|
|
|
|
|
|
|
|
@api_view(['GET']) |
|
|
|
|
def user_by_token(request): |
|
|
|
|
serializer = UserSerializer(request.user) |
|
|
|
|
@ -284,3 +290,28 @@ class ShortUserViewSet(viewsets.ModelViewSet): |
|
|
|
|
queryset = CustomUser.objects.all() |
|
|
|
|
serializer_class = ShortUserSerializer |
|
|
|
|
permission_classes = [] # Users are public whereas the other requests are only for logged users |
|
|
|
|
|
|
|
|
|
@api_view(['POST']) |
|
|
|
|
@permission_classes([IsAuthenticated]) |
|
|
|
|
def process_refund(request, team_registration_id): |
|
|
|
|
try: |
|
|
|
|
# Verify the user is the tournament umpire |
|
|
|
|
team_registration = get_object_or_404(TeamRegistration, id=team_registration_id) |
|
|
|
|
if request.user != team_registration.tournament.event.creator: |
|
|
|
|
return Response({ |
|
|
|
|
'success': False, |
|
|
|
|
'message': "Vous n'êtes pas autorisé à effectuer ce remboursement" |
|
|
|
|
}, status=403) |
|
|
|
|
|
|
|
|
|
payment_service = PaymentService(request) |
|
|
|
|
success, message, refund = payment_service.process_refund(team_registration_id) |
|
|
|
|
return Response({ |
|
|
|
|
'success': success, |
|
|
|
|
'message': message, |
|
|
|
|
'players': team_registration.players.all() |
|
|
|
|
}) |
|
|
|
|
except Exception as e: |
|
|
|
|
return Response({ |
|
|
|
|
'success': False, |
|
|
|
|
'message': str(e) |
|
|
|
|
}, status=400) |
|
|
|
|
|