iOS
The Trustly Lightbox SDK for iOS allows you to build a bank authorization workflow in your iOS app. Integrate the Select Bank Widget or the Trustly Lightbox to retrieve bank authorization data that can be used with other Trustly APIs.
To use an example project for testing and learning, see the Swift iOS Example App in GitHub.
If you need help with your integration, contact your Trustly representative or send your request to us.integrations@trustly.com.
Note: The examples provided here assume you’re using UIKit.
PayWithMyBank references are deprecated. If your app is using PayWithMyBank, you must change it to Trustly.
Prerequisites
Add the Trustly package
Add the Trustly package to your application to enable secure and convenient online bank payments.
CocoaPods
-
Open your project’s Podfile, or create one if it doesn’t exist.
-
Add the following line:
-
In Terminal, go to your project folder and run:
Swift Package Manager
-
Open your project in Xcode, and then click File > Add Package Dependencies.
-
Search for
trustly-iosor paste the following URL into the search field: -
Click Add Package and follow the prompts.
Manual
To install the Trustly package manually, see the ios-legacy documentation .
Set up OAuth support (Bank Login)
To support OAuth login flows, the Trustly Lightbox interacts with the ASWebAuthenticationSession class. In some cases it interacts with the customer’s mobile banking app directly. To support this functionality, your app must be configured to handle Universal Links so users are automatically returned to your app after authenticating with their bank. See Set up Universal Links for configuration steps.
If your app does not already have a Universal Link configured, you must set one up. Without it, users will not be automatically redirected to your app after logging in on a mobile banking app.
Define Establish Data with a Request Signature
To ensure communications between the Trustly Lightbox SDK and the Trustly API are secure, add a requestSignature authentication request to your iOS app to request the server access key before rendering the Select Bank Widget or Trustly Lightbox. Most of the information in the establishData property should be fetched or calculated dynamically. For example, customer information or unique order identifiers you want included in the merchantReference field. For example:
NOTE: When using the sandbox environment, set the
envproperty tosandbox. Before publishing your production application, remove theenvproperty.
For more information about generating a requestSignature, see Securing Requests.
For more information about properties, accepted values, and their behaviors, see Establish Data Object.
Display the Select Bank Widget
The Trustly Lightbox can be launched without using the Select Bank Widget. However, Trustly recommends rendering the Select Bank Widget for an optimal customer experience. For information about using the Select Bank Widget with the Trustly Lightbox, see Displaying the Bank Widget.
In your application, on the parent view implementation of viewDidLoad call the Trustly Lightbox SDKselectBankWidget function to initiate the Select Bank Widget view.
The following examples render the Select Bank Widget and then allow a customer to select their bank.
Launch the Lightbox
The Lightbox is launched by using the establishData parameter and the establish method. Customers activate the method by selecting a Checkout or a Continue button in your app. For example:
Handle the return from bank authentication
When the bank redirects back to your app via Universal Link, implement the handler in your SceneDelegate (iOS 13+) or AppDelegate (legacy) to notify the Lightbox SDK that the user has returned.
For a more comprehensive example of this logic, see the Trustly iOS example app.
Add callback functions
The Trustly Lightbox provides two callback functions to process terminal customer behaviors. When a customer successfully creates a bank authorization, the onReturn function is called. If the user exits the process at any time, or the authorization is otherwise unsuccessful, the onCancel function is called. For more information about these functions, see Redirect URLs.
Define two functions to handle these callbacks and pass them into the onReturn and onCancel parameters of the establish method. In the following examples, customer or Trustly app responses activate specific events:
Verify your server returns the correct Content-Type:
Add the Associated Domains entitlement
- Open your project in Xcode and select your application target.
- Go to Signing & Capabilities.
- Click + Capability and select Associated Domains.
- Add your domains, prefixed with
applinks::
Adding this capability automatically inserts the com.apple.developer.associated-domains key into your app’s entitlements file.
Implement the Universal Link handler
iOS delivers the Universal Link to your app via the scene(_:continue:) method in your SceneDelegate. Implement this method to extract the incoming URL and pass it to your routing logic:
For apps that support both Universal Links and legacy custom URL schemes during a migration period, see Migrate from custom schemes (iOS) for a unified router pattern that handles both link types through a single navigation flow.
Configure your deep link strategy (optional)
Universal Links function without a fallback. However, Trustly recommends having a default deep link strategy configured for your merchant account. This ensures your application has a consistent fallback behavior if a strategy isn’t explicitly provided within the establishData object in your code.
Any settings passed to the establishData object in your code override the default configurations stored in your Trustly account profile.
Because this setup requires internal configuration, you’ll need to contact your Customer Success Manager (CSM) or Trustly Support to enable this fallback for your account.
When you submit your request, you must provide the following information:
- Deep link strategy: Specify
deeplink-url. - Universal Link: Provide your fully qualified domain (for example,
https://yourdomain.com/).