WebView
Add the Trustly UI to multi-platform apps with WebView
Add the Trustly UI to multi-platform apps with WebView
You can use a WebView to integrate the Lightbox in applications built with a multiplatform architecture and a web-based checkout flow.
For testing and learning, see the Trustly WebView Example application in GitHub.
If you need help with your integration, contact your Trustly representative or send your request to us.integrations@trustly.com.
Note: The Swift and Kotlin languages are shown as examples. For iOS and Android, see the example app repository.
Use JavaScript to initialize and display the Trustly Lightbox in the web content loaded by your WebView.
If your web page containing the Lightbox serves both web browser users and mobile app users, the default Lightbox web browser behavior does not function when the integrationContext="InAppBrowser" property is included. Trustly recommends adding the metadata properties dynamically. See the Trustly WebView Example app for an example implementation.
To load the Trustly JavaScript library, add a script tag to the <head> section of the web page that will be loaded in the WebView. For example:
Optional. In production environments, replace sandbox.trustly.one with trustly.one.
Replace REACT_APP_TRUSTLY_ACCESS_ID with your Trustly Access ID.
To initialize and launch the Lightbox, add a metadata object with the following properties to the establishData variable:
urlScheme - the URL you expect the user to return to after completing an OAuth or “App-to-App” user flow. For example,my_app://checkout/bank/oauth_successintegrationContext - one of InAppBrowser, InAppBrowserNotify, or ExternalBrowser. In order for OAuth to work in the manner described in this guide, the string InAppBrowser must be provided.For example:
Configure your app to to enable interaction between the WebView and the Lightbox web page. For example:
When a user selects a bank requiring OAuth, the Trustly Lightbox uses window.open() to navigate to a Trustly-hosted URL. Since WebView cannot open new windows like a regular browser, your app must handle this navigation.
Within your WebView, add a function to check for window navigation events to the Trustly URL.
Many banks consider WebViews an insecure method for accepting and authenticating user credentials. Following the completion of this step, when a customer opens the Trustly Lightbox and selects an OAuth-required bank, a secure in-app-browser layer opens over the Lightbox. This layer contains information about the selected bank and a button that a customer can select to authenticate with their bank’s mobile app or through the bank’s OAuth login web page. After a customer is successfully authenticated, they are directed back to your app.
For iOS, the secure in-app browser class ASWebAuthenticationSession is preferred. If you’re using iOS 12 or earlier, your app might need to support SFAuthenticationSession.
For Android, use Chrome Custom Tabs.
Add a function to open a secure in-app browser. For example:
The parameter callbackURL provides the destination to redirect the user to when the authentication session is complete. The value of this parameter must be identical to the urlScheme parameter that is passed into the establishData.metadata object when the Lightbox is launched.
Import the WebKit framework and display a web page for authentication. For example:
To complete the authentication process, you need to modify the buildASWebAuthenticationSession so that when the session is complete, the WebView calls the proceedToChooseAccount() method which is built in to the Trustly Lightbox. For example: