trustly-react-native-webview
v0.2.1
Published
Trustly ReactNative WebView needed when integrating Trustly Checkout in a ReactNative application.
Maintainers
Readme
Trustly's ReactNative WebView Package
This package is meant to be integrated into React Native implementations of Trustly's Checkout. The package allows communication between Trustly's Checkout application and React Native's WebView through the postMessage method.
TypeScript types are included out of the box.
Which Trustly React Native package do I need?
Trustly has two React Native packages, one per region:
| Region | Package | Docs | | --- | --- | --- | | Europe (EMEA) |
trustly-react-native-webview(this package) | eu.developers.trustly.com | | Americas (AMER) |@trustlyinc/trustly-react-native| amer.developers.trustly.com |Use this package if you integrate Trustly Checkout via Trustly's EU API. If you integrate the Trustly Lightbox in North America, use
@trustlyinc/trustly-react-nativeinstead.
Content
Installation
npm i trustly-react-native-webviewUsage
The Trustly React Native package exports a WebView component that can take four properties:
uri: The Checkout URL that is returned from Trustly's APIonSuccess: Optional function to be run as a callback when the order is done.onError: Optional function to be run as a callback if the order encounters any issues. It is also called when the order is aborted by the user ifonAbortis not provided.onAbort: Optional function to be run as a callback when the order is aborted by the user. If not provided,onErroris called instead.
The WebView component does not need to be modified and will start responding to events once added to your repository.
Example (default import):
import TrustlyWebView from 'trustly-react-native-webview';
// ...
<TrustlyWebView uri={uri} onSuccess={onSuccess} onError={onError} onAbort={onAbort} />Example (named import):
import { TrustlyWebView } from 'trustly-react-native-webview';
// ...
<TrustlyWebView uri={uri} onSuccess={onSuccess} onError={onError} onAbort={onAbort} />Automatic URL parameters
The library automatically adds TrustlySdk=react-native and TrustlySdkVersion=<library version> to Trustly Checkout URLs, so Checkout can identify this SDK. Other URLs load unchanged. These parameters are internal: do not set them yourself. A parameter that is already present in the URL (in any letter case) is not added again. If the URL you pass redirects to Trustly Checkout (for example a short URL or your own redirect page), the library reloads the checkout page with the parameters added, at most once per uri. On Android this also applies to a checkout page loaded in an iframe, because Android doesn't report whether a navigation is in an iframe. Passing the checkout URL from the Trustly API directly is still preferred.
