> ## Documentation Index
> Fetch the complete documentation index at: https://docs.y.uno/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# Headless SDK (Enrollment iOS)

> Step-by-step guide on integrating Yuno's Headless SDK (Enrollment iOS) into your mobile application.

> [!NOTE]
>
> **This page documents a legacy SDK.** Starting a new integration? Use the [Yuno SDK](https://docs.y.uno/docs/yuno-sdk/get-started.md). Already on a legacy SDK? Follow the [migration guide](https://docs.y.uno/docs/yuno-sdk/migration/overview.md).
>
> The new **Yuno SDK** (Web v2.x, iOS v3.x, Android v3.x, React Native v2.x) replaces the Full, Lite, Seamless, Render, Headless, and Secure Fields SDKs with one API across every platform. Legacy SDKs remain supported side by side during the transition and are scheduled for deprecation in **2027**. Contact your Account Manager for migration planning.

> [!WARNING]
>
> **Orientation: Choosing Your Integration Flow**, before you begin, please review the [Official Integration Flow](https://docs.y.uno/docs/sdks/overview/understanding-flows.md).
>
> * **Standard Flow ([Full Checkout](https://docs.y.uno/docs/sdks/full-checkout/web-payments))**: Recommended for most merchants. Yuno handles the UI, security, and automatic updates for payment methods.
> * **Custom Flow (This SDK)**: Use this only if you require full control over the UX. **Note**: You will be responsible for manually handling payment statuses, 3DS transitions, and fraud routing data collection.

Yuno's Headless iOS SDK lets you enroll in payment methods and tokenize cards, saving them for future use.

The following steps describe enrolling a payment method using Yuno's Headless SDK.

## Requirements

To execute the enrollment process, you need to provide the `customer_session` to start the enrollment process in Step 3. To acquire the `customer_session`, you need to:

1. **Create a customer**: A customer is required to enroll in payments. Use the [Create Customer](https://docs.y.uno/reference/customers/create-customer.md) endpoint to create new customers. In the response, you will receive the customer `id`, which you use to create the customer session.
2. **Create the customer session**: Use the customer `id` and the [Create Customer Session](https://docs.y.uno/reference/customer-sessions-enrollment/create-customer-session.md) endpoint to receive the `customer_session`.

## Step 1: Include the library in your project

The first step is to install Yuno SDK to your iOS project.

> [!NOTE]
>
> **Check iOS SDK Versions**
>
> To view all available versions, visit the [release page](https://github.com/yuno-payments/yuno-sdk-ios/releases) on the Yuno iOS SDK repository.

You install Yuno SDK with [Swift Package Manager](https://www.swift.org/package-manager/). YunoSDK is no longer published on CocoaPods; the last CocoaPods version is 2.30.0. Set up the Swift package, and then add Yuno SDK as a dependency, as presented in the following code block:

```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
dependencies: [
    .package(url: "https://github.com/yuno-payments/yuno-sdk-ios.git", .upToNextMajor(from: "2.31.0"))
]
```

Add `YunoSDK` (dynamic) or `YunoSDK-Static` (static, what CocoaPods shipped) to your app target, never both.

## Step 2: Initialize Headless SDK with the public key

To initialize the Headless SDK, you need to import Yuno and provide a valid **PUBLIC\_API\_KEY**. If you don't have your API credentials, access the [Developers (Credentials)](https://docs.y.uno/docs/using-yuno/settings/developers-credentials.md) page to check how to retrieve them from the dashboard.

The code block below presents an example of importing and initializing the `Yuno`.

```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
import YunoSDK

Yuno.initialize(
    apiKey: "PUBLIC_API_KEY",
    callback: { print("Yuno SDK initialized") }
)
```

> [!NOTE]
>
> **Swift 6 Concurrency Requirements**
>
> If you're using Swift 6, you'll need to handle concurrency correctly when using the SDK's asynchronous methods. See the [Swift 6 Concurrency](https://docs.y.uno/docs/sdks/resources/swift-6-concurrency.md) guide for detailed implementation options and best practices.

> [!NOTE]
>
> **UISceneDelegate Initialization**
>
> If your app uses a `UISceneDelegate`, you can initialize Yuno within your `SceneDelegate`. However, if you prefer to initialize Yuno in a different part of your app, you can. The initialization method provides a callback that notifies you when the process has finished.

## Step 3: Create a customer session

To start the enrollment process, you need to provide the `customer_session`. First, you need to create a customer. You need a customer to enroll payments with. Use the [Create Customer](https://docs.y.uno/reference/customers/create-customer.md) endpoint to create new customers. In the response, you will receive the customer `id`, which you use to create the customer session.

After creating the customer, you can create the customer session. Use the customer `id` and the [Create Customer Session](https://docs.y.uno/reference/customer-sessions-enrollment/create-customer-session.md) endpoint. The `customer_session` will be provided in the response. You need a new `customer_session` every time you enroll in a new payment method.

## Step 4: Create an enrollment payment method object

You need an enrollment payment method object to set Headless SDK integration for enrollment. You can create one using the [Enroll Payment Method](https://docs.y.uno/reference/payment-methods-checkout/enroll-payment-method-checkout.md) endpoint. While creating the payment method object, you need to define which payment method your customer can enroll in. Currently, only CARD is available for Headless SDK.

> [!NOTE]
>
> **Card Verification**
>
> To verify cards with zero value authorization before enrollment, include the `verify` object when creating the payment method object for the customer session.

## Step 5: Start the enrollment process

Next, you will start the checkout process using the `apiClientEnroll` function, providing the necessary configuration parameters.

> [!WARNING]
>
> **Error Handling**
>
> This method throws an error if the Yuno SDK has not been initialized before calling it.

### Parameters

The following table lists all required parameters and their descriptions.

| Parameter | Description |
| - | - |
| `countryCode` | This parameter determines the country for which the payment process is being configured. The complete list of supported countries and their `countryCode` is available on the [Country coverage](https://docs.y.uno/docs/sdks/resources/country-coverage.md) page. |
| `customerSession` | Refers to the current enrollment's customer session received as a response to the [Create Customer Session](https://docs.y.uno/reference/customer-sessions-enrollment/create-customer-session.md) endpoint. Example: '438413b7-4921-41e4-b8f3-28a5a0141638' |

The next code block presents an example of the parameter configuration.

```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
var apiClientEnroll: YunoEnrollHeadless?

apiClientEnroll = try Yuno.apiClientEnroll(
    countryCode: "CO",
    customerSession: "eec6578e-ac2f-40a0-8065-25b5957f6dd3"
)
```

## Step 6: Generate a vaulted token

After collecting all user information, you can start the enrollment. First, you need to create a `vaulted_token` using the function `apiClientEnroll.continueEnrollment`. As it is an asynchronous function, you can use `do/catch` to ensure you will correctly handle triggered errors. Below, you will find an example of creating a `vaulted_token`:

```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
let enrollmentCollectedData: EnrollmentCollectedData = EnrollmentCollectedData(
    customerSession: "eec6578e-ac2f-40a0-8065-25b5957f6dd3",
    paymentMethod: CollectedData(
        type: "CARD",
        card: CardData(
            detail: CardData.Detail(
                number: "4111111111111111",
                expirationMonth: 12,
                expirationYear: 25,
                securityCode: "123",
                holderName: "Andrea",
                type: .credit
            )
        ),
        customer: Customer()
    )
)

let result = try await apiClientEnroll?.continueEnrollment(data: enrollmentCollectedData)
```

After enrolling the new card, you will receive the `vaulted_token`. You can use it to make payments in the future without asking for your customer's card information. The following code block presents an example of a response from the `apiClientEnroll.continueEnrollment` function. The response is a dictionary of type `[String: String]` with camelCase keys: `vaultedToken`, `status`, and `customerSession`.

```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
[
    "vaultedToken": "9104911d-5df9-429e-8488-ad41abea1a4b",
    // status: EXPIRED, REJECTED, READY_TO_ENROLL, ENROLL_IN_PROCESS, UNENROLL_IN_PROCESS,
    // IN_PROCESS, ENROLLED, DECLINED, CANCELED, ERROR, or UNENROLLED
    "status": "ENROLLED",
    "customerSession": "eec6578e-ac2f-40a0-8065-25b5957f6dd3"
]
```

> [!NOTE]
>
> **Using Webhooks for Enrollment Status**
>
> Consider using the enrollment status received via [Webhooks](https://docs.y.uno/docs/webhooks/index.md). Yuno recommends always basing business decisions on your platform on this status.

> [!NOTE]
>
> **Access the Demo Application**
>
> In addition to the code examples provided, you can access the [Yuno repository](https://github.com/yuno-payments/yuno-sdk-ios) for a complete implementation of Yuno iOS SDKs.

## Error handling

Handle errors returned by the SDK in your app, such as failed payments or validation errors. For HTTP status and response codes, see [Status and response codes](https://docs.y.uno/reference/payments/status-and-response-codes/payment.md) in the API reference.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.