Overview
The TripApiService provides HTTP methods for all trip-related operations throughout the driver’s journey, from accepting assignments to completing trips.
Location : src/app/core/services/http/trip-api.service.ts
Public Methods
getById()
Retrieves detailed information about a specific trip.
The unique identifier of the trip
Returns : Observable<TripDto>
this . tripApiService . getById ( 'trip_123456' ). subscribe ({
next : ( trip ) => {
console . log ( 'Trip details:' , trip );
this . displayOrigin = trip . origin . label ;
this . displayDestination = trip . destination . label ;
}
});
acceptAssignment()
Accepts a trip assignment offer before it expires.
The unique identifier of the trip assignment
Returns : Observable<TripDto>
this . tripApiService . acceptAssignment ( assignmentId ). subscribe ({
next : ( trip ) => {
console . log ( 'Assignment accepted:' , trip );
// Navigate to active trip view
this . router . navigate ([ '/trips/active' ]);
},
error : ( error ) => {
if ( error . code === 'ASSIGNMENT_EXPIRED' ) {
this . showMessage ( 'This trip offer has expired' );
}
}
});
declineAssignment()
Declines a trip assignment offer.
The unique identifier of the trip assignment
Returns : Observable<void>
this . tripApiService . declineAssignment ( assignmentId ). subscribe ({
next : () => {
console . log ( 'Assignment declined' );
// Return to home screen
}
});
markArrivedPickup()
Marks that the driver has arrived at the pickup location.
The unique identifier of the trip
The unique identifier of the driver
Returns : Observable<TripDto>
Response Fields :
ISO 8601 timestamp when driver arrived at pickup
Updated trip status (should be ‘ARRIVING’ or ‘PICKUP_ARRIVED’)
this . tripApiService . markArrivedPickup ( tripId , driverId ). subscribe ({
next : ( trip ) => {
console . log ( 'Marked as arrived at:' , trip . arrivedPickupAt );
// Start waiting timer
this . startWaitingTimer ( trip . arrivedPickupAt );
}
});
startTrip()
Starts the trip after picking up the passenger.
The unique identifier of the trip
The unique identifier of the driver
Returns : Observable<TripDto>
Response Fields :
ISO 8601 timestamp when trip started
Updated trip status (should be ‘IN_PROGRESS’)
this . tripApiService . startTrip ( tripId , driverId ). subscribe ({
next : ( trip ) => {
console . log ( 'Trip started at:' , trip . startedAt );
// Navigate to in-progress trip view
}
});
completeTrip()
Completes the trip and finalizes the fare calculation.
The unique identifier of the trip
payload
CompleteTripPayload
required
Trip completion details Show CompleteTripPayload Properties
The driver completing the trip
Additional fees (e.g., waiting charges)
Total waiting time in minutes
Reason for waiting charges
Actual distance traveled in kilometers
Actual trip duration in minutes
Returns : Observable<TripDto>
Example :
const payload : CompleteTripPayload = {
driverId: 'driver_123' ,
extraFees: 5.0 ,
waitingTimeMinutes: 8 ,
waitingReason: 'Passenger delayed at pickup' ,
actualDistanceKm: 12.5 ,
actualDurationMin: 25
};
this . tripApiService . completeTrip ( tripId , payload ). subscribe ({
next : ( trip ) => {
console . log ( 'Trip completed:' , trip );
console . log ( 'Final fare:' , trip . fareFinalTotal , trip . fareFinalCurrency );
// Show completion summary
}
});
Response Types
TripDto
Complete trip object returned by most endpoints:
interface TripDto {
id : string ;
status : string ;
origin : TripStopDto ;
destination : TripStopDto ;
intermediateStops ?: TripStopDto [];
passenger ?: {
id : string ;
name : string ;
phoneMasked : string ;
photoUrl ?: string ;
};
driver ?: {
id : string ;
name : string ;
phoneMasked : string ;
photoUrl ?: string ;
};
driverId ?: string ;
fareEstimatedTotal ?: number ;
fareEstimatedCurrency ?: string ;
fareFinalTotal ?: number ;
fareFinalCurrency ?: string ;
paymentMode : string ;
requestedAt : string ;
assignedAt ?: string ;
arrivedPickupAt ?: string ;
startedAt ?: string ;
completedAt ?: string ;
cancelledAt ?: string ;
}
See Trip Models for complete type definitions.
Error Handling
All trip operations may fail with specific error codes. Always handle these appropriately:
this . tripApiService . acceptAssignment ( assignmentId ). subscribe ({
error : ( error : ApiError ) => {
switch ( error . code ) {
case 'ASSIGNMENT_EXPIRED' :
this . showError ( 'This trip offer has expired' );
break ;
case 'ASSIGNMENT_ALREADY_TAKEN' :
this . showError ( 'Another driver accepted this trip' );
break ;
case 'DRIVER_NOT_AVAILABLE' :
this . showError ( 'You must be online to accept trips' );
break ;
default :
this . showError ( error . message || 'Failed to accept trip' );
}
}
});
Best Practices
Always refresh trip data after status changes to ensure UI reflects the latest state.
Waiting fees : Track waiting time from arrivedPickupAt to startedAt and apply charges according to your business rules.
Offline support : Consider queuing trip updates when offline and syncing when connection is restored.