|
|
|
|
@ -16,6 +16,7 @@ from django.shortcuts import get_object_or_404 |
|
|
|
|
|
|
|
|
|
from .serializers import ClubSerializer, CourtSerializer, DateIntervalSerializer, DrawLogSerializer, TournamentSerializer, UserSerializer, EventSerializer, RoundSerializer, GroupStageSerializer, MatchSerializer, TeamScoreSerializer, TeamRegistrationSerializer, PlayerRegistrationSerializer, PurchaseSerializer, ShortUserSerializer, FailedApiCallSerializer, LogSerializer, DeviceTokenSerializer, CustomUserSerializer, UnregisteredTeamSerializer, UnregisteredPlayerSerializer, ImageSerializer, ActivitySerializer, ProspectSerializer, EntitySerializer, TournamentSummarySerializer |
|
|
|
|
from tournaments.models import Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamScore, TeamRegistration, PlayerRegistration, Court, DateInterval, Purchase, FailedApiCall, Log, DeviceToken, DrawLog, UnregisteredTeam, UnregisteredPlayer, Image |
|
|
|
|
from tournaments.services.email_service import TournamentEmailService |
|
|
|
|
|
|
|
|
|
from biz.models import Activity, Prospect, Entity |
|
|
|
|
|
|
|
|
|
@ -621,110 +622,30 @@ def validate_stripe_account(request): |
|
|
|
|
|
|
|
|
|
@api_view(['POST']) |
|
|
|
|
@permission_classes([IsAuthenticated]) |
|
|
|
|
def create_payment_link(request, team_registration_id): |
|
|
|
|
def resend_payment_email(request, team_registration_id): |
|
|
|
|
""" |
|
|
|
|
Create a Stripe Payment Link for a team registration |
|
|
|
|
Resend the registration confirmation email (which includes payment info/link) |
|
|
|
|
""" |
|
|
|
|
try: |
|
|
|
|
# Verify team registration exists and user has permission |
|
|
|
|
team_registration = TeamRegistration.objects.get(id=team_registration_id) |
|
|
|
|
tournament = team_registration.tournament |
|
|
|
|
|
|
|
|
|
# Check if payment is required and team hasn't paid |
|
|
|
|
if tournament.is_free() or team_registration.get_payment_status() == 'PAID': |
|
|
|
|
return Response( |
|
|
|
|
{'error': 'Payment not required or already completed'}, |
|
|
|
|
status=status.HTTP_400_BAD_REQUEST |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# Create payment link |
|
|
|
|
payment_link_url = PaymentService.create_payment_link(team_registration_id) |
|
|
|
|
|
|
|
|
|
if payment_link_url: |
|
|
|
|
return Response({ |
|
|
|
|
'success': True, |
|
|
|
|
'payment_link': payment_link_url, |
|
|
|
|
'team_registration_id': str(team_registration_id), |
|
|
|
|
'tournament_name': tournament.display_name(), |
|
|
|
|
'amount': team_registration.get_team_registration_fee(), |
|
|
|
|
'currency': tournament.currency_code |
|
|
|
|
}) |
|
|
|
|
else: |
|
|
|
|
return Response( |
|
|
|
|
{'error': 'Failed to create payment link'}, |
|
|
|
|
status=status.HTTP_500_INTERNAL_SERVER_ERROR |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
except TeamRegistration.DoesNotExist: |
|
|
|
|
return Response( |
|
|
|
|
{'error': 'Team registration not found'}, |
|
|
|
|
status=status.HTTP_404_NOT_FOUND |
|
|
|
|
TournamentEmailService.send_registration_confirmation( |
|
|
|
|
request, |
|
|
|
|
tournament, |
|
|
|
|
team_registration, |
|
|
|
|
waiting_list_position=-1 |
|
|
|
|
) |
|
|
|
|
except Exception as e: |
|
|
|
|
return Response( |
|
|
|
|
{'error': f'Unexpected 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 or create a payment link for a specific team registration |
|
|
|
|
""" |
|
|
|
|
try: |
|
|
|
|
team_registration = TeamRegistration.objects.get( |
|
|
|
|
id=team_registration_id |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
tournament = team_registration.tournament |
|
|
|
|
|
|
|
|
|
# Check payment status |
|
|
|
|
payment_status = team_registration.get_payment_status() |
|
|
|
|
|
|
|
|
|
if payment_status == 'PAID': |
|
|
|
|
return Response({ |
|
|
|
|
'success': False, |
|
|
|
|
'message': 'Payment already completed', |
|
|
|
|
'payment_status': 'PAID' |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if tournament.is_free(): |
|
|
|
|
return Response({ |
|
|
|
|
'success': False, |
|
|
|
|
'message': 'Tournament is free', |
|
|
|
|
'payment_status': 'NOT_REQUIRED' |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
# Get or create payment link |
|
|
|
|
payment_link_url = PaymentService.get_or_create_payment_link(team_registration_id) |
|
|
|
|
|
|
|
|
|
if payment_link_url: |
|
|
|
|
return Response({ |
|
|
|
|
'success': True, |
|
|
|
|
'payment_link': payment_link_url, |
|
|
|
|
'team_registration_id': str(team_registration_id), |
|
|
|
|
'tournament_name': tournament.display_name(), |
|
|
|
|
'amount': team_registration.get_team_registration_fee(), |
|
|
|
|
'currency': tournament.currency_code, |
|
|
|
|
'payment_status': payment_status |
|
|
|
|
}) |
|
|
|
|
else: |
|
|
|
|
return Response( |
|
|
|
|
{'error': 'Failed to create payment link'}, |
|
|
|
|
status=status.HTTP_500_INTERNAL_SERVER_ERROR |
|
|
|
|
) |
|
|
|
|
return Response({ |
|
|
|
|
'success': True, |
|
|
|
|
'message': 'Email de paiement renvoyé' |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
except (Tournament.DoesNotExist, TeamRegistration.DoesNotExist): |
|
|
|
|
return Response( |
|
|
|
|
{'error': 'Tournament or team registration not found'}, |
|
|
|
|
status=status.HTTP_404_NOT_FOUND |
|
|
|
|
) |
|
|
|
|
except TeamRegistration.DoesNotExist: |
|
|
|
|
return Response({'error': 'Team not found'}, status=status.HTTP_404_NOT_FOUND) |
|
|
|
|
except Exception as e: |
|
|
|
|
return Response( |
|
|
|
|
{'error': f'Unexpected 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]) |
|
|
|
|
|