Type Alias ShoppingSession

ShoppingSession: {
    getShoppingSessionId: () => Promise<string>;
    submit: (data: SessionData) => Promise<void>;
    getInteroperabilityToken(): Promise<string>;
}

A Shopping Session represents a session in which a consumer is interacting with Klarna. A session can be created by partners via backend APIs using user_acount_token and passed down to the script tag when loading Web SDK.

<script src="https://js.klarna.com/web-sdk/v1/klarna.js" data-shopping-session-id="shopping-session-id"></script>

A session would be also created anonymously by Web SDK if no session is provided. The session can later become authenticated by the merchant by patching the session with an account linking token.

Type declaration

  • getShoppingSessionId: () => Promise<string>

    Get the session id

    // Retrieve the id from klarna.js
    const shoppingSessionId = await Klarna.Shopping.session().getShoppingSessionId()

    // Provide data from server-side
    PATCH https://api-global.klarna.com/v1/shopping/sessions/{shopping_session_id}
    {
    "supplementary_purchase_data": {
    "content": {
    "line_items": [{}],
    "shipping": [{}],
    }
    }
    }
  • submit: (data: SessionData) => Promise<void>

    Submit

    Submits pre-purchase related data for a sepcific session.

    document.getElementById('pay-with-klarna').addEventListener('click', async () => {
    await Klarna.Shopping.session().submit({ supplementaryData: {
    lineItems: []
    })
    })
  • getInteroperabilityToken:function
    • Allows partners to recieve an up to date Interoperability token that will be shared with Acquiring Partner once transaction process starts.

      Returns Promise<string>

      const interoperabilityToken = await Klarna.Shopping.session().getInteroperabilityToken()

      pspApi.initiatePayment({
      currency: "USD",
      amount: 100,
      paymentMethodOptions: {
      klarna: {
      interoperabilityToken: interoperabilityToken
      }
      }
      })