> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/implement-nfc-wallet/enroll-wallet.md).

# Enroll wallet

## Overview

Enroll your **digital wallet application** after **NFC Wallet SDK** initialization and before you start **Tokenization**. Wallet enrollment provisions the digital wallet application with the security assets required to call **NFC Wallet** services:

* Run this once per wallet instance.
* Run this only if the digital wallet application uses **NFC Wallet** services.
* Run this only on devices that support contactless payments. See [Check contactless capability](broken://spaces/iHBSjQEwsJj8Udj0AFXY/pages/bOB3wh3T2b7CA8EKfMLg).

{% hint style="warning" %}
Enroll only digital wallet applications that use **NFC Wallet** services.

This avoids unnecessary network traffic from the digital wallet application and unnecessary load on **NFC Wallet** product.
{% endhint %}

## Sequence diagram

High-level flow to enroll your wallet application.

<figure><img src="/files/pQz2vmongGZDVJ48XPme" alt=""><figcaption><p>Wallet enrollment flow.</p></figcaption></figure>

{% hint style="info" %}
This flow is technically called **wallet secure enrollment** in **NFC Wallet**.
{% endhint %}

## SDK Integration

### Prerequisites

Before you start, verify the following:

* Your digital wallet application is onboarded in the **NFC Wallet** backend.
* You initialized the **NFC Wallet SDK**.
* The wallet is not enrolled (`WalletSecureEnrollmentService.isEnrolled()` returns `false`).
* If you support contactless payments, confirm the device is eligible. See [Check contactless capability](/nfc-wallet-sdk-ios/implement-nfc-wallet/check-contactless-capability.md).

{% hint style="info" %}
Skip contactless capability check if your digital wallet application does not support contactless payments (for example, QR code or DSRP remote payment only).
{% endhint %}

### Perform wallet enrollment

Wallet enrollment is a one-time action in the digital wallet application lifecycle.

Run it after SDK initialization, and only if the wallet is not enrolled.

1. Create a `WalletSecureEnrollmentService` instance.
2. Check `wse.isEnrolled()`.
3. If needed, call `wse.enroll()` to start the process. If the operation is successful, the wallet secure enrollment is completed, otherwise, an error will be thrown.

After wallet secure enrollment completes successfully, continue with [Tokenize a card](/nfc-wallet-sdk-ios/implement-nfc-wallet/tokenize-a-card.md).

```swift
func invokeWSEAsync() async {
   do {
        let wse = try WalletSecureEnrollmentService()
        // Check wallet enrollment status.
        if wse.isEnrolled() {
            // WSE is enrolled
        } else {
            // Trigger wallet secure enrollment.
            try await wse.enroll()
            // Enrollment process is completed successfully here.
        }
    } catch {
        // WSE error 
    }
}
```

### Errors

When wallet enrollment fails, handle these error types:

* `clientError`: An internal SDK error. A message is provided to the digital wallet application.
* `serverError`: A backend error. A message, `httpStatus`, `errorCode`, and optional `additionalInfo` are provided to the digital wallet application.
* `networkError`: The device has no internet connection.

{% hint style="info" %}
The `WalletSecureEnrollmentService.eventStream` and `WalletSecureEnrollmentService.State` APIs are deprecated and will be removed in the next release. Hence, you have to migrate your code to use the `WalletSecureEnrollmentService.enroll` API and for all new implementations as demonstrated above
{% endhint %}

### Deprecated APIs

The following example demonstrates the use of `WalletSecureEnrollmentService.State` and `WalletSecureEnrollmentService.eventStream` APIs which are deprecated.

These are the possible events of `WalletSecureEnrollment` when the `WalletSecureEnrollmentService.eventStream` (deprecated) API is used:

* `.started`: Wallet secure enrollment process is started.
* `.completed` : Wallet secure enrollment process is completed.
* `.errorEncountered`: The wallet secure enrollment error is returned.

```swift
// Deprecated API
func invokeWSEAsync() async {
    do {
        let wse = try WalletSecureEnrollmentService()
        // check wallet enrollment status.
        if wse.isEnrolled() {
            // WSE is enrolled
        } else {
          // trigger wallet secure enrollment.
            wse.enroll()
            for await state in wse.eventStream {
              switch state {
                case .started:
                  // trigger when WSE started.
                case .completed:
                  // trigger when WSE completed.
                case .errorEncountered(let error):
                  switch error {
                    case .clientError(let message):
                        //error handling 
                    case .serverError(let message, let httpStatus, let errorCode, let additionalInfo):
                        //error handling 
                    case .networkError:
                        //error handling 
                    }
                }
            }
        }
    } catch {
        // WSE initialization error 
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/implement-nfc-wallet/enroll-wallet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
