Endpoint
Description
Purchases a ticket for an event using a valid waiting list offer. This mutation validates the waiting list entry, creates the ticket with payment information, and automatically processes the queue for the next person in line. Source:convex/events.ts:192-275
Parameters
The unique identifier of the event for which to purchase a ticket
The unique identifier of the user purchasing the ticket (must match the waiting list entry)
The waiting list entry ID with “offered” status. The offer must not be expired.
Waiting List Validation
The endpoint performs strict validation on the waiting list entry:- Entry Exists - The waiting list entry must exist in the database
- Status Check - Entry must have status “offered” (not waiting, expired, or purchased)
- User Match - The userId in the request must match the userId on the waiting list entry
- Offer Expiration - The offer must not have expired (checked by status)
Event Validation
The endpoint also validates the event:- Event must exist
- Event must not be cancelled (
is_cancelledmust be false/undefined)
Response
The mutation does not return a value on success. If the purchase fails, an error is thrown.Errors
"Waiting list entry not found"- The waitingListId doesn’t exist"Invalid waiting list status - ticket offer may have expired"- The entry is not in “offered” status"Waiting list entry does not belong to this user"- userId mismatch"Event not found"- The eventId doesn’t exist"Event is no longer active"- The event has been cancelled"Failed to complete ticket purchase: {error}"- Generic error during ticket creation
Side Effects
-
Ticket Creation - A new ticket is created with:
- Status: “valid”
- Purchase timestamp
- Payment intent ID and amount
- Waiting List Update - The waiting list entry status is changed to “purchased”
- Queue Processing - The next person in the waiting list is automatically offered a ticket
Example
Payment Flow
- User receives a ticket offer (waiting list status: “offered”)
- Frontend initiates Stripe payment
- Stripe returns paymentIntentId
- Call
purchaseTicketwith payment information - Ticket is created and payment is tracked
- Next user in queue receives an offer automatically