iOS Integration

ℹ️

Version 4 documentation

You’re viewing documentation for Mobile SDK version 4.x.

Version 4 introduces a new architecture and currently supports card payments, Apple Pay, Google Pay, Alipay+, DIMOCO, EPS, Half Fare PLUS, iDEAL, Klarna, PayPal, PostFinance Pay, SEPA Direct Debit, and Twint.

We are actively working toward full feature parity with version 3.x, with additional payment methods and features planned for upcoming releases.

For full feature coverage, refer to the version 3.x documentation.


📘

SDK integration: Now with transactionId

To start using the iOS SDK, make sure your backend can generate a version 2 transactionId via the /v2/transactions init endpoint.

See our migration guide if you are migrating from Mobile SDK 3.x and transactions v1:

→ Mobile SDK 4 Migration Guide

Integration

Add the SDK to your iOS project as a Swift package using the GitHub repository github.com/datatrans/ios-sdk. In most projects, select all available packages. If you are building an App Clip, include only the packages required for your payment methods and flows. Contact support if you need help choosing the right packages.

Start the SDK with a transactionId obtained from your server-side init call. You can also pass additional options and saved payment methods for faster checkout flows by using the provided SavedPaymentMethod classes. The example below shows the minimum setup required to start a transaction on iOS. For additional initialization options, see the iOS SDK reference.

let transaction = Transaction(transactionId: transactionIdFromBackend)
transaction.delegate = self // you must implement your TransactionDelegate here
transaction.start(presentingController: yourCheckoutViewController)
// 1. Declare a transaction binding
@State private var transaction: Datatrans.Transaction?

// 2. Attach our datatrans modifier with the binding to a root view
var body: some View {
    ContentView()
        .datatrans(startWithTransaction: $transaction)
}

// 3. Configure a transaction, then assign it to trigger the payment
let trx = Datatrans.Transaction(transactionId: transactionIdFromBackend)
trx.delegate = self

transaction = trx
DTTransaction* transaction = [[DTTransaction alloc] initWithTransactionId:transactionIdFromBackend];
transaction.delegate = self;  // you must implement your TransactionDelegate here
[transaction startWithPresentingController:yourCheckoutViewController];

Info.plist file

To use card scanning in your iOS app, add a camera usage description to Info.plist. This text explains why your app requests camera access. If you omit it, the app can crash when the card scanner is opened.

If you support app-switch payment methods such as PostFinance Pay or Twint, add the required payment app schemes to LSApplicationQueriesSchemes in Info.plist. This lets your app detect and switch to the payment app during checkout.

#CameraUsage
Key    :  Privacy - Camera Usage Description   
Value  :  $(PRODUCT_NAME) requires camera access to scan cards.

#PostFinance Pay
Key    :  LSApplicationQueriesSchemes
Value  :  [ "postfinance-epayment" ]

#Twint
Key    :  LSApplicationQueriesSchemes
Value  :  [ "twint-extended", "twint-issuer1", "twint-issuer2", ... ]
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) requires camera access to scan cards.</string>
<key>LSApplicationQueriesSchemes</key>
<array>
	<string>postfinance-epayment</string>
	<string>twint-extended</string>
	<string>twint-issuer1</string>
	<string>twint-issuer2</string>
	<string>twint-issuer3</string>
	<string>twint-issuer4</string>
	<string>twint-issuer5</string>
	<string>twint-issuer6</string>
	<string>twint-issuer7</string>
	<string>twint-issuer8</string>
	<string>twint-issuer9</string>
	<string>twint-issuer10</string>
	<string>twint-issuer11</string>
	<string>twint-issuer12</string>
	<string>twint-issuer13</string>
	<string>twint-issuer14</string>
	<string>twint-issuer15</string>
	<string>twint-issuer16</string>
	<string>twint-issuer17</string>
	<string>twint-issuer18</string>
	<string>twint-issuer19</string>
	<string>twint-issuer20</string>
	<string>twint-issuer21</string>
	<string>twint-issuer22</string>
	<string>twint-issuer23</string>
	<string>twint-issuer24</string>
	<string>twint-issuer25</string>
	<string>twint-issuer26</string>
	<string>twint-issuer27</string>
	<string>twint-issuer28</string>
	<string>twint-issuer29</string>
	<string>twint-issuer30</string>
	<string>twint-issuer31</string>
	<string>twint-issuer32</string>
	<string>twint-issuer33</string>
	<string>twint-issuer34</string>
	<string>twint-issuer35</string>
	<string>twint-issuer36</string>
	<string>twint-issuer37</string>
	<string>twint-issuer38</string>
	<string>twint-issuer39</string>
</array>

Twint uses multiple URL schemes to support app switches to its various issuer apps. To ensure compatibility across iOS versions, the order of entries in LSApplicationQueriesSchemes in your Info.plist is important.

Add your schemes in the following order:

  1. Your own schemes and those required by other integrations (e.g. postfinance-epayment).
  2. twint-extended and twint-issuer1. These two schemes are mandatory.
  3. twint-issuer2 through twint-issuer14, in ascending order.
  4. Additional Twint issuer schemes (twint-issuer15, twint-issuer16, etc.) until you reach a total of 50 entries in your file.

We recommend making use of all available slots to support as many TWINT issuer apps as possible on older iOS versions.

📘

URL scheme limits on iOS

For apps built with Xcode 27 (iOS 27 SDK) or later, only the first 25 entries in LSApplicationQueriesSchemes are available on iOS 27. On earlier iOS versions, up to 50 entries remain available.

This is why the order of the schemes matters. Make sure that twint-extended and at least twint-issuer1 through twint-issuer14 are within the first 25 entries.

Additional requirements for iOS

Credit and debit cards

To enable native 3-D Secure flows for credit and debit card transactions, include ThreeDS_SDK when linking our SDK through Swift Package Manager. Then set TransactionOptions.appCallbackURL to a universal link and configure an associated domain for your app so users can return to it seamlessly after authentication. For setup details, see Apple’s documentation on how to set up an associated domain.

Apple Pay

To enable Apple Pay in your iOS project, create an Apple merchant identifier, upload the certificate in your Datatrans merchant settings, and enable the Apple Pay capability in Xcode. For the full setup steps, see Apple Pay via Mobile SDK.

PayPal

To correctly process PayPal transactions in your iOS project, make sure to include PayPal’s PPRiskMagnes component in Swift Package Manager when you link our SDK. Also configure the app callback scheme as described in the next section so the user can return to your app after authentication.

App-switch payment methods (Twint, PostFinance Pay, PayPal)

If you process Twint, PostFinance Pay, or PayPal, set your app callback scheme in the transaction options. This is required so the payment app can return users to your app.

options.appCallbackScheme = "your_scheme" // PayPal, PostFinance Pay, Twint
options.appCallbackURL = "https://yourdomain.com/app" // Card payments
options.appCallbackScheme = @"your_scheme"; // PayPal, PostFinance Pay, Twint
options.appCallbackURL = @"https://yourdomain.com/app"; // Card payments

After the transaction

After the transaction has been completed, your delegate's transactionDidFinish method will be invoked with transaction details, including the payment method and the token if one was created. If the transaction failed, transactionDidFail is invoked with error code and message. If the transaction was canceled by the user, transactionDidCancel will be invoked.

We also send the transaction result to your configured webhook. See Webhook for details.

Styling the SDK

You can specify an accent color that the SDK uses to highlight certain key interface elements, such as the card scan button and the Pay button.

transaction.theme.accentColor = UIColor.red
transaction.theme.accentColor = UIColor.redColor;

By default, the SDK uses a blue accent color, as shown below.