Migrate to the latest iOS SDK version

Update to the current most recent version of the iOS SDK, which is 4.0.1.

We recommend that you update your SDK to the newest version, which is version 4.0.1. This version includes a new, smoother user experience.

This new UI currently works for GBP payments and EUR payments in Ireland. Any payments authorised with the iOS SDK in those countries will automatically use the new UI, while payments elsewhere will fall back to the old UI. You cannot customise the colours of the new UI, but you can still pass customisation values to change the appearance of the old UI when it falls back.

An example of the new Mobile SDK UI on the end user’s side.

An example of the new Mobile SDK UI on the end user’s side.

The SDK now uses a single-screen, declarative, state-driven navigation system under the hood. If you previously relied on imperative navigation APIs like pushpop, and present to handle navigating to and from the iOS SDK, we strongly recommend that you re-test your implementation to ensure that nothing is broken when you migrate.

The deprecated .redirect success case has now been completely removed. This is a minor breaking change. Check that there are no compiler errors and update your implementation if needed.

Configure the SDK

Configure the SDK with the following:

await TrueLayer.Payments.manager.configure(environment: .sandbox)

Import the TrueLayer iOS SDK

Import the iOS SDK using import TrueLayerSDK.

Process a payment

Below is an example of the latest implementation for payment processing.

TrueLayer.Payments.manager.processSinglePayment(
  context: TrueLayer.Payments.Models.SinglePayment.Context(
    identifier: // Your payment ID,
    token: // Your resource token,
    redirectURL: // Your redirect URL,
    preferences: TrueLayer.Payments.Models.SinglePayment.Preferences(
        presentationStyle: .present(on: yourViewController, style: .automatic)
      )
  )) { result in
    switch result {
      case .success(let authorizationFlowResult):
        // Handle `AuthorizationFlowResult`. See below for the new handling logic.

      case .failure(let error):
        // Handle error. See below for the new handling logic.
    }
}

This is an example of how to process a mandate:

TrueLayer.Payments.manager.processMandate(
  context: TrueLayer.Payments.Models.Mandate.Context(
    identifier: // Your mandate ID,
    token: // Your resource token,
    redirectURL: // Your redirect URL
    preferences: // Your possible preferences like type of presentation and country code.
  )) { processResult in
    switch processResult.result {
      case .success(let success):
        // Handle `TrueLayer.Payments.Models.Mandate.State`.
        print(success.state)

      case .failure(let failure):
        // Handle `TrueLayer.Payments.Models.Mandate.Error`.
        print(failure.error)
    }

    // Handle `resultShown`.
    print(processResult.resultShown)
}

We recommend that you re-invoke processSinglePayment or processMandate once the user is redirected from their bank back to your application.

Preferences

The implementation of the Preferences object should look like this:

TrueLayer.Payments.Models.SinglePayment.Preferences(preferredCountryCode: "GB")

Retrieve a payment status

To retrieve a payment status, use the following:

TrueLayer.Payments.manager.singlePaymentStatus(paymentIdentifier: paymentIdentifier, resourceToken: resourceToken)

Some types that the SDK exposes have changed their name since version 1.x.x. This means that you may have to rename those types as well to compile the project. The full list of type changes is below.

  • TrueLayer.Payments.Models.SinglePayment.Context
  • TrueLayer.Payments.Models.SinglePayment.Preferences
  • TrueLayer.Payments.Models.SinglePayment.Status
  • TrueLayer.Payments.Models.SinglePayment.State
  • TrueLayer.Payments.Models.SinglePayment.Error

Handle the payment result

Result screen

In the Preferences object, shouldShowResultScreen is set to true by default. This tells the SDK to display the result of a payment or mandate at the end of the authorization flow. This screen automatically refreshes until either:

  • the payment is creditable
  • a maximum wait time is reached.
    You can customise what time this is by setting maximumResultScreenTimeout.

By default, this timeout happens after 10 seconds. This is also the maximum length of time that you can set in this field (inputting a higher value results in a 10-second wait time).

Some banks require further input from the user, such as one-time passwords and other SCA methods. The SDK displays screens to handle these inputs by default.

Success states

As of version 4.0.1, this is the full list of success states, alongside the events that each of them indicate. They display inside TrueLayer.Payments.Models.SinglePayment.State .

Note that there is no longer a redirect success state.

Success stateDescription
.authorizedThe user authorized the payment with the bank.
.executedThe bank confirmed the payment.
.settledThe funds have reached the destination.

Failure reasons

As of 4.0.1, this is the full list of failure reasons. They display inside TrueLayer.Payments.Models.SinglePayment.Error .

Failure reasonDescription
.authorizationFailedThe authorization process failed when the user tried to connect to their bank.
.connectionIssuesThere was an issue when connecting to the internet.
.genericA unexpected error. This error will be passed as a String parameter.
.invalidTokenThe token used to make the payment is not authorised to do so.
.invalidRedirectURIThe redirect URI passed to the SDK is invalid.
.paymentExpiredThe user took too long to complete the payment, so it expired.
.paymentNotFoundThe requested payment was not found.
.paymentRejectedThe payment was rejected by the bank.
.providerOfflineThe preselected provider was offline.
.sdkNotConfiguredThe SDK configure method has not been called before using it.
.serverErrorThe server encountered an error while processing the answer.
.blockedThe payment has been blocked due to a regulatory requirement. This may happen if your user fails a sanctions check.
.invalidAccountDetailsThe payment failed because either the remitter or beneficiary’s account details were invalid.
.invalidAccountHolderNameThe payment failed because the account holder name was invalid.
.invalidCredentialsThe credentials provided by the end user to log into their bank were incorrect.
.invalidRemitterAccountThe remitter’s account details were incorrect.
.invalidRequestThe payment failed due to invalid data in the request.
.invalidSortCodeThe end user provided an invalid sort code.
.insufficientFundsThe end user did not have the required balance in their account to complete this payment.
.notAuthorizedThe end user cancelled the payment or wasn't able to successfully authenticate on the provider's UI.
.paymentLimitExceededThe end user exceeded a payment limit with their bank.
.providerErrorThe provider unexpectedly failed when creating the payment.
.providerExpiredThe payment failed because the token or exchange code used to communicate with the bank expired.
.providerRejectedThe provider rejected the payment.
.unknownErrorThe payment failed for an unknown reason on the server side.
.userCanceledAtProviderThe payment failed because the user cancelled the authorisation during the payment flow.
.unexpectedBehaviorThe SDK encountered an unexpected behaviour.
.userCanceledThe user cancelled the payment.