Klarna Checkout integration to Capacitor.js for loading Checkout widget inside Capacitor app.
yarn add @foodello/capacitor-klarna-kco
or
npm install @foodello/capacitor-klarna-kco
Then run
npx cap sync
Required: Include configuration to capacitor.config.json
{
"plugins": {
"KlarnaKco": {
"iosReturnUrl": "your-app-scheme://",
"androidReturnUrl": "your-app-scheme://",
"environment": "playground", // Optional
"handleEPM": false, // Optional
"handleValidationErrors": false, // Optional
"region": "eu", // Optional
"theme": "light" // Optional
}
}
}
repositories {
....
maven {
url 'https://x.klarnacdn.net/mobile-sdk/'
}
}
ext {
...
klarnaSdkVersion: 'x.x.x'
}
Default is 2.5.2
capacitor.config.json
.
AndroidManifest.xml
:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="<your-app-scheme>" />
<data android:host="<your-app-host>" />
</intent-filter>
Note:
The hosting Activity should be using launchMode of singleTask or singleTop to prevent a new instance from being created when returning from an external application. This should be singleTask
if you have not modified this by yourself.
<activity android:launchMode="singleTask|singleTop">
Import plugin to your application
import { KlarnaKco } from "@foodello/capacitor-klarna-kco";
Remember to attach listeners to the events you are willing to handle. For example in order to perform navigation inside your application, listen complete
-event:
KlarnaKco.addListener('complete', ({ url }) => {/* PERFORM NAVIGATION */})
https://docs.klarna.com/in-app/
SetSnippetOptions
|
**Returns:** Promise<CallResult>
**Since:** 2.0.0
--------------------
### open()
```typescript
open() => PromisePromise<CallResult>
**Since:** 2.0.0
--------------------
### close()
```typescript
close() => PromisePromise<CallResult>
**Since:** 2.0.0
--------------------
### destroy()
```typescript
destroy() => PromisePromise<KlarnaCallResult>
**Since:** 1.0.0
--------------------
### suspend()
```typescript
suspend() => PromisePromise<KlarnaCallResult>
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.Complete, ...)
```typescript
addListener(eventName: EventsEnum.Complete, listenerFunc: (data: EventData[EventsEnum.Complete]) => void) => PromiseEventsEnum.Complete
|
| **`listenerFunc`** | (data: { url: string; path: string; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.External, ...)
```typescript
addListener(eventName: EventsEnum.External, listenerFunc: (data: EventData[EventsEnum.External]) => void) => PromiseEventsEnum.External
|
| **`listenerFunc`** | (data: { url: string; path: string; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 2.0.0
--------------------
### addListener(EventsEnum.Load, ...)
```typescript
addListener(eventName: EventsEnum.Load, listenerFunc: (data: EventData[EventsEnum.Load]) => void) => PromiseEventsEnum.Load
|
| **`listenerFunc`** | (data: { customer: { type: string; }; shipping_address: { country: string; postal_code: string; }; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.UserInteracted, ...)
```typescript
addListener(eventName: EventsEnum.UserInteracted, listenerFunc: (data: EventData[EventsEnum.UserInteracted]) => void) => PromiseEventsEnum.UserInteracted
|
| **`listenerFunc`** | (data: { type: string; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.Customer, ...)
```typescript
addListener(eventName: EventsEnum.Customer, listenerFunc: (data: EventData[EventsEnum.Customer]) => void) => PromiseEventsEnum.Customer
|
| **`listenerFunc`** | (data: { type: string; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.Change, ...)
```typescript
addListener(eventName: EventsEnum.Change, listenerFunc: (data: EventData[EventsEnum.Change]) => void) => PromiseEventsEnum.Change
|
| **`listenerFunc`** | (data: { email: string; postal_code: string; country: string; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.BillingAddressChange, ...)
```typescript
addListener(eventName: EventsEnum.BillingAddressChange, listenerFunc: (data: EventData[EventsEnum.BillingAddressChange]) => void) => PromiseEventsEnum.BillingAddressChange
|
| **`listenerFunc`** | (data: { postal_code: string; country: string; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.ShippingAddressChange, ...)
```typescript
addListener(eventName: EventsEnum.ShippingAddressChange, listenerFunc: (data: EventData[EventsEnum.ShippingAddressChange]) => void) => PromiseEventsEnum.ShippingAddressChange
|
| **`listenerFunc`** | (data: { postal_code: string; country: string; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.ShippingOptionChanged, ...)
```typescript
addListener(eventName: EventsEnum.ShippingOptionChanged, listenerFunc: (data: EventData[EventsEnum.ShippingOptionChanged]) => void) => PromiseEventsEnum.ShippingOptionChanged
|
| **`listenerFunc`** | (data: { description: string; id: string; name: string; price: number; promo: string; tax_amount: number; tax_rate: number; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.OrderTotalChange, ...)
```typescript
addListener(eventName: EventsEnum.OrderTotalChange, listenerFunc: (data: EventData[EventsEnum.OrderTotalChange]) => void) => PromiseEventsEnum.OrderTotalChange
|
| **`listenerFunc`** | (data: { order_total: number; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.CheckboxChange, ...)
```typescript
addListener(eventName: EventsEnum.CheckboxChange, listenerFunc: (data: EventData[EventsEnum.CheckboxChange]) => void) => PromiseEventsEnum.CheckboxChange
|
| **`listenerFunc`** | (data: { key: string; checked: boolean; }) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.NetworkError, ...)
```typescript
addListener(eventName: EventsEnum.NetworkError, listenerFunc: (data: EventData[EventsEnum.NetworkError]) => void) => PromiseEventsEnum.NetworkError
|
| **`listenerFunc`** | (data: Record<string, never>) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.RedirectInitiated, ...)
```typescript
addListener(eventName: EventsEnum.RedirectInitiated, listenerFunc: (data: EventData[EventsEnum.RedirectInitiated]) => void) => PromiseEventsEnum.RedirectInitiated
|
| **`listenerFunc`** | (data: true) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### addListener(EventsEnum.LoadConfirmation, ...)
```typescript
addListener(eventName: EventsEnum.LoadConfirmation, listenerFunc: (data: EventData[EventsEnum.LoadConfirmation]) => void) => PromiseEventsEnum.LoadConfirmation
|
| **`listenerFunc`** | (data: Record<string, never>) => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 1.0.0
--------------------
### Interfaces
#### CallResult
| Prop | Type | Description | Since |
| ------------- | -------------------- | -------------------------------------- | ----- |
| **`status`** | boolean
| Return status of the call | 2.0.0 |
| **`message`** | string
| Corresponding message for status value | 2.0.0 |
#### SetSnippetOptions
| Prop | Type | Description | Since |
| ------------- | ------------------- | ----------------------------------- | ----- |
| **`snippet`** | string
| The KCO frame's snippet from Klarna | 2.0.0 |
#### KlarnaCallResult
| Prop | Type |
| ------------ | ---------------------- |
| **`result`** | 'invoked'
|
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| **`remove`** | () => Promise<void>
|
### Enums
| Prop | Type |
| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| **`[EventsEnum.BillingAddressChange]`** | { postal_code: string; country: string; }
|
| **`[EventsEnum.Change]`** | { email: string; postal_code: string; country: string; }
|
| **`[EventsEnum.CheckboxChange]`** | { key: string; checked: boolean; }
|
| **`[EventsEnum.Complete]`** | { url: string; path: string; }
|
| **`[EventsEnum.Customer]`** | { type: string; }
|
| **`[EventsEnum.External]`** | { url: string; path: string; }
|
| **`[EventsEnum.LoadConfirmation]`** | Record<string, never>
|
| **`[EventsEnum.Load]`** | { customer: { type: string; }; shipping_address: { country: string; postal_code: string; }; }
|
| **`[EventsEnum.NetworkError]`** | Record<string, never>
|
| **`[EventsEnum.OrderTotalChange]`** | { order_total: number; }
|
| **`[EventsEnum.RedirectInitiated]`** | true
|
| **`[EventsEnum.ShippingAddressChange]`** | { postal_code: string; country: string; }
|
| **`[EventsEnum.ShippingAddressUpdateError]`** | Record<string, never>
|
| **`[EventsEnum.ShippingOptionChanged]`** | { description: string; id: string; name: string; price: number; promo: string; tax_amount: number; tax_rate: number; }
|
| **`[EventsEnum.UserInteracted]`** | { type: string; }
|
### Type Aliases
#### Record
Construct a type with a set of properties K of type T
{
[P in K]: T;
}
### Enums
#### EventsEnum
| Members | Value |
| -------------------------------- | -------------------------------------------- |
| **`BillingAddressChange`** | 'billing_address_change'
|
| **`Change`** | 'change'
|
| **`CheckboxChange`** | 'checkbox_change'
|
| **`Complete`** | 'complete'
|
| **`Customer`** | 'customer'
|
| **`External`** | 'external'
|
| **`Load`** | 'load'
|
| **`LoadConfirmation`** | 'load_confirmation'
|
| **`NetworkError`** | 'network_error'
|
| **`OrderTotalChange`** | 'order_total_change'
|
| **`RedirectInitiated`** | 'redirect_initiated'
|
| **`ShippingAddressChange`** | 'shipping_address_change'
|
| **`ShippingAddressUpdateError`** | 'shipping_address_update_error'
|
| **`ShippingOptionChanged`** | 'shipping_option_changed'
|
| **`UserInteracted`** | 'user_interacted'
|
Members | Value |
---|---|
Verbose |
verbose |
Error |
error |
Off |
off |
Members | Value |
---|---|
NA |
na |
OC |
oc |
EU |
eu |
Members | Value |
---|---|
Demo |
demo |
Playground |
playground |
Staging |
staging |
Production |
production |
Members | Value |
---|---|
Automatic |
automatic |
Dark |
dark |
Light |
light |