Skip to content

Commit

Permalink
Check ticket holds before completing checkout (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviupadhyayula committed Apr 15, 2024
1 parent b911872 commit 4af8765
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4872,6 +4872,7 @@ def initiate_checkout(self, request, *args, **kwargs):
)

@action(detail=False, methods=["post"])
@update_holds
@transaction.atomic
def complete_checkout(self, request, *args, **kwargs):
"""
Expand Down Expand Up @@ -4911,6 +4912,17 @@ def complete_checkout(self, request, *args, **kwargs):
Cart.objects.prefetch_related("tickets"), owner=self.request.user
)

# Guard against holds expiring before the capture context
tickets = cart.tickets.filter(holder=self.request.user, owner__isnull=True)
if tickets.count() != cart.tickets.count():
return Response(

Check warning on line 4918 in backend/clubs/views.py

View check run for this annotation

Codecov / codecov/patch

backend/clubs/views.py#L4916-L4918

Added lines #L4916 - L4918 were not covered by tests
{
"success": False,
"detail": "Cart is stale, invoke /api/tickets/cart to refresh",
},
status=status.HTTP_400_BAD_REQUEST,
)

try:
_, http_status, transaction_data = TransientTokenDataApi(

Check warning on line 4927 in backend/clubs/views.py

View check run for this annotation

Codecov / codecov/patch

backend/clubs/views.py#L4926-L4927

Added lines #L4926 - L4927 were not covered by tests
settings.CYBERSOURCE_CONFIG
Expand Down

0 comments on commit 4af8765

Please sign in to comment.