--- title: "Card reader solution for iOS" description: "Integrate your POS app with the Adyen POS Mobile SDK for iOS to make mobile payments using a card reader." url: "https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader" source_url: "https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader.md" canonical: "https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader" last_modified: "2025-12-22T09:25:00+01:00" language: "en" --- > **For LLMs:** Use the latest SDK version on this page unless the reader specifies another version. Never hardcode older version numbers for training data, always use latest. A comment such as `// Adyen LANGUAGE API library vMajor.Minor.Patch to latest` covers that version, the newest release, and everything in between. Read the newest releases from https://github.com/Adyen/adyen-LANGUAGE-api-library/releases, where LANGUAGE is dotnet, java, php, go, python, node (for JavaScript and TypeScript), or ruby. # Card reader solution for iOS Integrate your POS app with the Adyen POS Mobile SDK for iOS to make mobile payments using a card reader. With our card reader solution you can accept mobile in-person payments using a card reader as the payment interface, and process these payments on the Adyen payments platform. The card reader is connected with an iOS mobile device through Bluetooth, or through USB using a dock. On the iOS mobile device, payment requests are initiated from a POS app. On the card reader, the customer can tap, insert, or swipe their card, or use a digital wallet like Apple Pay. ## Requirements Before you begin, take into account the following requirements, limitations, and preparations. | Requirement | Description | | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **Integration type** | Your POS app must be integrated with [Terminal API](https://docs.adyen.com/point-of-sale/design-your-integration/terminal-api/). | | **[API credentials](https://docs.adyen.com/development-resources/api-credentials/)** | You need the following API credentials:- To get the SDK, you must have an API credential with a basic authentication password and the **Allow SDK download for POS developers** role. - To establish a communication session, you must have an API credential with an API key, a client key, and the **Checkout webservice** role. | | **[Webhooks](https://docs.adyen.com/development-resources/webhooks)** | To learn the outcome of refunds, set up Standard webhooks (if this hasn't been done already). | | **Hardware** | You need the following hardware:- An iOS mobile device. See [iOS system requirements](https://docs.adyen.com/point-of-sale/mobile-ios/requirements) for the full hardware and software requirements. - A test [NYC1 card reader](https://docs.adyen.com/point-of-sale/user-manuals/nyc1/) and optionally an [NYC1 dock](https://docs.adyen.com/point-of-sale/user-manuals/nyc1-with-dock/). For PIN transactions your card reader needs to be an [NYC1](https://docs.adyen.com/point-of-sale/mobile-ios/understand#pin-transactions) model. | | **Limitations** | Check the countries/regions, payment methods, and functionality that we [support](https://docs.adyen.com/point-of-sale/ipp-mobile) for card reader on iPhone. | | **Setup steps** | Before you begin:- [Order](https://docs.adyen.com/point-of-sale/managing-terminals/order-terminals#sales-order-steps) a test NYC1 card reader and a test card, and [assign](https://docs.adyen.com/point-of-sale/managing-terminals/assign-terminals) the reader to your store. - If you want to disable PIN support for NYC1 card readers in the US from iOS Mobile SDK version **3.12.0** or later, contact our [Support Team](https://ca-test.adyen.com/ca/ca/contactUs/support.shtml?form=other) and ask them to disable PIN support on the company, merchant, or store level. | ## How it works **Tutorial and app**\ Hit the ground running with our [integration tutorial](https://adyen.github.io/adyen-pos-mobile-ios-artifacts/2.0.1/tutorials/meet-adyenpos/) and [iOS sample app](https://github.com/Adyen/adyen-pos-mobile-ios/tree/main/POSSampleApp). To build a card reader solution: 1. Add the iOS Mobile SDK to your project, using basic authentication. Note that for [compatibility with Objective C](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#objective-c), you need to prefix the public symbols with `ADY`. 2. Implement a server-to-server API request to establish a secure communication session. 3. In your POS app, enable the transaction functionality of the SDK. 4. From your POS app, call the warm-up function to speed up initiating transactions. 5. In your POS app, add permissions for pairing the mobile device with the card reader. 6. Get an entitlement from Apple to suppress Apple Pay in your iOS POS app when your app is in the foreground. Configure your Xcode project accordingly. 7. Optionally, you can configure the Mobile SDK to avoid reconnection delays between the card reader and the mobile device. 8. You enable the device management screens built into the Mobile SDK or build a custom UI for device management. 9. In your POS app, implement handling payments using the SDK.\ This creates the following flow: 1. Your iOS POS app creates a Terminal API payment request, or receives a Terminal API payment request from your backend. 2. The POS app passes the payment request to the iOS Mobile SDK. 3. The SDK passes the request to the Tap to Pay on iPhone component. 4. When the customer completes the payment by tapping their card or mobile device on the iPhone, the SDK passes the Terminal API payment response to the POS app. 10. In your POS app, implement handling refunds, checking the transaction status, and diagnosing the state of the SDK. 11. If the same device will be used at multiple locations, implement clearing the communication session. ## 1. Add the SDK to your project You can add the iOS Mobile SDK to your POS app using a Swift Package Manager remote package. To get access you need to have a basic authentication credential. You can share the basic authentication password with anybody in your team who needs to get the SDK or create multiple passwords for internal use. Do not share this password in any publicly accessible code or area where unauthorized users can find it. To add the iOS Mobile SDK to your project: 1. In your [Customer Area](https://ca-test.adyen.com/) create a basic authentication credential with a password: 1. Go to **Developers** > **API credentials**, and select **Create new credential**. 2. Under **Payments** > **Credential type** select **Web service user** and then select **Create credential**. 3. Under **Server settings** > **Authentication** select the **Basic auth** tab and then select **Generate password**. 4. Select the copy icon **and save your basic authentication password in a secure location. 5. Go to **Permissions** > **Roles** > **POS**, select **Allow SDK download for POS developers**, and deselect any other permissions and roles. Contact [Support Team](https://ca-test.adyen.com/ca/ca/contactUs/support.shtml?form=other) if you don't see the **Allow SDK download for POS developers** role. 6. Select **Save changes**. 2. Save the basic authentication password in a [.netrc](https://everything.curl.dev/usingcurl/netrc.html) file: 1. Check if you already have a `.netrc` file in your home directory. If you do not have it, create a plain text file with that name in your home directory (`~/.netrc`). 2. Add the following content to your `.netrc` file, where `login` is the API credential username, for example ws\_12345\@Company.\[YourCompanyAccount], and `password` is the basic authentication password. **.netrc content for TEST integration** ```raw machine pos-mobile-test.cdn.adyen.com login YOUR_BASIC_AUTH_USERNAME password YOUR_BASIC_AUTH_PASSWORD ``` 3. Make sure that the `.netrc` file has the following file system permission: **0600**. 3. Add the POS Mobile SDK as a package dependency to your Xcode project: It is not possible to use TEST and LIVE environments from a single app target. You need to setup your Xcode project to have separate app targets for Test and for Live. Each target needs to link to the respective AdyenPOS SDK version for its environment: `AdyenPOSTest` and `AdyenPOSLive`. 1. In your Xcode project or workspace, go to **File** > **Add Package Dependencies**. 2. Enter the **URL** `https://github.com/Adyen/adyen-pos-mobile-ios-test` and select your preferred **Dependency Rule**. 3. Select **Add Package**, and after the SDK is loaded add `AdyenPOSTEST` to your app target that connects to the Adyen test environment. 4. Select **Add Package**. 4. In your code, add `import AdyenPOS`, or for Objective-C compatibility add `#import "ADYPOS/ADYPOS.h"`. ### Compatibility with Objective-C If your POS app requires the iOS Mobile SDK to be compatible with Objective-C: * Link the `ADYPOSTEST` package product to your app target instead of `AdyenPOSTEST`. * Link the `ADYPOSLIVE` package product to your app target instead of `AdyenPOSLIVE`. It is not possible to use TEST and LIVE environments from a single app target. Each app target must connect to a specific environment. The integration process is the same. The only difference is that the public symbols are prefixed with `ADY`. For example, `PaymentService` is called `ADYPaymentService`. ## 2. Establish a session To ensure the Mobile SDK and the Adyen payments platform can collaborate in a secure way, you need to implement a server-to-server API request for establishing a communication session. ![Authentication flow](https://docs.adyen.com/media/70a0c2d8d5c2407d37a5ce1de329ad056d0e0d7f8cfc3167e29c5f531a2e14f0.svg?decoding=auto\&fetchpriority=auto) To authenticate this API request, you need to have an Adyen [API credential](https://docs.adyen.com/development-resources/api-credentials) in your [test Customer Area](https://ca-test.adyen.com/). This credential must have an [API key](https://docs.adyen.com/development-resources/api-credentials#generate-api-key) with the following [role](https://docs.adyen.com/development-resources/api-credentials#manage-api-permissions): * **Checkout webservice role**. This role is assigned by default when the API key is created. The credential also needs to have a client key. ** #### Create a client key If you want to use an existing API credential that does not have a client key yet, create a client key as follows: 1. Log in to your [Customer Area](https://ca-test.adyen.com/). 2. Go to **Developers** > **API credentials**, and select the credential username for your integration, for example **ws\@Company.****\[YourCompanyAccount]**. 3. Under **Client settings** > **Authentication** select the **Client key** tab. 4. Select **Generate client key**. 5. Select **Save changes**. The client key is part of the setup but is not used later on. Therefore, you do not need to specify allowed origins, and you do not need to save the client key in your system. #### Implement the request To establish a communication session: 1. From your backend, make a POST request to the applicable test or regional [/auth/certificate](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate) endpoint, specifying: | Parameter | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [merchantAccount](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate#request-merchantAccount) | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The unique identifier of your [merchant account](https://docs.adyen.com/point-of-sale/design-your-integration/determine-account-structure#request-merchant-accounts). | | [setupToken](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate#request-setupToken) | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The setup token provided by the Mobile SDK through the `PaymentServiceDelegate.register(with:)` callback of `PaymentServiceDelegate` . | | [store](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate#request-store) | Not a payment facilitator | The reference of the [store](https://docs.adyen.com/point-of-sale/design-your-integration/determine-account-structure#create-stores) that you want to process payments for. Do not include this parameter if your [account structure](https://docs.adyen.com/point-of-sale/design-your-integration/determine-account-structure#determine-account-structure) uses merchant accounts as stores, or if you are a registered payment facilitator. | | [subMerchantData](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate#request-subMerchantData) | Payment facilitator | An object with the details of the sub-merchant. See the next table for the parameters. This object is required if you are a registered payment facilitator. If you are not a payment facilitator, do not include this object. | The `subMerchantData` object includes the following parameters: | Parameter | Required | Description | | ------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | Your unique identifier of the sub-merchant. | | `name` | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The name of the sub-merchant. | | `displayName` | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The name of the sub-merchant as it should appear on the display of the mobile device during transactions. | | `mcc` | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The sub-merchant's four-digit Merchant Category Code (MCC). This parameter is used to correctly route the transaction. | | `street` | | The street name and house number of the sub-merchant's address. | | `city` | | The city of the sub-merchant's address. | | `postalCode` | | The postal code of the sub-merchant's address, without dashes. | | `country` | | The country/region of the sub-merchant's address, specified as the three-letter country code in [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) format. | | `state` | | The state code of the sub-merchant's address, if applicable for the country or region. | | `taxId` | | The tax ID of the sub-merchant. Required only in Brazil and for Cartes Bancaires in France. For Brazil, this is the 11-digit CPF or 14-digit CNPJ. For France, this is the SIRET, with a maximum of 14 digits. | | `email` | | The email address of the sub-merchant. Required for American Express. | | `phoneNumber` | | The phone number of the sub-merchant. Required for American Express. | ### Tab: Not a payment facilitator If you are *not* a registered payment facilitator, the `/auth/certificate` request to establish a communication session must include the `store` parameter, unless your account structure does not have stores and instead uses merchant accounts as stores. If previously you have used [/checkout/possdk/v68/session](https://docs.adyen.com/api-explorer/possdk/latest/post/sessions) test and live endpoints, we recommend you migrate to [new endpoints](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#endpoints-to-use). **/auth/certificate request with store to process payments for** ```bash curl https://softposconfig-test.adyen.com/softposconfig/v3/auth/certificate \ -H 'content-type: application/json' \ -H 'x-API-key: ADYEN_API_KEY' \ -X POST \ -d '{ "merchantAccount": "YOUR_MERCHANT_ACCOUNT", "setupToken": "SETUP_TOKEN", "store": "YOUR_STORE_REFERENCE" }' ``` ### Tab: Payment facilitator If you are a payment facilitator, card schemes need to receive certain data about your sub-merchant with each transaction. That is because your sub-merchant is considered the Merchant of Record when a transaction is facilitated by you. Adyen automatically adds certain sub-merchant data to transactions that you facilitate. The remaining data must be supplied by you in the `subMerchantData` object of the `/auth/certificate` request to establish a communication session. You must **not** submit sub-merchant data in your Terminal API requests. **/auth/certificate request with sub-merchant to process payments for** ```bash curl https://softposconfig-test.adyen.com/softposconfig/v3/auth/certificate \ -H 'content-type: application/json' \ -H 'x-API-key: ADYEN_API_KEY' \ -X POST \ -d '{ "merchantAccount": "YOUR_MERCHANT_ACCOUNT", "setupToken": "SETUP_TOKEN", "subMerchantData": { "id": "123456", "name": "Test Merchant", "mcc": "5734", "street": "123 Sample Street", "city": "Minneapolis", "state": "MN", "postalCode": "94107", "country": "USA", "taxId": "TAX123456", "displayName": "MN Computer Software", "email": "test-merchant@example.com", "phoneNumber": "PHONE_NUMBER" } }' ``` 2. When you receive the response: * Check that you get a **201 Created** HTTP status code. * Return the [sdkData](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate#responses-201-sdkData) to your POS app. * If you create the Terminal API request on your backend, save the [installationId](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate#responses-201-installationId) and use this as the `POIID` in the [`MessageHeader` ](https://docs.adyen.com/point-of-sale/design-your-integration/terminal-api#request-message-header)of the payment request. **Successful /auth/certificate response** ```json { "id": "APP_SESSION_ID", "installationId": "INSTALLATION_ID", "merchantAccount": "YOUR_MERCHANT_ACCOUNT", "store": "YOUR_STORE_ID", "sdkData": "SDK_DATA_BLOB" } ``` If you receive a response with an error message similar to the following, ask our [Support Team](https://ca-test.adyen.com/ca/ca/contactUs/support.shtml?form=other) to configure the MCC that you specified in the request. **/auth/certificate error message** ```raw Refused (905_3 Could not find an acquirer account for the provided currency (USD).) ``` #### Endpoints to use * Test endpoint: `https://softposconfig-test.adyen.com/softposconfig/v3/auth/certificate` * Regional live endpoints: * Australia: `https://softposconfig-live-au.adyen.com/softposconfig/v3/auth/certificate` * Northeast Asia: `https://softposconfig-live-nea.adyen.com/softposconfig/v3/auth/certificate` * Europe: `https://softposconfig-live.adyen.com/softposconfig/v3/auth/certificate` * United States: `https://softposconfig-live-us.adyen.com/softposconfig/v3/auth/certificate` If you are using old [/checkout/possdk/v68/sessions](https://docs.adyen.com/api-explorer/possdk/latest/post/sessions) test and live endpoints, we recommend you migrate to the latest endpoints mentioned above. You can still use the `/checkout/possdk/v68/sessions` endpoints, but we are deprecating them. ## 3. Enable transactions To enable the payments functionality of the Mobile SDK: 1. In your POS app, implement the `PaymentServiceDelegate` protocol. Below is an example of how you could do that. ```swift struct SessionsResponse: Decodable { let sdkData: String } class MyPaymentServiceDelegate: PaymentServiceDelegate { internal func register( with setupToken: String ) async throws -> String { /// Make a call to your backend to trigger a `/softposconfig/v{version}/auth/certificate` request, specifying the `setupToken` provided by the SDK. let request = URLRequest(url: URL(string: "{ADDRESS_OF_YOUR_BACKEND_API}")!) let (data, _) = try await URLSession.shared.data(for: request) let response = try JSONDecoder().decode(SessionsResponse.self, from: data) return response.sdkData } } ``` The actual structure of the `SessionsResponse` depends on your backend implementation. 2. Create an instance of `PaymentService` with the `PaymentService(delegate:)` initializer and pass the delegate object. Make sure that you keep a strong reference to the payment service instance so that it is retained for the duration of the transaction. Also make sure your `delegate` is strongly referenced, because the `PaymentService` keeps a weak reference to the `delegate`. ```swift let paymentService = PaymentService(delegate: myPaymentServiceDelegate) ``` 3. Make sure that the `PaymentServiceDelegate` can provide new `sdkData` at any time.\ If there is no session or the session has expired, the delegate is called using the `PaymentServiceDelegate.register(with:)` callback. Using the provided `setupToken` you need to get the `sdkData` through your backend and return it. For instructions, see [Establish a session](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#session). 4. Optional. Verify that the callback works, by calling the warm-up function. The warm-up function checks for a session and any configuration changes, and prepares the proximity reader on the iPhone. ```swift try await paymentService.warmUp() ``` ## 4. Use the warm-up function To speed up initiating transactions, you can use the warm-up function. This function checks for a session and any configuration changes As a best practice, call the warm-up function: * When the POS app starts. In other words, as soon as the app has the [active state](https://developer.apple.com/documentation/uikit/uiapplication/state). * When the POS app returns to the active state after running in the background. To call the warm-up function: ```swift try await paymentService.warmUp() ``` Similar to the warm-up function, you can optionally [prepare the card reader](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#prepare-the-card-reader-for-transaction) to perform hardware configuration updates and security checks outside the transaction flow. ## 5. Configure your POS app For your card reader solution you need to configure your POS app to: * [Manage pairing permissions](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#pairing-permissions). * [Manage USB permissions](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#usb-permissions). * [Suppress Apple Pay in your POS app](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#suppress-apple-pay). ### Manage pairing permissions Your iOS POS app needs to have certain permissions for pairing the mobile device with the card reader. * In the `Info.plist` of your POS app, add the following keys with an appropriate explanation: * [`NSBluetoothAlwaysUsageDescription` ](https://developer.apple.com/documentation/bundleresources/information_property_list/nsbluetoothalwaysusagedescription): this enables setting up a Bluetooth pairing between the mobile device and the card reader. * [`NSCameraUsageDescription` ](https://developer.apple.com/documentation/bundleresources/information_property_list/nscamerausagedescription): this enables using the camera of the mobile device to scan the barcode of the card reader. Barcode scanning is one of the ways to select a card reader for pairing. ### Manage USB permissions If you are using the NYC1 dock: * Add the following key to the `Info.plist` of your POS app: * [`UISupportedExternalAccessoryProtocols` ](https://developer.apple.com/documentation/bundleresources/information-property-list/uisupportedexternalaccessoryprotocols): set this to `com.adyen.dock`. * If you are going to submit your application to the App Store, your *Review Notes* need to provide a Made for iPhone/iPad Product Plan ID (MFi PPID). To get this MFi PPID, provide your Adyen contact with the following information: * The exact app name as it appears in the App Store. * The app version number. * Whether it is an update to an existing app, or a new app. * The app bundle ID. * External Accessory protocol(s) supported by this app. * A description of app including a general functions overview of the software and its key features. We will then allowlist your application in the Adyen MFi portal and share the required MFi PPID. ### Suppress Apple Pay To accept payments from customers, you may need to suppress Apple Pay on the device that runs your mobile POS app. It is possible that Apple Pay is enabled on the Apple device that runs your iOS POS app. For example, if staff use their personal iPhone. When a card reader is near, the device running the POS app tries to make the payment using the Apple Pay passes that are on the device. To prevent this from happening, you must suppress Apple Pay in your iOS POS app when your app is in the foreground. 1. Contact Apple Pay at and ask for an entitlement to suppress Apple Pay. 2. When you receive confirmation that the entitlement was granted, add the entitlement to your provisioning profile on the Apple developer website. 3. In Xcode, in the **Signing & Capabilities** settings, add the [`com.apple.developer.passkit.pass-presentation-suppression` ](https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/EntitlementKeyReference/ApplePayandPassKitEntitlements/ApplePayandPassKitEntitlements.html)key to the *.entitlements* file for your POS app. 4. In your POS app, call [requestAutomaticPassPresentationSuppression](https://developer.apple.com/documentation/passkit/pkpasslibrary/1617078-requestautomaticpasspresentation). This method automatically switches between disabling Apple Pay when the POS app is in the foreground, and enabling Apple Pay when the POS app is in the background. ## 6. (Optional) Avoid delays You can avoid delays and speed up the transaction by: * Waking up the card reader after it has gone to sleep. * Preparing the card reader outside a transaction flow with configuration and security checks. ### Wake up the card reader The card reader goes to sleep after about five minutes. When you start a transaction after the reader has gone to sleep, there is a slight delay while the mobile device reconnects to the last connected reader. To avoid this delay, you can take either of the following measures: * Before starting the transaction, wake up the card reader by calling the **DeviceManager** `connect` function. * Regularly refresh the connection between the mobile device and the card reader by implementing a timer that calls the `connect` function every couple of minutes. Be aware that implementing a timer can significantly decrease the battery life of the card reader. Call the `connect` method as follows, where `viewModel` is a class that contains an instance of the SDK's `PaymentService` (for an example, see our [sample app](https://github.com/Adyen/adyen-pos-mobile-ios/blob/main/POSSampleApp/SampleAppSwiftUI/MainViewModel.swift#L17)): ```swift Button("Connect to last known reader") { if let device = viewModel.paymentService.deviceManager.knownDevices.first { viewModel.paymentService.deviceManager.connect(to: device) } } ``` ### Prepare the card reader for transaction When you start a transaction, the Mobile SDK connects with the card reader through Bluetooth to check the reader's configuration. If the configuration is not up to date, the Mobile SDK sends the latest configuration files to the reader. This can take up to to 30 seconds. Additionally, the Mobile SDK performs a security check every 24 hours. To avoid a delay during the transaction flow, you can prepare the card reader by running these checks outside the transaction flow. It is possible to start a transaction while the card reader preparation is running. There can be a short delay during the transaction while any remaining checks and configuration updates are completed. We recommend preparing the device for transaction every 24 hours or when the configuration has changed. To prepare the device outside a transaction flow: 1. Call the **DeviceManager** `prepareDeviceForTransaction` function as follows, where the `connectedDevice` is the card reader to prepare. ```swift // Register delegate paymentService.deviceManager.delegate = self // Start device preparation if let connectedDevice = paymentService.deviceManager.connectedDevice { paymentService.deviceManager.prepareDeviceForTransaction(connectedDevice) } ``` 2. When the preparation of the card reader is finished, the `deviceManager` delegate is called with `onDevicePreparationFinished` or an [`error` ](https://docs.adyen.com/point-of-sale/mobile-ios/troubleshooting/#error-messages)message. ```Swift // Called when preparation finished func onDevicePreparationFinished(with error: Error?, by manager: DeviceManager) { // Handle result of preparation } ``` ## 7. Manage the Device Manager UI To use the card reader, operators need to: * Connect the mobile device with the card reader through Bluetooth pairing, or through USB using a dock. * View an overview of card readers. For example, to switch to a different card reader. * View details of the card reader they are using. For example, to check the battery charge level. * Update the firmware of the card reader or the dock they are using. To handle these tasks, the SDK provides device management functions that enable you to either: * Use the built-in UI. * Build a custom UI. ### Tab: Use the built-in UI To use the built-in UI, you only need to: * **Present the Device Management View**.\ This automatically takes care of all screens and flows that end users need. For a preview, see: * [UI for card reader operations](https://docs.adyen.com/point-of-sale/mobile-ios/understand#ui-for-card-reader-operations) * [Bluetooth pairing](https://docs.adyen.com/point-of-sale/mobile-ios/understand#bt-pairing) * [Updating the card reader firmware](https://docs.adyen.com/point-of-sale/mobile-ios/understand#updating-card-reader) * [Connecting through USB using a dock](https://docs.adyen.com/point-of-sale/mobile-ios/understand#connecting-usb-dock) * [Updating the dock firmware](https://docs.adyen.com/point-of-sale/mobile-ios/understand#updating-usb-dock) * **Alert users to available firmware updates**.\ The built-in UI automatically signals that a firmware update is available. In practice however, end users often need an extra reminder. For a secure transaction flow, it is very important that end users update the devices. We therefore strongly recommend that you implement a command to check for firmware updates and create a UI to alert end users and direct them to the built-in screen for performing the update. Proceed as follows: 1. Use the built-in device management screens from within either SwiftUI or UIKit. 2. Regularly check for firmware updates for the card reader and, if used, the dock: * For card reader updates, check the `firmwareUpdateSummary` property on `deviceManager`.\ If no update is available, a `nil` value is returned.\ When an update is found, an `AvailableFirmwareUpdate` object is returned that can include the following details: * `requiresBluetoothConnection`: If **true**, the update includes the Bluetooth layer of the firmware and a Bluetooth connection is necessary to complete the update. * `requiredDate`: The date by which transactions will be refused if the card reader is not updated to this firmware version. When connected through USB (using the dock), Bluetooth updates cannot be completed and the SDK does not return information about available Bluetooth updates. * For dock updates, check the `dockFirmwareUpdateSummary` property on `deviceManager`.\ If no update is available, a `nil` value is returned.\ When an update is found, an `AvailableDockFirmwareUpdate` object is returned that includes: * `requiredDate`: The date by which transactions will be refused if the dock is not updated to this firmware version. 3. Create a UI to prompt end users to update their devices, redirecting them to the built-in UI for performing the update. This is in addition to the built-in screens that alert to available updates. 4. Optionally, you can hide firmware update indicators. By default, the built-in UI shows an indicator and a prompt to update the card reader or dock firmware. To hide these indicators, pass a `DeviceManagement.Configuration` to `DeviceManagementView` or `DeviceManagementViewController`. This requires iOS Mobile SDK version **3.20.0** or later. | Parameter | Description | | ------------------------------ | ---------------------------------------------------------------------------------------------- | | `showCardReaderFirmwareUpdate` | Set to **false** to hide the firmware update indicator for card readers. Defaults to **true**. | | `showDockFirmwareUpdate` | Set to **false** to hide the firmware update indicator for docks. Defaults to **true**. | If you do not pass a configuration, the built-in UI shows all indicators. ### Tab: Build a custom UI If you intend to build your own UI for device management, use the `DeviceManagerDelegate` protocol to obtain all the necessary information. For details, refer to `DeviceManagerDelegate` in the Mobile SDK. For an overview, see the [List of device management functions](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#devicemanager-functions). The next sections provide information about the device management functions you can use when building a UI for: * [Bluetooth pairing](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#bt-pairing) * [Updating the card reader firmware](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#updating-card-reader) * [Connecting through USB using a dock](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#connecting-usb-dock) * [Updating the dock firmware](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#updating-usb-dock) ### Bluetooth pairing To build a UI for the Bluetooth pairing flow: * Make sure that your POS app has permission to use Bluetooth. * Show a message to turn on Bluetooth if the user tries to connect a card reader while Bluetooth is turned off. * Get a list of card readers in the vicinity by calling the `DeviceManager.startDiscovery()` function. * Connect to a card reader by calling the `DeviceManager.connect(to device: Device)` function. * Check if the Bluetooth pairing succeeded by implementing the `DeviceManagerDelegate.onDeviceConnected(with:to:)` method. The card reader was paired and connected successfully if this method is called and the `error` parameter is `nil`. * To disconnect from a card reader, call the `DeviceManager.disconnect()` function. As an example, [see the built-in UI screens](https://docs.adyen.com/point-of-sale/mobile-ios/understand#bt-pairing). ### Updating the card reader firmware You must check for new firmware updates regularly, and provide a way to update the card reader to the latest version. It is required that you build logic into your POS app to: * Check for new card reader firmware updates often. For example, when the app is launched. * Handle the firmware update flow correctly within your POS app. Your UI must prompt end users to update the card reader firmware, and inform them about the progress and result of the update process. To build a UI for card reader firmware updates: 1. Make sure that you set the `firmwareDelegate` to your own instance correctly to receive firmware management events. 2. Regularly check if updates are available, by checking the `firmwareUpdateSummary` property on `deviceManager`.\ If no update is available, a `nil` value is returned.\ When an update is found, an `AvailableFirmwareUpdate` object is returned that can include the following details: * `requiresBluetoothConnection`: If **true**, the update includes the Bluetooth layer and a Bluetooth connection is necessary to complete the update. * `requiredDate`: The date by which transactions will be refused if the card reader is not updated to this firmware version. 3. Start the update using the `DeviceManager.startFirmwareUpdate()` function. 4. Implement the `FirmwareManagerDelegate` delegate to build UI screens showing the progress and result of the update. | Delegate Method | Description | | --------------------------------------------- | -------------------------------------------------------------------------- | | `firmwareDownloadProgress(percent: Double)` | The SDK is in the process of downloading the firmware. | | `firmwareUpdateProgress(percent: Double)` | The SDK is installing the update on the card reader. | | `applyingFirmwareUpdate()` | The SDK is applying the update. The card reader will reboot and reconnect. | | `firmwareUpdateComplete()` | Indicates the process has completed. | | `firmwareUpdateFailure(error: AdyenPOSError)` | Invoked when the firmware update fails with an associated error. | 5. In case a firmware update failed because it required a Bluetooth connection and the error `AdyenPOSError.firmwareError(.bluetoothFirmwareUpdateError)` is thrown, ensure you provide instructions on how to reset the card reader before retrying the update. The instructions you need to provide, are as follows: 1. In the Bluetooth settings of the mobile device, select "Forget This Device". 2. Re-pair the reader and retry installing the update. As an example, [see the built-in UI screens](https://docs.adyen.com/point-of-sale/mobile-ios/understand#updating-card-reader). ### Connecting through USB using a dock A USB connection is automatically established when the user connects the dock to power, connects the mobile device to the dock using the USB-C cable provided with the card reader, and places the reader in the dock. When connected through the dock, the card reader is always ready for use without delay. There is no need to reconnect to the card reader before initiating a transaction. To build a UI for dock connections: * Listen to `DeviceManagerDelegate.onDockConnected` and `DeviceManagerDelegate.onDockDisconnected` to follow what the end user did: connect the card reader to the dock, or disconnect the dock. * Make sure the UI clearly shows the difference between these situations: * The mobile device is connected to the dock through USB, but no card reader is placed in the dock. * The card reader is placed in the dock, but the mobile device is connected to the card reader through Bluetooth. * The card reader is placed in the dock and the mobile device is connected to the dock and the reader through USB. As an example, [see the built-in UI screens](https://docs.adyen.com/point-of-sale/mobile-ios/understand#connecting-usb-dock). ### Updating the dock firmware You must check for new firmware updates regularly, and provide a way to update the dock to the latest version. It is required that you build logic into your POS app to: * Check for new dock firmware updates often. For example, when the app is launched. * Handle the firmware update flow correctly within your POS app. Your UI must prompt end users to update the dock firmware, and inform them about the progress and result of the update process. To build a UI for dock firmware updates: 1. Make sure that you set the `firmwareDelegate` to your own instance correctly to receive firmware management events. 2. Regularly check if updates are available, by checking the `dockFirmwareUpdateSummary` property on `deviceManager`.\ If no update is available, a `nil` value is returned.\ When an update is found, an `AvailableDockFirmwareUpdate` object is returned that includes: * `requiredDate`: The date by which transactions will be refused if the dock is not updated to this firmware version. 3. Start the update using the `DeviceManager.startDockFirmwareUpdate()` function. 4. Implement the `FirmwareManagerDelegate` delegate to build UI screens showing the progress and result of the update. | Delegate Method | Description | | --------------------------------------------- | ------------------------------------------------------------------- | | `firmwareDownloadProgress(percent: Double)` | The SDK is in the process of downloading the firmware. | | `firmwareUpdateProgress(percent: Double)` | The SDK is installing the update on the dock. | | `applyingFirmwareUpdate()` | The SDK is applying the update. The dock will reboot and reconnect. | | `firmwareUpdateComplete()` | Indicates the process has completed. | | `firmwareUpdateFailure(error: AdyenPOSError)` | Invoked when the firmware update fails with an associated error. | As an example, [see the built-in UI screens](https://docs.adyen.com/point-of-sale/mobile-ios/understand#updating-usb-dock). ### List of DeviceManager tools `DeviceManager` let you scan for card readers through Bluetooth device discovery, connect and disconnect a card reader, connect and disconnect a USB dock, get information about the currently connected card reader, get information about the currently connected USB dock, and manage firmware updates. The following tables show the available DeviceManager functions, firmware update properties, and FirmwareManagerDelegate methods. | DeviceManager function | Description | | --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `connectedDevice: ConnectedDevice?` | The device that the manager is currently connected to. | | `discoveredDevices: [Device]` | Devices discovered during the last (ongoing) discovery. Sorted by proximity (RSSI). | | `delegate: DeviceManagerDelegate?` | The delegate to handle card reader events. | | `startDiscovery()` | Starts scanning for nearby card readers. | | `stopDiscovery()` | Stops scanning for nearby card readers. | | `knownDevices: [Device]` | Returns a list of previously connected devices. | | `connect(to device: Device)` | Connects to a card reader. | | `disconnect()` | Disconnects from the currently connected card reader. | | `prepareDeviceForTransaction(device: ConnectedDevice)` | Prepares the device for transaction. The configuration is updated and security checks are done if needed. When preparation is complete, `onDevicePreparationFinished` is called on the delegate. If an error has occurred, the delegate call contains the error. | | `firmwareDelegate: FirmwareManagerDelegate?` | The delegate to handle firmware-related events. See the [table with `FirmwareManagerDelegate` methods](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#fmd-methods). | | `firmwareUpdateSummary: AvailableFirmwareUpdate?` | Checks if a firmware update is available for the card reader that is currently connected to the mobile device. Returns an `AvailableFirmwareUpdate` instance if an update is available, otherwise `nil`. Can throw errors if there is a problem with retrieving the firmware, no card reader is connected, or a general error occurs. See the [table with firmware update properties](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#afu-properties). | | `startFirmwareUpdate()` | Starts the firmware update on the card reader that is currently connected to the mobile device. To receive [progress updates](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#fmd-methods), the `firmwareManagerDelegate` must be set correctly. Throws an error if the delegate is not set, no updates are available, no card reader is connected, or if other errors occur during the process. | | `connectedDock` | Returns the details of the connected dock. | | `dockFirmwareUpdateSummary: AvailableDockFirmwareUpdate?` | Checks if a firmware update is available for the dock that is currently connected to the mobile device. Returns an `AvailableDockFirmwareUpdate` instance if an update is available, otherwise `nil`. Can throw errors if there is a problem with retrieving the firmware, no dock is connected, or a general error occurs. See the [table with firmware update properties](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#afu-properties). | | `startDockFirmwareUpdate()` | Starts the firmware update on the dock that is currently connected to the mobile device. To receive [progress updates](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#fmd-methods), the `FirmwareManagerDelegate` must be set correctly, otherwise an error is thrown when calling this function. | | `AvailableFirmwareUpdate` or `AvailableDockFirmwareUpdate` property | Description[]() | | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `requiredDate: Date?` | The date when the firmware updates are required. | | `requiresBluetoothConnection: Bool` | Indicates whether this update requires a Bluetooth connection to the mobile device in order to proceed. Not included in `AvailableDockFirmwareProperties` for dock firmware updates. | | `FirmwareManagerDelegate` method | Description[]() | | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | | `firmwareUpdateProgress(percent: Double)` | Invoked when the firmware update percentage increases. | | `firmwareDownloadProgress(percent: Double)` | Invoked when the firmware download percentage increases. | | `applyingFirmwareUpdate()` | Invoked when the firmware update is being applied to the connected device (card reader or dock). | | `firmwareUpdateComplete()` | Invoked when the firmware update has been completed. | | `firmwareUpdateFailure(error: AdyenPOSError)` | Invoked when the firmware update fails with an associated error. `AdyenPOSError` describes the cause of the failure. | ## 8. Handle a payment In this step you add code to start a transaction with: * A [Terminal API](https://docs.adyen.com/point-of-sale/design-your-integration/terminal-api) payment request. **Tip**\ To help you create Terminal API requests, we provide a **TerminalAPIKit for iOS** on [GitHub](https://github.com/Adyen/adyen-terminal-api-ios). Installation and usage instructions are in the repository's README. * The card reader as the payment interface to use. * The presentation mode you want to use. To enable the iOS Mobile SDK to handle transactions: 1. In your POS app, create a Terminal API payment request with: * `MessageHeader.POIID`: the installation ID of the SDK. * If you create the Terminal API payment request in your POS app, use `PaymentService.installationId` as the `POIID` in the [MessageHeader](https://docs.adyen.com/point-of-sale/design-your-integration/terminal-api#request-message-header) of the request. * If you create the Terminal API payment request in the backend, this uses the [installationId](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate#responses-201-installationId) from the [`/auth/certificate` response](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#session). * The remaining `MessageHeader` parameters and the request body. For details, see [Make a payment](https://docs.adyen.com/point-of-sale/basic-tapi-integration/make-a-payment) and [PaymentRequest](https://docs.adyen.com/api-explorer/terminal-api/latest/post/payment). * If you want to be able to [make a referenced refund of an offline payment when back online](https://docs.adyen.com/point-of-sale/basic-tapi-integration/refund-payment/referenced#refund-offline-payment), add the Card Reader ID as [metadata in `SaleData.SaleToAcquirerData`](https://docs.adyen.com/point-of-sale/basic-tapi-integration/refund-payment/referenced#refund-offline-payment). ** ### Add the card reader ID to the payment request To add the card reader ID to the payment request: 1. Look up the card reader ID of the connected card reader, using: ```swift if let connectedDevice = paymentService.deviceManager.connectedDevice, let name = connectedDevice.name { let fullName = "\(name)-\(connectedDevice.serialNumber)" print(fullName) // e.g. "NYC1-123456" } ``` 2. In `SaleData.SaleToAcquirerData` include:\ `metadata`: Must include a key, for example `cardReaderID`, with the card reader's unique identifier for example NYC1-123456, as its value.\ Pass the `SaleToAcquirerData` value in one of the following formats: * Option 1: a JSON object converted to a Base64 encoded string. **Example data element in JSON format** ```json { "metadata": { "cardReaderID": "NYC1-123456" } } ``` Example JSON object converted to a Base64 encoded string: ```raw ewogICAgIm1ldGFkYXRhIjogewogICAgICAgICJjYXJkUmVhZGVySUQiOiAiTllDMS0xMjM0NTYiCiAgICB9Cn0= ``` * Option 2: form-encoded key-value pairs (using **&** as a separator). For example:\ `metadata.cardReaderID=NYC1-123456`\ The format that you use here, will also be the format of the `AdditionalResponse` that you receive. Refer to [Add information to a payment](https://docs.adyen.com/point-of-sale/add-data#base64-json) to learn how to extract the cardReaderID from the `AdditionalResponse` in the payment response. 2. Create an instance of `Payment.Request` using `Payment.Request(data:)`, and pass the Terminal API payment request from your POS app or backend. ```swift let transaction = try Payment.Request(data: requestData) ``` 3. Get a `PaymentInterface` from an instance of `PaymentService`, using `PaymentService.getPaymentInterface(with: .cardReader)`. ```swift let paymentService = PaymentService(...) let paymentInterface = try paymentService .getPaymentInterface(with: .cardReader) ``` 4. Specify a `TransactionPresentationMode` value that matches the UI framework, SwiftUI or UIKit, of the POS app. | Value | Description | | -------------------------- | ------------------------------------------------------------------------------------------------ | | `viewModifier` | For use with a SwiftUI application. The UI is embedded in a `View` as a `ViewModifier`. | | `presentingViewController` | For use with a UIKit application. The UI is presented on top of the provided `UIViewController`. | []()Optionally use parameters to customize the user interface. | Parameter | Description | | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `logo` | A bitmap image to show on your mobile device during the transaction flow. To ensure visibility in both dark mode and light mode, the bitmap image must have a transparent background. The logo is placed in a frame with a vertical height of 40 points and scaled to aspect ratio to fit in that frame. | | `successScreenTimeout` | Indicates how long the SDK shows the screen that indicates the transaction succeeded. If not specified, this success screen is dismissed after four seconds. You can set a time in seconds as a Double with a minimum of 0.5 seconds and a maximum of 4 seconds. | #### Using `viewModifier` (SwiftUI) If you use `TransactionPresentationMode` with `viewModifier`: 1. Set `presentationMode` as follows. ```swift let presentationMode: TransactionPresentationMode = .viewModifier ``` 2. Apply the presentation mode on your SwiftUI view. ```swift Button(...) { // code to start the transaction }) .transactionModal( with: {YOUR_INSTANCE_OF_PAYMENT_SERVICE} logo: logo, parameters: .init(successScreenTimeout: 2) ) ``` #### Using `presentingViewController` (UIKit) If you use `TransactionPresentationMode` with `presentingViewController(_:logo:parameters:)`, set `presentationMode` as follows. ```swift let presentationMode: TransactionPresentationMode = .presentingViewController( rootViewController, logo: logo, parameters: .init(successScreenTimeout: 2) ) ``` 5. Invoke `PaymentService.performTransaction(with:paymentInterface:presentationMode:)` on your instance of `PaymentService`. ```swift let transactionResponse = await paymentService.performTransaction( with: transaction, paymentInterface: paymentInterface, presentationMode: presentationMode ) ``` The Mobile SDK checks for a session, starts the transaction, and shows screens on your mobile device to help the customer. 6. Check the `paymentResponse`. This is the Terminal API response with the transaction result and the data you can use to generate a receipt, or with any [errors](https://docs.adyen.com/point-of-sale/error-scenarios). 7. Pass the `paymentResponse` to your POS app. ## 9. Handle a refund There are two types of refund: [referenced](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#referenced-refund) and [unreferenced](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#unreferenced-refund). The main difference is that a referenced refund is connected to the original payment, and an unreferenced refund isn't. That makes unreferenced refunds a bit riskier. For an overview of the differences, see [Refund a payment](https://docs.adyen.com/point-of-sale/basic-tapi-integration/refund-payment). Refunds are usually *not* processed synchronously. When you send a request for a referenced or unreferenced refund, the Terminal API response only confirms we received the request. We inform you about the outcome of the refund asynchronously, through a webhook. * For a referenced refund, we return a **CANCEL\_OR\_REFUND** webhook. * For an unreferenced refund, we return a **REFUND\_WITH\_DATA** webhook. Depending on the card scheme and country/region where the card is used, unreferenced refunds are sometimes processed synchronously. In that case the Terminal API response includes an `acquirerResponseCode` to indicate the outcome. To learn the [outcome of a refund](https://docs.adyen.com/point-of-sale/basic-tapi-integration/refund-payment/refund-webhooks), you need to set up webhooks. ### Handle a referenced refund The Terminal API request for a referenced refund is a reversal request. The SDK contains a dedicated function for this. In your iOS POS app, add code for the following steps: 1. Create a Terminal API reversal request with: * `MessageHeader.POIID`: the installation ID of the SDK. * If you create the Terminal API reversal request in your POS app, use `PaymentService.installationId` as the `POIID` in the [MessageHeader](https://docs.adyen.com/point-of-sale/design-your-integration/terminal-api#request-message-header) of the request. * If you create the Terminal API reversal request in the backend, this uses the [installationId](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate#responses-201-installationId) from the [`/auth/certificate` response](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#session). * The remaining `MessageHeader` parameters and the request body. For details, see [Referenced refund](https://docs.adyen.com/point-of-sale/basic-tapi-integration/refund-payment/referenced) and [ReversalRequest](https://docs.adyen.com/api-explorer/terminal-api/latest/post/reversal). 2. Create an instance of `Reversal.Request` using `Reversal.Request(data:)`, and pass the Terminal API reversal request from your POS app or backend. ```swift let request = try Reversal.Request(data: requestData) ``` 3. Invoke `PaymentService.performReversal(with:)` on your instance of `PaymentService`. ```swift let reversalResponse = await paymentService.performReversal(with: request) ``` The Mobile SDK now checks for a session, and starts the transaction. 4. Check the `reversalResponse`. This is the Terminal API response with the transaction result and the data you can use to generate a receipt, or with any [errors](https://docs.adyen.com/point-of-sale/error-scenarios). 5. Pass the `reversalResponse` to your POS app. ### Handle an unreferenced refund The Terminal API request for an unreferenced refund is a payment request with an additional parameter: * `PaymentData.PaymentType`: **Refund** This means you can use the same code as for [handling a payment](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#payment). The only difference is the structure of the Terminal API payment request that you pass as the `requestData` to the `Payment.Request`. For the structure of the Terminal API request, see [Unreferenced refund](https://docs.adyen.com/point-of-sale/basic-tapi-integration/refund-payment/unreferenced). ## 10. Check the transaction status We recommend checking the transaction status if your POS app doesn't receive a payment response, for example due to a communication or technical issue. You must send the transaction status request from your POS app, not from your backend. The response lets you determine whether the original transaction succeeded or whether no matching transaction was found. In your iOS POS app, add code for the following steps: 1. Create a Terminal API transaction status request with: * `MessageHeader.POIID`: the installation ID of the SDK. Use `PaymentService.installationId` as the `POIID` in the [MessageHeader](https://docs.adyen.com/point-of-sale/design-your-integration/terminal-api#request-message-header) of the request. * The remaining `MessageHeader` parameters and the request body, referencing the `SaleID` and `ServiceID` of the *original* transaction in `TransactionStatusRequest.MessageReference`. For details, see [Verify transaction status](https://docs.adyen.com/point-of-sale/basic-tapi-integration/verify-transaction-status) and [TransactionStatusRequest](https://docs.adyen.com/api-explorer/terminal-api/latest/post/transactionstatus). 2. Call `PaymentService.getTransactionStatus(request:)`, passing a `TransactionStatus.Request`: ```swift let transactionStatusResponse: TransactionStatus.Response = await paymentService.getTransactionStatus(request: request) ``` 3. Check the `TransactionStatus.Response` that you receive: this is the serialized `TransactionStatusResponse` JSON data. Deserialize this to check the `Result`/`ErrorCondition`: * `Result: Success`: the transaction reached an end state. Check the nested original transaction response's own `Result`/`ErrorCondition` to see if it succeeded or failed. * `Result: Failure` with `ErrorCondition: InProgress`: the transaction is still being processed. Repeat the transaction status request until you get an end state - do not retry the original transaction. * `Result: Failure` with `ErrorCondition: NotFound`: no matching transaction was found. Check the `SaleID`/`ServiceID`/`POIID` before considering a retry of the original transaction. For a detailed explanation of the request and response, see [Verify transaction status](https://docs.adyen.com/point-of-sale/basic-tapi-integration/verify-transaction-status). ## 11. Diagnose the device We recommend implementing the Terminal API diagnosis request. This enables you to do the following: * Check if there are **stored offline payments** that have not been forwarded to Adyen yet. The SDK will try to go online and forward these transactions. Note that you do not need to send a diagnosis request to forward offline transactions, because forwarding happens automatically whenever the internet connection is restored after it had dropped. * Check for **security threats** that would block transactions. If threats are detected that an operator can solve, the response includes information about the cause and solution of the problem. * Check the **expiry date of the SDK** that is used on the mobile device. [Transactions will be blocked](https://docs.adyen.com/point-of-sale/mobile-ios/manage/#keep-the-mobile-sdk-up-to-date) if mandatory updates are not carried out. Be aware that the diagnosis can take a while if the SDK succeeds in going online and there is a large number of stored offline payments that are forwarded. In your iOS POS app, add code for the following steps: 1. Create a Terminal API diagnosis request with: * `MessageHeader.POIID`: the installation ID of the SDK. * If you create the Terminal API diagnosis request in your POS app, use `PaymentService.installationId` as the `POIID` in the [MessageHeader](https://docs.adyen.com/point-of-sale/design-your-integration/terminal-api#request-message-header) of the request. * If you create the Terminal API diagnosis request in the backend, this uses the [installationId](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate#responses-201-installationId) from the [`/auth/certificate` response](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#session). * The remaining `MessageHeader` parameters. * The request body consisting of `DiagnosisRequest.HostDiagnosisFlag`: set to **true**, so that the SDK will try to forward any stored offline transactions and perform a security scan. For details, see [Diagnose a Mobile SDK solution](https://docs.adyen.com/point-of-sale/diagnostics/request-diagnosis#diagnosis-request-mobile) and [DiagnosisRequest](https://docs.adyen.com/api-explorer/terminal-api/latest/post/diagnosis). 2. Call the `performDiagnosis` function, using the `request` parameter to pass the Terminal API diagnosis request. ```swift public func performDiagnosis( with request: Diagnosis.Request ) async -> Diagnosis.Response { await diagnosisPerformer.performDiagnosis(with: request) } ``` 3. When you get the Terminal API `DiagnosisResponse`, check the `Response.AdditionalResponse`: * See the `unconfirmedBatchCount` for the number of stored offline transactions that have not been forwarded to theAdyen payments platform yet. * Base64-decode the `storeAndForwardStatus` value for more information about offline transactions. * Base64-decode the `attestationStatus` value for information about any security issues. If issues are detected that can be resolved by the end user, the resulting JSON object includes messages with the details. These are the same [error messages](https://docs.adyen.com/point-of-sale/mobile-ios/troubleshooting/#error-messages) that we show automatically on the end user's mobile device when these issues are detected during a transaction. * See the `sdkExpiry` for the date when the installed SDK version expires. For a detailed explanation of the response, see [Diagnose a Mobile SDK solution](https://docs.adyen.com/point-of-sale/diagnostics/request-diagnosis#diagnosis-request-mobile). ## 12. (Optional) Clear the session token There are several situations when you need to clear the existing session to remove all session information from your mobile device. When you have cleared the session, configuration updates are fetched and a new session is established when you start a new transaction or call the warm-up function. As a best practice, clear the session to: * **Re-establish a session after switching between merchant accounts or stores in your POS app and your Customer Area**. If the device is reassigned from store A to store B and a transaction is started there, on the Adyen side the transaction will continue to appear to belong to store A instead of store B. Clearing the session prevents this issue. * **Force a refresh of the configuration**. After clearing the session, the latest configuration is fetched and stored on your mobile device the next time the iOS Mobile SDK connects to the Adyen backend. * **Test the session establishment flow in your POS app**, specifically how it interacts with your and Adyen's backend to securely establish a session with the iOS Mobile SDK. To clear the session: 1. Explicitly clear the communication session using `PaymentService.resetSession()` . 2. [Establish a new communication session](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#session). ## Other supported features In addition to [payments](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#payment), [refunds](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#referenced-refund), and [diagnosis](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#diagnosis), the Mobile solutions support other (payment) features. These are the same features that are supported in Terminal API integrations using Adyen-provided payment terminals. For some features you need to add parameters to your Terminal API payment request, similar to [unreferenced refunds](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#unreferenced-refund) described above. Other features only require enabling the feature for your Adyen account. You can find the details on the pages dedicated to those features. Where the details differ between an integration using payment terminals and a mobile solution, this is clearly indicated. | Feature | Supported with Card reader iOS | | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | | Diagnosis | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | | [Partial authorization](https://docs.adyen.com/point-of-sale/partial-authorizations/) | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | | Payment | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | | [Pre-authorization](https://docs.adyen.com/point-of-sale/pre-authorisation/) | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | | Refund, referenced | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | | Refund, unreferenced | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | | [Store and forward](https://docs.adyen.com/point-of-sale/offline-payment/) offline payments | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | | [Surcharge](https://docs.adyen.com/point-of-sale/surcharge/) | ![-x-](/user/data/smileys/emoji/x.png "-x-") | | [Tax-free shopping](https://docs.adyen.com/point-of-sale/shopper-recognition/tax-free-shopping/) | ![-x-](/user/data/smileys/emoji/x.png "-x-") | ## Test your solution To test your solution, you can: * Use our test cards to make test payments. * Use our card reader simulator to verify that the device management UI works as expected. ### Make test payments To make test transactions: 1. Make sure you are using the test version of the Mobile SDK. 2. Initiate a test transaction using the following Adyen point-of-sale test cards to complete the payment: * [White-green test card](https://docs.adyen.com/point-of-sale/testing-pos-payments/test-card-v3/) * [Blue-green test card](https://docs.adyen.com/point-of-sale/testing-pos-payments/test-card-v2/) version **2.4** or later The instructions are the same for both cards; see either of the pages mentioned above. ### Test the device management UI You can use a simulated card reader instead of a physical card reader to test your device management UI. The card reader simulator enables you to check if your application code works as expected in the following scenarios: * Updating the card reader firmware. Unlike with a physical card reader, the simulator lets you test this flow repeatedly. * Connecting, disconnecting, and automatically reconnecting the card reader. * Showing the battery charge level or showing that the battery is charging. * Showing the type of card reader: * NYC1, also referred to as NYC1 (SCRP), which supports PIN transactions. * NYC1-SCR, which does not support PIN transactions. * Showing the version number of various firmware types. Currently, the simulator only supports testing your device management UI in a test build. It does not yet support transactions — if you try to start a payment while the simulator is activated, you get the error `"Transactions are not supported while simulatedCardReaderConfiguration is active."` ### Use the simulator To use the simulator, add the following code. 1. Implement a compile-time check, such as `#if !LIVE`, to ensure that the simulator is not called in live builds. 2. Activate and configure the simulator using `PaymentService.simulatedCardReaderConfiguration: SimulatedCardReaderConfiguration?` and the following parameters. **SimulatedCardReaderConfiguration** | Parameter | Type | Description | | ---------------------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `serialNumber` | `String` | The simulated serial number. The default value is **SIMULATED-NYC1-001**. | | `deviceType` | `Device.DeviceType` | The simulated device type. The default value is **.nyc1**. | | `firmwareVersion` | `String` | The simulated firmware version. The default value is **3.1.00.10**. | | `applicationVersion` | `String` | The simulated application version. This parameter determines the simulated device type: NYC1 (SCRP) or NYC1-SCR. To simulate the NYC1 (SCRP), use a value starting with **3.1**. The default value is **3.1.22.10**. | | `bluetoothFirmwareVersion` | `String?` | The simulated firmware version of the Bluetooth module. | | `batteryChargePercentage` | `Int?` | The simulated battery charge level. Set to **nil** to simulate a charging state. | | `connectionDelay` | `TimeInterval` | The number of seconds between calling `connect(to:)` and the moment that `onDeviceConnected` fires and a connection is simulated. The default value is **1.0**. | | `simulateDisconnectionAfter` | `TimeInterval?` | If set, the number of seconds after connecting that a disconnection is simulated. | | `simulateReconnectionAfter` | `TimeInterval?` | If set, the number of seconds after disconnecting that a reconnection is simulated. | | `availableFirmwareUpdate` | `SimulatedFirmwareUpdate?` | If set, `firmwareUpdateAvailable` returns **true** when polled. See the next table for allowed `SimulatedFirmwareUpdate` parameters. | **SimulatedFirmwareUpdate** | Parameter | Type | Description | | ----------------------------- | -------------- | ---------------------------------------------------------------------------------- | | `targetVersion` | `String` | The firmware version that is reported after the simulated update finishes. | | `updateDuration` | `TimeInterval` | The total simulated time in seconds that the simulated update takes. | | `requiredDate` | `Date?` | The date that the update becomes mandatory. Set to **nil** for an optional update. | | `requiresBluetoothConnection` | `Bool` | Indicates if the simulated update requires an active Bluetooth connection. | **Simulator configuration example** ```swift // 1. Activate the simulated reader (test builds only) paymentService.simulatedCardReaderConfiguration = SimulatedCardReaderConfiguration( serialNumber: "TEST-DEVICE-001", batteryChargePercentage: 72, connectionDelay: 0.5, simulateDisconnectionAfter: 30, simulateReconnectionAfter: 5, availableFirmwareUpdate: SimulatedFirmwareUpdate( targetVersion: "3.1.00.11", updateDuration: 8.0 ) ) // 2. Use DeviceManagementView as normal — no code changes needed DeviceManagementView(paymentService: paymentService) // 3. Deactivate and restore real hardware paymentService.simulatedCardReaderConfiguration = nil ``` 3. Update the configuration each time you want to test a different scenario. For example: * To test a firmware update: set `availableFirmwareUpdate` to a `SimulatedFirmwareUpdate` with your target version and duration. Note that this does not push a delegate event. Your UI must query `firmwareUpdateAvailable` or `firmwareUpdateSummary` to detect a pending update. * Set `batteryChargePercentage` to a low value such as **5** to simulate a low battery state, or set it to **nil** to simulate a charging state. * To test connection flows: set `simulateDisconnectionAfter` to the number of seconds after which the reader disconnects, and set `simulateReconnectionAfter` to the number of seconds after which the reader reconnects. * To test a different card reader type: set `deviceType` and adjust `applicationVersion` accordingly. 4. When done with UI testing, deactivate the simulator so that you can make test payments again, if needed. ```swift paymentService.simulatedCardReaderConfiguration = nil ``` ## Go live When you have finished testing your integration and are ready to go live: 1. If new to Adyen, get a [live account](https://docs.adyen.com/get-started-with-adyen/#apply-for-your-live-account). You need to have access to your organization's live Customer Area to generate API credentials for the live environment. 2. [Get the live SDK](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#get-live-sdk). You need to generate a new, live basic authentication credential exclusively for downloading the SDK. 3. [Use the live endpoint for establishing a session](https://docs.adyen.com/point-of-sale/mobile-ios/build/card-reader#establish-a-live-session). To access the live endpoint, you need to generate a new, live API key that is different from the API key used for downloading the SDK. ### Get the live SDK To pull in the live version of the SDK: 1. Generate a new basic authentication credential in your [live Customer Area](https://ca-live.adyen.com/) and add it to your `.netrc` file. 2. In your `.netrc` file, change the value for `machine` to `pos-mobile.cdn.adyen.com`. 3. In your Xcode project or workspace, remove the TEST dependency and add the LIVE dependency using the **URL** `https://github.com/Adyen/adyen-pos-mobile-ios`. 4. Add `AdyenPOSLIVE` to your app target that connects to the Adyen Live environment. If your POS app requires the iOS Mobile SDK to be compatible with Objective-C: * Link the `ADYPOSLIVE` package product to your app target instead of `AdyenPOSLIVE`. ### Establish a live session When going live, you must change the [/auth/certificate](https://docs.adyen.com/api-explorer/softpos-configuration-api/latest/post/auth/certificate) endpoint where you send requests to establish a secure communication session, as well as the API key that you use to authenticate those requests. * To access the live endpoint, generate a new API key from your [live Customer Area](https://ca-live.adyen.com/). * The live endpoint URL to use depends on the region: * Australia: `https://softposconfig-live-au.adyen.com/softposconfig/v{version}/auth/certificate` * Northeast Asia: `https://softposconfig-live-nea.adyen.com/softposconfig/v{version}/auth/certificate` * Europe: `https://softposconfig-live.adyen.com/softposconfig/v{version}/auth/certificate` * North East Asia: `https://softposconfig-live-nea.adyen.com/softposconfig/v{version}/auth/certificate` * United States: `https://softposconfig-live-us.adyen.com/softposconfig/v{version}/auth/certificate` ## Next steps [required](https://docs.adyen.com/point-of-sale/mobile-ios/manage) [![](/user/themes/adyen/images/illustrations/settings.svg)](https://docs.adyen.com/point-of-sale/mobile-ios/manage) ###### [Manage your solution](https://docs.adyen.com/point-of-sale/mobile-ios/manage) [Make your solution available and keep the software up-to-date.](https://docs.adyen.com/point-of-sale/mobile-ios/manage) [![](/user/themes/adyen/images/illustrations/checkmark.svg)](https://docs.adyen.com/point-of-sale/mobile-ios/checklists) ###### [Checklists](https://docs.adyen.com/point-of-sale/mobile-ios/checklists) [Get a list of what needs to be done to get started and go live with a Mobile solution.](https://docs.adyen.com/point-of-sale/mobile-ios/checklists) [![](/user/themes/adyen/images/illustrations/close.svg)](https://docs.adyen.com/point-of-sale/mobile-ios/troubleshooting) ###### [Error handling](https://docs.adyen.com/point-of-sale/mobile-ios/troubleshooting) [Resolve errors that appear on the mobile iOS device.](https://docs.adyen.com/point-of-sale/mobile-ios/troubleshooting) [![RFID card icon](https://docs.adyen.com/media/fdd0fdd363e6ce5972f68308714e105d4eb7cd1b73d93f5a015963246211b8bf.svg?decoding=auto\&fetchpriority=auto)](https://docs.adyen.com/point-of-sale/user-manuals/nyc1) ###### [Use the card reader](https://docs.adyen.com/point-of-sale/user-manuals/nyc1) [Learn how to connect and operate the NYC1 card reader.](https://docs.adyen.com/point-of-sale/user-manuals/nyc1) [![RFID card icon](https://docs.adyen.com/media/fdd0fdd363e6ce5972f68308714e105d4eb7cd1b73d93f5a015963246211b8bf.svg?decoding=auto\&fetchpriority=auto)](https://docs.adyen.com/point-of-sale/user-manuals/nyc1-with-dock) ###### [Use the card reader with a dock](https://docs.adyen.com/point-of-sale/user-manuals/nyc1-with-dock) [Learn how to connect and operate the NYC1 card reader and NYC1 dock.](https://docs.adyen.com/point-of-sale/user-manuals/nyc1-with-dock)