Skip to content

Latest commit

 

History

History
143 lines (102 loc) · 6.94 KB

File metadata and controls

143 lines (102 loc) · 6.94 KB

Klarna Network Core SDK React Native

NPM React Native Platform License Developed at Klarna

Core package for React Native Klarna Network packages. This library wraps KlarnaNetworkCore sdk and provides the shared Klarna entry point, session management, and integration metadata used by other React Native Klarna Network packages:

  • KlarnaNetworkPayments React Native
  • KlarnaNetworkMessaging React Native
  • KlarnaNetworkIdentity React Native

New Architecture only (TurboModule).

Requirements

  • iOS 13 or later.
  • Android 5.0 (API 21) or later.
  • React Native 0.76.0 or later (New Architecture required).

Getting started

Add Dependency

NPM

npm install @klarna/react-native-klarna-network-core --save

Yarn

yarn add @klarna/react-native-klarna-network-core

Usage

Initialize

Call Klarna.initialize once at app startup before using any Klarna Network SDK.

import { Klarna } from '@klarna/react-native-klarna-network-core';

const klarna = await Klarna.initialize({
  clientId: 'your-client-id',
  appReturnUrl: 'your-app://return',
  // optional
  accountId: 'account-id',
  locale: 'en-US',
  klarnaNetworkSessionToken: 'token',
});

Session token

const token = await klarna.network.session.token();

// Clear the session when done
await klarna.network.session.clear();

Handle return URL (iOS only — deep link)

Call this from your deep-link handler to let the SDK process redirect callbacks.

const handled = await Klarna.handleReturnUrl(url);

Integration metadata

Optionally tag the integration for analytics and debugging:

klarna.setIntegrationMetadata({
  integrator: {
    name: 'MyApp',
    sessionReference: 'session-ref',
    moduleName: 'klarna-network-payment',
    moduleVersion: '1.0.0',
  },
});

API

Klarna

Method Signature Description
initialize (config: KlarnaConfiguration) => Promise<Klarna> Initializes the native SDK. Must be called before any other method.
handleReturnUrl (static) (url: string) => Promise<boolean> Processes a deep-link return URL (iOS only). Returns true if the SDK handled it.
getIntegrationMetadata () => KlarnaIntegrationMetadata | null Returns the currently set integration metadata.
setIntegrationMetadata (metadata: KlarnaIntegrationMetadata) => void Sets integration metadata on the native layer.
dispose () => Promise<void> Releases the native instance. Call when the SDK is no longer needed.

KlarnaConfiguration

Field Type Required Description
clientId string Yes Klarna client ID
appReturnUrl string Yes Deep-link URL scheme for OAuth redirects
accountId string No Klarna account ID
locale string No BCP 47 locale string (e.g. "en-US")
klarnaNetworkSessionToken string No Pre-existing session token

KlarnaNetworkSession

Method Signature Description
token () => Promise<string> Returns the active network session token
clear () => Promise<void> Clears the current session

Support

If you are having any issues using the SDK in your project or if you think that something is wrong with the SDK itself, please follow our support guide.

Contribution

If you want to contribute to this project please follow our contribution guide.

License

This project is licensed under Apache License, Version 2.0.