Skip to main content

Quick Start

Get up and running with the Flex Checkout Android 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 to your app's build.gradle.kts:

Kotlin
dependencies {
implementation("com.github.flexapp:flex-checkout-android:1.7.0")
}

Add JitPack to your settings.gradle.kts:

Kotlin
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}

2. Add the Split Rent Button to Your Layout​

Add the FlexSplitRentButtonView to your Activity's layout XML. This pre-built button automatically opens the Flex Checkout flow when tapped.

XML
<!-- activity_main.xml -->
<com.flex.checkout.components.FlexSplitRentButtonView
android:id="@+id/splitRentButton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

3. Initialize the SDK​

Set up the SDK in your Activity's onCreate:

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.flex.checkout.Flex
import com.flex.checkout.configuration.FlexConfig
import com.flex.checkout.configuration.CheckoutConfig
import com.flex.checkout.configuration.SplitRentButtonConfig
import com.flex.checkout.events.ModalEventType
import com.flex.checkout.types.FlexEnvironment

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

// 1. Initialize the SDK.
val sdk = Flex.initialize(this, FlexConfig(
clientId = "your-flex-client-id",
environment = FlexEnvironment.INT // use FlexEnvironment.PROD for production
))

// 2. Register a token provider.
sdk.loadToken {
val response = yourApi.getFlexToken()
response.token
}

// 3. Configure checkout callbacks.
sdk.checkout(CheckoutConfig(
onOpen = { /* Checkout opened */ },
onClose = { /* Checkout closed */ },
onError = { error -> /* Handle error */ },
onEvent = { event ->
when (event.type) {
ModalEventType.ONBOARDING_COMPLETED -> {
// User completed onboarding.
// event.data.autopayEnabled indicates if autopay was set up.
}
ModalEventType.PAYMENT_COMPLETED -> {
// User completed payment.
}
}
},
))

// 4. Bind the Split Rent Button.
findViewById<com.flex.checkout.components.FlexSplitRentButtonView>(
R.id.splitRentButton
).bind(SplitRentButtonConfig())
}
}
info

Replace yourApi.getFlexToken() (Kotlin) or yourApi.getFlexTokenSync() (Java) 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, error handling, and ProGuard details