Trip States
A trip progresses through multiple states during its lifecycle. Here are all possible states:pending
Initial state when a trip is first created. The trip request has been received but driver matching has not yet started. Possible transitions:assigning- When the matching system begins looking for available driverscancelled- If the passenger cancels before matching starts
assigning
The system is actively searching for and offering the trip to available drivers. Possible transitions:accepted- When a driver accepts the trip assignmentno_drivers_found- If no drivers accept within the timeout periodcancelled- If the passenger cancels during matching
accepted
A driver has accepted the trip and is preparing to head to the pickup location. Possible transitions:arriving- When the driver starts navigating to the pickup pointcancelled- If the passenger or driver cancels
arriving
The driver is en route to the pickup location. Possible transitions:arriving(arrived at pickup) - When the driver reaches the pickup pointin_progress- When the passenger boards and the trip startscancelled- If the passenger or driver cancels
in_progress
The passenger is on board and the trip is actively underway to the destination. Possible transitions:completed- When the trip reaches the final destinationcancelled- In rare cases (emergency, etc.)
completed
The trip has been successfully completed. This is a terminal state. No further transitions possible.cancelled
The trip was cancelled by the passenger, driver, or system. This is a terminal state. No further transitions possible.no_drivers_found
No available drivers accepted the trip within the matching timeout period. This is a terminal state. No further transitions possible.State Transition Diagram
Lifecycle Timestamps
Each state transition is tracked with specific timestamp fields:When the trip was initially requested (trip creation)
When a driver accepted the trip assignment
Estimated time when driver will arrive at pickup (set when entering
arriving)When the driver physically arrived at the pickup location
When the trip started (passenger on board, entering
in_progress)When the trip was successfully completed
When the trip was cancelled (if applicable)
API Endpoints for State Transitions
Each state transition is triggered by specific API endpoints:pending → assigning
POST /trips/{id}/assign/start
assigning → accepted
PATCH /trips/assignments/{assignmentId}/accept
accepted → arriving
POST /trips/{id}/arriving
arriving → arrived at pickup
POST /trips/{id}/arrived-pickup
arriving/arrived → in_progress
POST /trips/{id}/start
in_progress → completed
POST /trips/{id}/complete
assigning → no_drivers_found
POST /trips/{id}/assign/no-drivers
Driver Assignment Flow
Theassigning state involves a multi-step assignment process:
- System creates assignments - Trip assignments are created for eligible drivers based on proximity, vehicle category, and availability
- Drivers receive offers - Each assignment represents an offer sent to a driver with a timeout (typically 15-30 seconds)
-
Driver responds - Driver can:
- Accept - Trip moves to
accepted, driver is assigned - Reject - System continues offering to other drivers
- Timeout - If no response within timeout, offer expires and continues to next driver
- Accept - Trip moves to
-
Outcomes:
- If any driver accepts → Trip becomes
accepted - If all drivers reject/timeout → Trip becomes
no_drivers_found - If passenger cancels during matching → Trip becomes
cancelled
- If any driver accepts → Trip becomes
Assignment Endpoints
POST /trips/{id}/reject
POST /trips/{id}/expire
Events and Notifications
Each state transition triggers domain events that can be used for:- Real-time notifications - WebSocket updates to passenger and driver apps
- Audit logging - Complete history of trip state changes
- Analytics - Trip metrics and performance tracking
- Integration hooks - Third-party system notifications
Event Types
TripRequestedEvent- Trip created (pending)AssigningStartedEvent- Matching started (assigning)DriverAcceptedEvent- Driver accepted assignment (accepted)ArrivingStartedEvent- Driver en route (arriving)DriverArrivedPickupEvent- Driver at pickup locationTripStartedEvent- Trip in progress (in_progress)TripCompletedEvent- Trip finished (completed)DriverRejectedEvent- Driver rejected offerAssignmentExpiredEvent- Offer timeoutNoDriversFoundEvent- No drivers available (no_drivers_found)
Get Active Trip for Passenger
Path Parameters
Passenger user UUID
Response
Indicates if the operation was successful
Response message
The active trip object, or null if the passenger has no active trip
Example Request
Get Active Trip for Driver
Path Parameters
Driver UUID
Response
Indicates if the operation was successful
Response message
The active trip object, or null if the driver has no active trip
Example Request
Accept Trip Assignment (Driver)
Path Parameters
Assignment UUID (not trip UUID)
Headers
Bearer token for driver authentication. The driver ID is extracted from the JWT.
Response
Indicates if the operation was successful
Response message
Updated trip object in
accepted status with driver assignedExample Request
Error Responses
- 401 Unauthorized: Invalid or missing JWT token
- 409 Conflict: Assignment not active or already responded to
Reject Trip Assignment
Path Parameters
Trip UUID
Body Parameters
UUID of the driver rejecting the assignment
Reason for rejection (e.g.,
too_far, unavailable, other)Response
Indicates if the operation was successful
Response message
Trip object (still in
assigning status)Example Request
Error Responses
- 409 Conflict: Assignment not active or already responded to
- 400 Bad Request: Validation error
Expire Trip Assignment
Path Parameters
Trip UUID
Response
Indicates if the operation was successful
Response message
Trip object. If more drivers are available, continues in
assigning status. Otherwise may transition to no_drivers_found.Example Request
Error Responses
- 409 Conflict: Assignment not active or already responded to
Mark Trip as No Drivers Found
Path Parameters
Trip UUID
Response
Indicates if the operation was successful
Response message
Trip object in
no_drivers_found statusExample Request
Use Case
This endpoint is typically called automatically by the matching system when:- All eligible drivers have rejected the trip
- All assignment offers have timed out
- No drivers are available within the search radius
Viewing Trip Events
You can retrieve the complete audit trail of all events for a trip:GET /trips/{id}/events
Business Rules
State Validation
- State transitions are validated to ensure they follow the allowed flow
- Invalid transitions (e.g.,
pending→completed) are rejected with HTTP 409 Conflict
Driver Assignment
- Only the assigned driver can perform actions on trips in
accepted,arriving, orin_progressstates - Driver ID is validated on all driver action endpoints
Fare Calculation
fareEstimatedTotalis set when trip is created (based on pricing engine)fareTotalis calculated when trip transitions tocompleted- Fare breakdown includes actual distance, duration, surge, and all fees
Cancellation
- Trips can be cancelled at any non-terminal state
- Cancellation policies may apply fees depending on trip state
- Both passenger and driver may have cancellation rights with different rules
See Also
- Create Trip - Initialize a new trip
- Get Trip - Retrieve trip details including current state
- List Trips - Filter trips by status
