This method is used to book a new trip
book(tripBooking: TripBooking) : Call<TripInfo>
This method accepts TripBooking
as a parameter. This can be created with a quoteId
and optional flightNumber
. TripBooking
also contains an optional paymentNonce
string. This nonce represents the payment method for booking the trip. It is optional for invoice bookings where no payment method is required from the user. Otherwise, this payment nonce comes from Braintree Payment SDK. More information on integrating payment SDKs can be found here: https://developer.karhoo.com/docs/using-the-ui-sdk#payment-method-setup
QuoteService
needs to be used in order to get a quoteId
.
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 quoteId = "1234" // you can get this ID from the quotes service.
let passengers = Passengers(
additionalPassengers: 0,
passengerDetails: [PassengerDetails(
firstName: "John",
lastName: "Smith",
phoneNumber: "+441234567890",
email: "[email protected]",
locale: "gb"
)])
let tripBooking = TripBooking(quoteId: quoteId,
passengers: passengers,
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]",
locale = "gb"
)))
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
}
}