Skip to content

Kustom Checkout in an Android app

Add Kustom Checkout to an Android app with KustomMobileSDK — add the Gradle dependency, create a KustomCheckoutView in XML or code and handle its events.

For native and hybrid approaches, return URLs and migration from Klarna, see Kustom Checkout in a mobile app.

  • A server endpoint that returns a checkout snippet. Your backend creates the order with your API credentials and returns its html_snippet. Keep credentials out of the app. See Create an order. This guide calls the endpoint <YOUR-URL>.
  • A return URL. A custom URL scheme your app is registered for, such as myapp://. It brings the customer back after a payment method sends them to a third-party app. See the return URL.

Add the KustomMobileSDK Maven repositories and the dependency to your Gradle build:

repositories {
maven("https://x.kustomcdn.co/mobile-sdk/android/")
maven("https://x.klarnacdn.net/mobile-sdk/")
}
dependencies {
implementation("com.kustom.mobile.sdk:kustom-mobile-sdk:1.x.x")
}

The second repository is required because KustomMobileSDK still resolves shared artifacts from the Klarna Mobile SDK’s Maven host. Keep it until Kustom says otherwise.

Declare KustomCheckoutView in your layout or create it in code.

In XML. Declare the view with its environment, region and return URL:

<com.kustom.mobile.sdk.api.checkout.KustomCheckoutView
android:id="@+id/checkoutView"
app:kustomEnvironment="production"
app:kustomRegion="eu"
app:kustomReturnUrl="myapp://" />

Then look it up in your activity and attach an event handler (step 4):

val checkoutView: KustomCheckoutView = findViewById(R.id.checkoutView)
checkoutView.eventHandler = myEventHandler

In code. Create the view and set its theme:

val checkoutView = KustomCheckoutView(
activity = this,
returnURL = "myapp://",
eventHandler = myEventHandler,
environment = KustomEnvironment.PRODUCTION,
region = KustomRegion.EU,
theme = KustomTheme.LIGHT
)

Fetch the html_snippet from <YOUR-URL> and set it on the view:

checkoutView.setSnippet(snippet)

The event handler implements KustomEventHandler: onEvent receives product events and onError receives SDK errors. Act on each event by its action:

checkoutView.eventHandler = object : KustomEventHandler {
override fun onEvent(component: KustomComponent, event: KustomProductEvent) {
when (event.action) {
"complete" -> loadConfirmationSnippet(event.params["uri"])
"external" -> openExternalPayment(event.params["uri"])
"validation_error" -> handleValidationError(
event.params["error_type"],
event.params["error_text"],
)
}
}
override fun onError(component: KustomComponent, error: KustomMobileSDKError) {
Log.e(TAG, "Received error: ${error.name}. Message: ${error.message}")
}
}

The complete action means the customer has paid, and params["uri"] is the confirmation URL to load next. external carries the URL of an external payment method to send the customer to, and validation_error carries the error’s type and text. Events and errors lists every action and error field.

Point the app at a Playground order and run the flow end to end:

  1. The checkout renders after setSnippet.
  2. Paying with Playground test data dispatches a complete event carrying a uri.
  3. Your confirmation screen loads from that uri.
  4. Turning off the network mid-checkout produces an error in onError, with isFatal indicating whether checkout can continue.

If the view stays blank, check that <YOUR-URL> returned a snippet.

Pausing checkout during an order update. Call suspend() to block interaction before updating the order and resume() afterward:

checkoutView.suspend()
checkoutView.resume()

BankID doesn’t return the customer to your app. The customer may need to switch back manually after authentication.

This page is also available as Markdown — append .md to its URL — and is indexed in llms.txt.