Klarna Web SDK v2/r6
    Preparing search index...

    Interface KlarnaIdentity

    Main interface to the Identity API

    <script type="module">
    const { KlarnaSDK } = await import("https://js.klarna.com/web-sdk/v2/klarna.mjs");

    const klarna = await KlarnaSDK({
    clientId: "klarna_live_client_elZGI1B5dHBIRWcjZrNldnbEVj...",
    });
    </script>

    This is the recommended and preferred method of integration

    const siwkButton = klarna.Identity.button({
    scope: "profile:name profile:email",
    redirectUri: "http://localhost:3000/callback",
    })

    siwkButton.mount('#container');
    siwkButton.on("render", async () => {
    // implement logic
    });

    siwkButton.on("click", async () => {
    // implement logic
    });

    klarna.Identity.on("signin", async (signinResponse) => {
    // implement logic
    });

    klarna.Identity.on("error", async (error) => {
    // implement error handling logic
    });
    siwkButton.unmount():
    
    <button id="merchants-custom-button">I am a custom button</button>
    
    const siwkButton = klarna.Identity.button({
    scope: "profile:name profile:email",
    redirectUri: "http://localhost:3000/callback",
    })

    siwkButton.attach('#merchants-custom-button');
    siwkButton.on("render", async () => {
    // implement logic
    });

    siwkButton.on("click", async () => {
    // implement logic
    });

    klarna.Identity.on("signin", async (signinResponse) => {
    // implement logic
    });

    klarna.Identity.on("error", async (error) => {
    // implement error handling logic
    });
    siwkButton.detach():
    

    If needed you can create multiple Identity Buttons

    const siwkButton = klarna.Identity.button({
    scope: "profile:name profile:email",
    redirectUri: "http://localhost:3000/callback",
    })

    siwkButton.mount("#container-1")

    // SECOND BUTTON RENDERED IN THE SAME PAGE
    const siwkButton2 = klarna.Identity.button({
    scope: "profile:name profile:email",
    redirectUri: "http://localhost:3000/callback",
    // Notice, for multiple buttons we need to provide an ID
    id: 'secondIdentityButton',
    })

    siwkButton2.mount("#container-2")


    // Cleanup
    siwkButton.unmount()
    siwkButton2.unmount()

    The Identity Button is responsive and you can adjust its size by specifying the width and height of the klarna-identity-button-custom-size class.

    .klarna-identity-button-custom-size {
    width: 335px; // min: 48px
    height: 48px; // min: 35px, max: 60 px
    }
    const tokenizationButton = klarna.Identity.button({
    scope: "payment:customer_present profile:name profile:email",
    redirectUri: "http://localhost:3000/callback",
    })

    This is required to be able to run the SIWK + Tokenization flow. We will use the information provided here to create a payment request.

    klarna.Identity.button({
    scope: "payment:customer_present profile:name profile:email",
    redirectUri: "http://localhost:3000/callback",
    paymentRequest: {
    amount: 1000,
    currency: "EUR",
    }
    })
    klarna.Identity.on("signin", async (signinResponse) => {
    // implement logic
    });
    interface KlarnaIdentity {
        button(id?: string): KlarnaIdentityButton;
        button(data: any): KlarnaIdentityButton;
        on(
            event: "signin",
            callback: (response: IdentitySignInResponse) => Promise<void>,
        ): void;
        on(event: "error", callback: (error: Error) => Promise<void>): void;
    }
    Index

    Methods

    Methods

    • Registers signin event handler.

      This event handler needs to be registered also on the redirect callback page to trigger handling redirect response.

      Parameters

      Returns void

    • Registers error event handler.

      Parameters

      • event: "error"
      • callback: (error: Error) => Promise<void>

      Returns void