Sign in with Klarna x Tokenized Payments

In this guide you will learn how to integrate Tokenized Payments in Sign in with Klarna into your Android app.

The flow will initiate when the scope contains payment:customer_present or payment:customer_not_present.
It also has a new callback KlarnaSignInTokenizationCallbackKlarnaSignInTokenizationCallback to be implemented by the client to provide the tokenization ID.
When the tokenization ID is valid, the process will proceed with the payment flow. However, if the tokenization ID is either invalid or not provided, the process will conclude with a successful sign-in flow.

The KlarnaSignInButtonKlarnaSignInButton now has a new callback called KlarnaSignInTokenizationCallbackKlarnaSignInTokenizationCallback that needs to be implemented. The callback implementation must provide the tokenization ID to the completion handler in order to continue the flow.

KOTLIN
class YourSignInTokenizationCallback : KlarnaSignInTokenizationCallback {

    override fun onTokenization(klarnaComponent: KlarnaComponent, completionHandler: (String) -> Unit) {
        // call your api here
        completionHandler("your-tokenization-id")
    }
}

While the user is interacting with the Sign in with Klarna flow or when the flow is completed, you'll receive events by setting an event handler when creating an instance of KlarnaSignInSDK. On the right you can see an example of how to implement such an event handler.

KOTLIN
val eventHandler = object : KlarnaEventHandler {
   override fun onEvent(klarnaComponent: KlarnaComponent, event: KlarnaProductEvent) {
      when(event.action) {
         KlarnaSignInEvent.USER_TAPPED_BUTTON -> {
            // User tapped the KlarnaSignInButton, auth process starting
         }
         KlarnaSignInEvent.USER_AUTH -> {
            // User completed interactive auth, tokens will be fetched
         }
         KlarnaSignInEvent.USER_CANCELLED -> {

Pass the KlarnaSignInTokenizationCallbackKlarnaSignInTokenizationCallback instance into the KlarnaSignInButtonKlarnaSignInButton constructor.

KOTLIN
//Create an instance of KlarnaSignInButton and pass the callback
val button = KlarnaSignInButton(... tokenizationCallback =  yourSignInTokenizationCallbackInstance)

To have Tokenized Payments with the Sign in with Klarna SDK in your Android app, you need to create an instance of KlarnaSignInSDK, call its signIn() function and pass the tokenizationId into its param.

KOTLIN
val sdk = KlarnaSignInSDK ...
sdk.signIn(
  ...
  tokenizationId = "Your-tokenization-id"
)

After calling the signIn() function you will receive the events in the event handler that you've passed to the SDK.