Add API endpoint to get payment link for team registration

main
Razmig Sarkissian 4 weeks ago
parent fcb2ef9549
commit 0158ce150d
  1. 2
      api/urls.py
  2. 36
      api/views.py
  3. 2
      tournaments/services/payment_service.py

@ -64,5 +64,5 @@ urlpatterns = [
path('stripe/create-account/', views.create_stripe_connect_account, name='create_stripe_account'), 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('stripe/create-account-link/', views.create_stripe_account_link, name='create_account_link'),
path('resend-payment-email/<str:team_registration_id>/', views.resend_payment_email, name='resend-payment-email'), path('resend-payment-email/<str:team_registration_id>/', views.resend_payment_email, name='resend-payment-email'),
path('payment-link/<str:team_registration_id>/', views.get_payment_link, name='get-payment-link'),
] ]

@ -647,6 +647,42 @@ def resend_payment_email(request, team_registration_id):
except Exception as e: except Exception as e:
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) 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']) @api_view(['GET'])
@permission_classes([IsAuthenticated]) @permission_classes([IsAuthenticated])
def is_granted_unlimited_access(request): def is_granted_unlimited_access(request):

@ -710,7 +710,7 @@ class PaymentService:
customer_email = team_registration.team_contact() customer_email = team_registration.team_contact()
currency_code = tournament.currency_code or 'EUR' 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}") print(f"[PAYMENT LINK] is_corporate_tournament: {tournament.is_corporate_tournament}")
# Base metadata (same as checkout session) # Base metadata (same as checkout session)

Loading…
Cancel
Save