- Checkout
- Features
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.
Before you start
Section titled “Before you start”- 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.
Step by step
Section titled “Step by step”1. Add the SDK
Section titled “1. Add the SDK”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.
2. Create the checkout view
Section titled “2. Create the checkout view”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 = myEventHandlerIn 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)3. Set the snippet
Section titled “3. Set the snippet”Fetch the html_snippet from <YOUR-URL> and set it on the view:
checkoutView.setSnippet(snippet)4. Handle events and errors
Section titled “4. Handle events and errors”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.
Check that it works
Section titled “Check that it works”Point the app at a Playground order and run the flow end to end:
- The checkout renders after
setSnippet. - Paying with Playground test data dispatches a
completeevent carrying auri. - Your confirmation screen loads from that
uri. - Turning off the network mid-checkout produces an error in
onError, withisFatalindicating whether checkout can continue.
If the view stays blank, check that <YOUR-URL> returned a snippet.
Variations
Section titled “Variations”Pausing checkout during an order update. Call suspend() to block interaction before
updating the order and resume() afterward:
checkoutView.suspend()checkoutView.resume()Troubleshooting
Section titled “Troubleshooting”BankID doesn’t return the customer to your app. The customer may need to switch back manually after authentication.
Related
Section titled “Related”- Confirmation and push — what your server must do once
completefires - Create an order — the call behind
<YOUR-URL> - Kustom Checkout in a mobile app — native or hybrid, the return URL and migrating from the Klarna Mobile SDK
- iOS and React Native — the same integration on the other platforms
- Test data — Playground customers and cards to pay with
This page is also available as Markdown — append .md to its URL — and is indexed in llms.txt.