Implementation Steps
The SDK must be initialised in your AppDelegate
To implement the SDK’s In Path flow within your app, please use the following steps:
Steps
Initialise the SDK in your App Delegate
Note that the production
parameter must be set to true when submitting your app to the AppStore.
// In application(_:didFinishLaunchingWithOptions:)
CarTrawlerSDK.sharedInstance().initialiseSDK(with: nil,
customParameters: nil,
production: false)
The production parameter must be set to true when submitting your app to the AppStore.
style
: An optional CTStyle object, used to set the fonts as well as the primary, secondary, and accent colors in the SDK. Please ensure any custom fonts used are included in your main bundle.
Initialise the CTContext Object with the Required Parameters
This can be done in the view controller the SDK will be presented from.
The implementationID
is needed by the SDK to fetch partner specific configuration.
import CarTrawlerSDK
// Create a context for in Path flow
let context = CTContext(implementationID: "your implementation ID",
clientID: "your client ID",
flow: .inPath)
context.countryCode = "IE" // The country code associated with the device’s system region is used by default.
context.currencyCode = "EUR" // The currency associated with the device’s system region is used by default.
context.languageCode = "EN" // The language associated with the device’s system region is used by default.
// Create CTFLightDetails
let flightDetails = CTFlightDetails()
flightDetails.flightOrigin = "DUB|LHR|2025-01-16T06:05:00|2025-01-16T07:25:00|XX8719"
flightDetails.flightReturn = "LHR|DUB|2025-01-22T21:20:00|2025-01-23T22:45:00|XX8720"
flightDetails.passengerBreakdown = CTFlightPassengerBreakdown(adults: 2, teens: 0, children: 0, infants: 0)
flightDetails.firstName = "John"
flightDetails.surName = "Doe"
flightDetails.customerEmail = "john.doe@example.com"
flightDetails.fareClass = "business"
flightDetails.flightFare = 175.95
flightDetails.bags = 1
flightDetails.loyaltyNumber = "ABC123456"
flightDetails.loyaltyTier = "gold"
// Set flight details on context
context.flightDetails = flightDetails
The countryCode
property refers to the country of residency.
Object Description:
class CTContext: NSObject {
let implementationID: String
let clientID: String
let flowType: CTFlowType
let countryCode: String
let currencyCode: String
let pinnedVehicleID: String
let flightDetails: CTFlightDetails
}
class CTFlightDetails: NSObject {
let flightOrigin: String
let flightReturn: String
let passengerBreakdown: CTFlightPassengerBreakdown
let firstName: String
let surName: String
let customerEmail: String
let flightFare: Double
let bags: UInt
let loyaltyNumber: String
let loyaltyTier: String
}
class CTFlightPassengerBreakdown: NSObject {
let adults: UInt
let teens: UInt
let children: UInt
let infants: UInt
}
Click here for an in depth explanation of CTContext’s properties.
Prewarm Grid View
After initialisation and setup of your CTContext
object for In Path, you can pre warm the grid view. Prewarm mode allows the Grid View to preload all necessary API data before the user reaches the car rental offer page, resulting in significantly faster load times. To use prewarm, you must request the CTGridView object to the SDK and add as a subview to a visible UIView, the component doesn’t need to appear on the screen and it’s hidden by default. At this point the grid view won’t display any UI, instead, it will fetch and cache API responses. These cached responses are then used when the user navigates to the main offer page, making the experience seamless and quick.
It is recommended to prewarm the grid view in a previous step or ViewController before you reach the ViewController where it will effectively be presented. Example:
class Step1ViewController: UIViewController {
var context: CTContext!
override func viewDidLoad() {
super.viewDidLoad()
// Request prewarmed grid view hidden by default
let gridView = CarTrawlerSDK.sharedInstance().preWarmGridView(with: context)
// Add to subview
self.view.addSubview(gridView)
}
}
Present Grid View
The grid view is a component returned by the SDK where a number of recommended vehicles will be displayed as a grid.
When the user taps on a vehicle block, the grid view will work internally to present the SDK in a modal from the UIViewContoller sent as a parameter.
Request grid view to the CarTrawlerSDK:
func getGridView(
from: UIViewController, // The UIViewController from where the SDK modal will be presented
context: CTContext // The CTContext with all parameters needed
)
Add the grid view to your own view controller:
class Step2ViewController: UIViewController {
var context: CTContext! // Previously configured context
override func viewDidLoad() {
super.viewDidLoad()
// Request grid view
let gridView = CarTrawlerSDK.sharedInstance().getGridView(from: self, context: context)
// Add to subview
self.view.addSubview(gridView)
}
}
Present Grid View with alternative flow (FBE)
The default behaviour of the grid view is flightDetails.context = "IN_PATH"
, which means it will assume it has been presented during the flight selection, it will open the InPath flow and return the booking JSON when the user selects the vehicle.
Alternatively, you can use the grid view in the end of your flow, for example as a post booking option, after the user has paid for the flight but didn’t rent a car.
On that case, the flightDetails.context
can be set to CONFIRMATION
and when the user taps on any vehicle, it will open a FBE flow, which is the complete flow (vehicle and insurance selection, payment and confirmation) provided by CarTrawler.
Example of request grid view with alternative flow (FBE):
import CarTrawlerSDK
class Step2ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Create a context for in Path flow
let context = CTContext(implementationID: "your implementation ID",
clientID: "your client ID",
flow: .inPath)
context.countryCode = "IE" // The country code associated with the device’s system region is used by default.
context.currencyCode = "EUR" // The currency associated with the device’s system region is used by default.
context.languageCode = "EN" // The language associated with the device’s system region is used by default.
// Create CTFLightDetails
let flightDetails = CTFlightDetails()
flightDetails.flightOrigin = "DUB|LHR|2025-01-16T06:05:00|2025-01-16T07:25:00|XX8719"
flightDetails.flightReturn = "LHR|DUB|2025-01-22T21:20:00|2025-01-23T22:45:00|XX8720"
flightDetails.passengerBreakdown = CTFlightPassengerBreakdown(adults: 2, teens: 0, children: 0, infants: 0)
flightDetails.firstName = "John"
flightDetails.surName = "Doe"
flightDetails.customerEmail = "john.doe@example.com"
flightDetails.fareClass = "business"
flightDetails.flightFare = 175.95
flightDetails.bags = 1
flightDetails.loyaltyNumber = "ABC123456"
flightDetails.loyaltyTier = "gold"
flightDetails.context = "CONFIRMATION" // Needed to define the flow
// Set flight details on context
context.flightDetails = flightDetails
// Request grid view
let gridView = CarTrawlerSDK.sharedInstance().getGridView(from: self, context: context)
// Add to subview
self.view.addSubview(gridView)
}
}
Collect the booking data after flow completion
After a user has gone through the entire In Path flow and selected a vehicle, the SDK will use a delegate callback to send all of the booking data.
The payload JSON to be used on the reservation process, it will be returned as request["ota"]
CarTrawler SDK Delegate:
// Required. Called when the user wants to add an In Path booking to their flight booking.
func didProduce(inPathPaymentRequest request: [AnyHashable : Any], vehicle: CTInPathVehicle, payment: Payment) {
print("\(request)")
print("\(request["ota"])") // Payload JSON to make the booking
print("Total \(vehicle.totalCost)")
print("Insurance \(vehicle.insuranceCost)")
print("Vehicle Name \(vehicle.vehicleName)")
print("*** PAYNOW: \(vehicle.payNowPrice)\n" ,
"*** PAYLATER: \(vehicle.payLaterPrice)\n" ,
"*** PAYDESK: \(vehicle.payAtDeskPrice)\n" ,
"*** BOOKINGFEE: \(vehicle.bookingFeePrice)\n")
print("*** Payment ***")
print("authTotal: \(payment.authTotal)")
print("authCurrency: \(payment.authCurrency)")
}
In Path Vehicle Object:
class CTInPathVehicle: NSObject {
let firstName: String // First name
let lastName: String // Last name
let vehicleName: String // Vehicle name
let vendorName: String // Vendor name
let vehicleImageURL: URL // vehicle image url
let vendorImageURL: URL // vendorImageURL
let pickUpLocationName: String // pick-up location name
let dropOffLocationName: String // drop-off location name
let pickupDate: Date // pick-up date
let dropoffDate: Date // drop-off date
let isBuyingInsurance: Bool // is buying insurance
let insuranceCost: Number // Insurance cost
let totalCost: Number // total cost
let refId: String // vehicle reference id
let payNowPrice: Number // pay now price
let payAtDeskPrice: Number // pay at the desk price
let payLaterPrice: Number // pay later price
let bookingFeePrice: Number // just the vehicle rental price