Skip to main content

Quick Start

Get up and running with the Flex Checkout iOS SDK in minutes. This guide walks you through installation, initialization, and opening your first checkout.

For detailed configuration options, see the Installation page.

1. Add the Dependency​

Add the SDK using Swift Package Manager in your Package.swift:

Swift
dependencies: [
.package(url: "https://github.com/flexapp/flex-checkout-ios", from: "1.6.0")
]

Or add it through Xcode: File > Add Package Dependencies... and enter https://github.com/flexapp/flex-checkout-ios.


2. Initialize the SDK​

Set up the SDK in your app's entry point and pass it to your root view:

Swift
import FlexCheckout
import SwiftUI

@main
struct MyApp: App {
private let sdk: FlexSDKProtocol

init() {
let sdk = Flex.initialize(config: ...) // 2a
sdk.loadToken { ... } // 2b
sdk.checkout(CheckoutConfig(...)) // 2c

self.sdk = sdk
}

var body: some Scene {
WindowGroup {
ContentView(sdk: sdk)
}
}
}

The three calls inside init(), expanded:

Initialize​

Swift
let sdk = Flex.initialize(config: FlexConfig(
clientId: "your-flex-client-id",
environment: .int // use .prod for production
))

Register a token provider​

Swift
sdk.loadToken {
try await yourApi.getFlexToken().token
}

Configure checkout callbacks​

Swift
sdk.checkout(CheckoutConfig(
onOpen: { /* opened */ },
onClose: { /* closed */ },
onError: { error in /* handle error */ },
onEvent: { event in
switch event.type {
case .onboardingCompleted:
// event.data.autopayEnabled if autopay was set up
break
case .paymentCompleted:
break
}
}
))

3. Add the Split Rent Button​

Add the FlexSplitRentButton SwiftUI view to your content view:

Swift
import FlexCheckout
import SwiftUI

struct ContentView: View {
let sdk: FlexSDKProtocol

var body: some View {
VStack {
FlexSplitRentButton(config: SplitRentButtonConfig())
}
}
}
info

Replace yourApi.getFlexToken() with your actual backend API call that returns a Flex token. See the Installation page for details on token loading.

That's it! When the user taps the Split Rent Button, the checkout modal will open automatically.


Next Steps​

  • Customize the Checkout modal with interstitial settings and event handling
  • Style and configure the Split Rent Button
  • Review the full Installation guide for lifecycle management and error handling