Using the SDK

Configuring the SDK

You must initialise the SDK to use an environment using the API key that was supplied to you by BookingGo before using it:

    let apiKey = APIKey(partner: "partner", secret: "D376BE3C-3381-4DE1-B360-E5CEA0E79D81")
    BookingGoCars.initialize(withEnvironment: .production(apiKey: apiKey))

It is expected that the SDK will be initialized when the app starts - e.g. in the application’s didFinishLaunchingWithOptions implementation - this so that it can obtain configuration in the background so it is up-to-date when one of the SDK’s flows is invoked.

Styling the UI

You can inject styles that define colors, fonts and metrics used by the UI of the SDK:

    let primaryBackgroundColor = UIColor.blue
    let primaryForegroundColor = UIColor.white
    let secondaryBackgroundColor = UIColor.darkGray
    let secondaryForegroundColor = UIColor.white

    let headingFont = UIFont.systemFont(ofSize: 22.0)
    let ctaFont = UIFont.systemFont(ofSize: 17.0)

    let statusBarStyle: UIStatusBarStyle = .lightContent

    BookingGoCars.applyStyle(Style(defaultTheme: Theme(palette: Palette(primaryBackgroundColor: primaryBackgroundColor,
                                                                        primaryForegroundColor: primaryForegroundColor,
                                                                      secondaryBackgroundColor: secondaryBackgroundColor,
                                                                      secondaryForegroundColor: secondaryForegroundColor),
                                                    typography: Typography(heading: headingFont, cta: ctaFont),
                                                       metrics: UIMetrics(preferredStatusBarStyle: statusBarStyle))))

Presenting a flow

Two flows are available:

  1. In-path for use in your booking flow
  2. Standalone for use outside of your booking flow

These can be presented from a parent view-controller as follows:

  1. In-path
    let passengerCounts = PassengerCounts { builder in
        builder.adults = 1
        builder.teenagers = 0
        builder.children = 0
        builder.infants = 0
    }

    let searchContext = SearchContext { builder in
        builder.pickUp = SearchPickUp(date: pickupDate, location: .airport(airport: Airport(iataCode: "MAN")))
        builder.flightDesignator = FlightDesignator(code: "AB 1234")
        builder.driverAge = 25
        builder.localePreferences = LocalePreferences(countryOfResidence: "GB", displayCurrency: "GBP", preferredLanguage: "EN")
        builder.passengerCounts = passengerCounts
    }

    if let searchContext = searchContext {
        BookingGoCars.present(.inPath(searchContext: searchContext, partnerInformation: nil), from: self, completion: { [weak self] (booking: Booking?) in
            self?.makeBooking(booking)
        })
    }
  1. Standalone
    BookingGoCars.present(.standalone(preferredLanguage: "EN", partnerInformation: nil), from: self, completion: { [weak self] (booking: Booking?) in
        self?.saveBooking(booking)
    })

Requesting a price

A price can be requested for a search context (pick-up/drop-off location and times) - this will return the lowest or most recommended available price for that search:

    BookingGoCars.requestPrice(searchContext: buildSearchContext()) { (result) in
        switch result {
        case .success(let indicativePrice):
            DispatchQueue.main.sync {
                priceLabel.text = "\(indicativePrice.prefix) \(indicativePrice.price.description) \(indicativePrice.suffix)"
            }
        case.failure(_):
            DispatchQueue.main.sync {
                priceLabel.text = ""
            }
        }
    }

Obtaining the model for building an “upsell widget” for in-path

In order to entice the customer to enter the in-path car rental flow, you may want to display a “widget” with a CTA that contains copy to upsell the service - the model for this can be requested as follows:

    let inPathUpsellWidgetModel = BookingGoCars.getInPathUpsellWidgetModel()

    if let url = URL(string: inPathUpsellWidgetModel.bannerImageUrl) {
            bannerImageView.loadFromURL(url)
        }

    headlineLabel.text = inPathUpsellWidgetModel.headline
    taglineLabel.text = inPathUpsellWidgetModel.tagline

Adding an event listener

Your application can listen to events (page-views, user-actions, errors) from the SDK that are also reported back to BookingGo by adding an EventListener to the SDK:

    class MyEventListener: EventListener {
    func eventFired(_ event: Event) {
        print("\(event)")
    }

    ...

    let eventListener = MyEventListener()
    BookingGoCars.addEventListener(eventListener)