From 0158ce150d76f8e165873349c258132aa61d3ff3 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Thu, 16 Oct 2025 09:55:38 +0200 Subject: [PATCH] Add API endpoint to get payment link for team registration --- api/urls.py | 2 +- api/views.py | 36 +++++++++++++++++++++++++ tournaments/services/payment_service.py | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/api/urls.py b/api/urls.py index f82d616..deccf8a 100644 --- a/api/urls.py +++ b/api/urls.py @@ -64,5 +64,5 @@ urlpatterns = [ path('stripe/create-account/', views.create_stripe_connect_account, name='create_stripe_account'), path('stripe/create-account-link/', views.create_stripe_account_link, name='create_account_link'), path('resend-payment-email//', views.resend_payment_email, name='resend-payment-email'), - + path('payment-link//', views.get_payment_link, name='get-payment-link'), ] diff --git a/api/views.py b/api/views.py index 1f86b01..a1c0f6d 100644 --- a/api/views.py +++ b/api/views.py @@ -647,6 +647,42 @@ def resend_payment_email(request, team_registration_id): except Exception as e: return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) +@api_view(['GET']) +@permission_classes([IsAuthenticated]) +def get_payment_link(request, team_registration_id): + """ + Get payment link for a team registration. + Only accessible by the umpire (tournament creator). + """ + try: + team_registration = get_object_or_404(TeamRegistration, id=team_registration_id) + + # Check if the user is the umpire (creator) of the tournament + if request.user != team_registration.tournament.event.creator: + return Response({ + 'success': False, + 'message': "Vous n'êtes pas autorisé à accéder à ce lien de paiement" + }, status=403) + + # Create payment link + payment_link = PaymentService.create_payment_link(team_registration.id) + + if payment_link: + return Response({ + 'success': True, + 'payment_link': payment_link + }) + else: + return Response({ + 'success': False, + 'message': 'Impossible de créer le lien de paiement' + }, status=500) + + except TeamRegistration.DoesNotExist: + return Response({'error': 'Team not found'}, status=status.HTTP_404_NOT_FOUND) + except Exception as e: + return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + @api_view(['GET']) @permission_classes([IsAuthenticated]) def is_granted_unlimited_access(request): diff --git a/tournaments/services/payment_service.py b/tournaments/services/payment_service.py index c2b259b..3a76ba3 100644 --- a/tournaments/services/payment_service.py +++ b/tournaments/services/payment_service.py @@ -710,7 +710,7 @@ class PaymentService: customer_email = team_registration.team_contact() currency_code = tournament.currency_code or 'EUR' - print(f"[PAYMENT LINK] Tournament: {tournament.name}") + print(f"[PAYMENT LINK] Tournament: {tournament.display_name()}") print(f"[PAYMENT LINK] is_corporate_tournament: {tournament.is_corporate_tournament}") # Base metadata (same as checkout session)