This method is used to book a new trip
book(tripBooking: TripBooking) : Call<TripInfo>
This method Iaccepts a TripBooking as a parameter. This can be created with a quoteId, UserInfo object and optional flightNumber.
QuoteService needs to be used in order to get a quoteId and UserService to get a UserInfo object.
Parameters
tripBooking:TripBooking
Returns
Call<TripInfo>
Errors
- InvalidQuoteId
- K4001
CouldNotBookTrip - K4002
CouldNotBookTripInvalidRequest - K4003
CouldNotBookTripCouldNotFindQuote - K4004
CouldNotBookTripAttemptToBookExpiredQuote - K4005
CouldNotBookTripPermissionsDenied - K4006
CouldNotBookTripPaymentPreAuthFailed - K4014
CouldNotBookTripCouldNotBookTripAsAgent - K4015
CouldNotBookTripCouldNotBookTripAsTraveller
Examples
iOS
let tripService = Karhoo.getTripService()
let userInfo = UserInfo(userId: "123",
firstName: "John",
lastName: "Smith",
email: "[email protected]",
mobileNumber: "+441234567890",
locale: "uk",
metadata: "")
let tripBooking = TripBooking(quoteId: "1234",
userInfo: userInfo,
flightNumber: nil)
tripService.book(tripBooking: tripBooking).execute { result in
switch result {
case .success(let trip):
print("Trip: \(trip)")
case .failure(let error):
print("error: \(error.code) \(error.message)")
}
}
Android
val tripService = KarhooApi.tripService
val quoteId = "1234" // you can get this ID from the quotes service.
val passengers = Passengers(
additionalPassengers = 0,
passengerDetails = listOf(PassengerDetails(
firstName = "John",
lastName = "Smith",
phoneNumber = "+441234567890",
email = "[email protected]"
)))
val flightNumber = "BOE747"
val tripBooking = TripBooking(
quoteId = quoteId,
passengers = passengers,
flightNumber = flightNumber))
tripsService.book(tripBooking)
.execute { result ->
when (result) {
is Resource.Success -> print(result.data) //Handle data
is Resource.Failure -> print(result.error) //Handle error
}
}
