react-native-klarna-inapp-sdk
Advanced tools
Comparing version 2.2.2 to 2.2.3
@@ -43,3 +43,11 @@ "use strict"; | ||
if (this.props.onKlarnaMessage != null) { | ||
this.props.onKlarnaMessage(event.nativeEvent.klarnaMessageEvent); | ||
const klarnaMessageEvent = event.nativeEvent.klarnaMessageEvent; | ||
let params = {}; | ||
try { | ||
params = JSON.parse(klarnaMessageEvent.params); | ||
} catch (e) {} | ||
this.props.onKlarnaMessage({ | ||
action: klarnaMessageEvent.action, | ||
params: params | ||
}); | ||
} | ||
@@ -46,0 +54,0 @@ }, |
@@ -35,3 +35,11 @@ import React, { Component } from 'react'; | ||
if (this.props.onKlarnaMessage != null) { | ||
this.props.onKlarnaMessage(event.nativeEvent.klarnaMessageEvent); | ||
const klarnaMessageEvent = event.nativeEvent.klarnaMessageEvent; | ||
let params = {}; | ||
try { | ||
params = JSON.parse(klarnaMessageEvent.params); | ||
} catch (e) {} | ||
this.props.onKlarnaMessage({ | ||
action: klarnaMessageEvent.action, | ||
params: params | ||
}); | ||
} | ||
@@ -38,0 +46,0 @@ }, |
@@ -23,3 +23,3 @@ import React, { Component, type RefObject } from 'react'; | ||
} | ||
export interface KlarnaWebViewNativeEvent { | ||
interface KlarnaWebViewNativeEvent { | ||
readonly url: string; | ||
@@ -42,2 +42,5 @@ readonly loading: boolean; | ||
readonly action: string; | ||
readonly params: { | ||
[key: string]: any; | ||
}; | ||
} | ||
@@ -44,0 +47,0 @@ export interface KlarnaWebViewRenderProcessGoneEvent { |
@@ -15,3 +15,3 @@ import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes'; | ||
} | ||
export type KlarnaWebViewNavigationEvent = Readonly<{ | ||
type KlarnaWebViewNavigationEvent = Readonly<{ | ||
navigationEvent: Readonly<{ | ||
@@ -49,2 +49,3 @@ url: string; | ||
action: string; | ||
params: string; | ||
}>; | ||
@@ -51,0 +52,0 @@ }>; |
{ | ||
"name": "react-native-klarna-inapp-sdk", | ||
"title": "Klarna Mobile SDK React Native", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "This library wraps Klarna Mobile SDK and exposes its functionality as React Native components.", | ||
@@ -6,0 +6,0 @@ "main": "lib/commonjs/index", |
175
README.md
@@ -5,3 +5,3 @@ # Klarna Mobile SDK React Native | ||
[![React Native][dependency-badge]][dependency-url] | ||
[![Platforms][platforms-badge]][platforms-url] | ||
[![Platform][platform-badge]][platform-url] | ||
[![License][license-badge]][license-url] | ||
@@ -11,3 +11,5 @@ [![Developed at Klarna][klarna-badge]][klarna-url] | ||
This library wraps Klarna Mobile SDK and exposes its functionality as React Native components. It | ||
currently supports Klarna Payments via a Payment View component. | ||
currently has the following components: | ||
- `KlarnaPaymentView` to integrate Klarna Payments, | ||
- `KlarnaStandaloneWebView` to integrate Klarna Standalone WebView. | ||
@@ -18,3 +20,3 @@ This repository also includes a test application that you can use to see how it works. | ||
* [Android](https://github.com/klarna/klarna-mobile-sdk) | ||
* [Android](https://github.com/klarna/klarna-mobile-sdk-android) | ||
* [iOS](https://github.com/klarna/klarna-mobile-sdk) | ||
@@ -30,5 +32,3 @@ * [Flutter](https://github.com/klarna/klarna-mobile-sdk-flutter) | ||
* [Overview](https://docs.klarna.com/mobile-sdk/) | ||
* [Android](https://docs.klarna.com/mobile-sdk/android/) | ||
* [iOS](https://docs.klarna.com/mobile-sdk/ios/) | ||
* [React Native](https://docs.klarna.com/mobile-sdk/reactnative/) | ||
* [Using the Mobile SDK on React Native](https://docs.klarna.com/mobile-sdk/reactnative/) | ||
@@ -72,161 +72,2 @@ ## Getting started | ||
``` | ||
--- | ||
## Usage | ||
You can import the `KlarnaPaymentView` from the library. You'll then be able to add it as a | ||
component to your app. This component exposes callbacks as props and methods you can call via the | ||
component's ref. | ||
The view will self-size height-wise and grow it fill it containing view's width. | ||
### Props | ||
It has the following props: | ||
| Name | Type | Description | | ||
|-------------------------| --- |-------------------------------------------------------------------------------| | ||
| `category` | `String` | The payment method category you want to render in your view. | | ||
| `returnUrl` | `String` | An app-defined URL scheme the component uses to return customers to your app. | | ||
| `onInitialized` | `() => {}` | The initialize call completed. | | ||
| `onLoaded` | `() => {}` | The load call completed. | | ||
| `onLoadedPaymentReview` | `() => {}` | The load payment review call completed. | | ||
| `onAuthorized` | `(approved, authToken, finalizeRequired) => {}` | The authorize call completed. | | ||
| `onReauthorized` | `(approved, authToken) => {}` | The reauthorize call completed. | | ||
| `onFinalized` | `(approved, authToken) => {}` | The finalize call completed. | | ||
| `onError` | `(error) => {}` | An error occurred. | | ||
--- | ||
#### Return URL | ||
You can read more about how the return URL works and how to add it tou your iOS application [here](https://developers.klarna.com/documentation/in-app/ios/getting-started/#return-url) and for your Android application [here](https://developers.klarna.com/documentation/in-app/android/getting-started/#return-url). | ||
--- | ||
### Prop callback parameters | ||
--- | ||
#### approved: `boolean` | ||
Determines whether the previous operation was successful and yielded an authorization token. | ||
##### Available on: | ||
- `onAuthorized` | ||
- `onReauthorized` | ||
- `onFinalized` | ||
--- | ||
#### authToken: `string | null` | ||
If `authorize()`, `reauthorize()` or `finalize()` succeeded, they will return a token you can submit | ||
to your backend. | ||
##### Available on: | ||
- `onAuthorized` | ||
- `onReauthorized` | ||
- `onFinalized` | ||
--- | ||
#### finalizeRequired: `boolean | null` | ||
If `authorize()` requires that you additionally call `finalize()`, . | ||
##### Available on: | ||
- `onAuthorized` | ||
--- | ||
#### error: `KlarnaPaymentsSDKError` | ||
If a method failed, `onError()` will let you know via an error object. Contains `name`, `message`, | ||
`action`, `isFatal`, `sessionId` properties. | ||
##### Available on: | ||
- `onError` | ||
--- | ||
--- | ||
### View methods | ||
Each payment view exposes a set of methods via a view's ref. You can see in the test app or in the | ||
below example how these can be called. The methods are the following: | ||
--- | ||
#### initialize() | ||
Initializes the view with a session token. You have to have added the view to your application and | ||
supplied a payment method category. | ||
##### Parameters | ||
| Name | Type | Description | | ||
|---------|----------|--------------------------------------------------| | ||
| clientToken | `string` | The client token you get from Klarna Payments API. | | ||
--- | ||
#### load() | ||
Loads the view. This will render content in the view. | ||
##### Parameters | ||
| Name | Type | Description | | ||
| ---- |-----------------------|------------| | ||
| sessionData | `string \| undefined` | A JSON object with updated session data serialized into a string.| | ||
--- | ||
#### loadPaymentReview() | ||
Renders a description of the payment terms your customer has agreed to. | ||
Once a session is authorized, you can then either render a payment review in the existing | ||
payment view or `initialize()` a new payment view with the same session token and call this method. | ||
##### Note: | ||
This only works with specific payment methods and countries. | ||
--- | ||
#### authorize() | ||
Authorizes the payment session. | ||
##### Parameters | ||
| Name | Type | Description | | ||
| ---- |------------------------|----------------------------------------------------------------------| | ||
| autoFinalize | `boolean \| undefined` | A flag used to turn on/off auto-finalization for direct bank transfer. | | ||
| sessionData | `string \| undefined` | A JSON object with updated session data serialized into a string.| | ||
--- | ||
#### reauthorize() | ||
If the details of the session (e.g. cart contents, customer data) have changed, call this to update | ||
the session and get a new authorization token. | ||
##### Parameters | ||
| Name | Type | Description | | ||
| ---- |-----------------------| ----------- | | ||
| sessionData | `string \| undefined` | A JSON object with updated session data serialized into a string.| | ||
--- | ||
#### finalize() | ||
If a specific payment method needs you to trigger a second authorization, call finalize when you're | ||
ready. | ||
##### Parameters | ||
| Name | Type | Description | | ||
| ---- |-----------------------|------------| | ||
| sessionData | `String \| undefined` | A JSON object with updated session data serialized into a string.| | ||
--- | ||
## Support | ||
@@ -250,4 +91,4 @@ | ||
[dependency-url]: https://www.npmjs.com/package/react-native-klarna-inapp-sdk?activeTab=dependencies | ||
[platforms-badge]: https://img.shields.io/badge/platform-react%20native-lightgrey?style=flat-square | ||
[platforms-url]: https://reactnative.dev | ||
[platform-badge]: https://img.shields.io/badge/platform-React%20Native-lightgrey?style=flat-square | ||
[platform-url]: https://reactnative.dev | ||
[license-badge]: https://img.shields.io/github/license/klarna/react-native-klarna-inapp-sdk?style=flat-square | ||
@@ -254,0 +95,0 @@ [license-url]: https://github.com/klarna/react-native-klarna-inapp-sdk/blob/master/LICENSE |
@@ -21,3 +21,3 @@ import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes'; | ||
export type KlarnaWebViewNavigationEvent = Readonly<{ | ||
type KlarnaWebViewNavigationEvent = Readonly<{ | ||
navigationEvent: Readonly<{ | ||
@@ -58,4 +58,3 @@ url: string; | ||
action: string; | ||
// Dictionary is not supported for events | ||
// params: { [key: string]: any }; | ||
params: string; | ||
// TODO What is a KlarnaWebViewComponent? | ||
@@ -62,0 +61,0 @@ // component: KlarnaWebViewComponent; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1520
273673
92