logo
Trustly Docs
BETA

iOS fallback methods

Updated 5 months ago
  1. Redirecting to the standalone browser

    • Implementation

    • Getting the user back your app

  2. In-app browser

    • Implementation


Our iOS SDK ensures the best user experience and support coverage. If you are unable to integrate our SDK, use one of the following fallback methods.

You can redirect to the Trustly URL in the device’s default browser. Redirecting to the default browser will ensure the best compatibility besides the SDK and proper handling of multi-factor authentication, app-to-app redirection, error handling etc.

With this option the attribute ReturnToAppURL should NOT be a part of the order initiation call since the transaction will be done outside of your application.

After order has been initiated towards Trustly API the returned url is opened in the users stand alone browser. This means that the user will be redirected out from your app to the device's default browser and ensure to provide a stable checkout session and a good user experience.

Example of order initation params
{
    ...
    "params": {
        ...
        "Data": { 
            ...
            "Attributes": {
                ...
                "ReturnToAppURL": null,
                "SuccessURL": "<URL-SCHEME> or <UNIVERSAL-APP-LINK>",
                "FailURL": "<URL-SCHEME> or <UNIVERSAL-APP-LINK>"
                ...


Swift example of opening Trustly URL in standalone browser
if let trustlyURL = URL(string: "<TRUSTLY-URL>") {
	UIApplication.shared.open(trustlyURL, options: [:])
}

Since this integration option results in the user being redirected out from your application, it's a good practice to also get the user back once the session reaches an end state (success or aborted).

To be able to redirect the user back to your app once the order reaches an end state, it's possible to initiate an order by inserting your custom URL scheme, or universal link/app link as values within the SuccessURL and FailURL attributes.

By doing this you ensure that the user will automatically be redirected back to where they started the Trustly order which will give a seamless user experience.

You can choose to embed Trustly Checkout within a in-app browser making use of a SFSafariViewController. This will ensure that the user stays within your app during the checkout session without needing to implement our SDK. Since technically SFSafariViewController is an instance of standalone Safari, we need you to pass additional query parameter so we can trigger the correct flow.

When presenting the Trustly checkout in a in-app browser, we need additional flags so that we can distinguish between standalone Safari and SFSafariViewController.

To achieve this, you simply need to append a query parameter IsNative to the Trustly Checkout URL you will receive from the Trustly API when initiating an order.

Code sample
import SafariServices
... 
if let checkoutUrlWithIsNative = URL(string: checkoutUrl + "&IsNative") {
  let safari = SFSafariViewController(url: checkoutUrlWithIsNative,configuration: SFSafariViewController.Configuration())
present(safari, animated: true, completion: nil)
}


If you want to enable automatic redirects back to your application and your in-app browser, please see the ReturnToAppURL parameter.