# TokenizedResponse

Represents the token Finix issues after a successful payment sheet submission. Use the `id` to create a Payment Instrument via the Finix API.

Which object you receive depends on which [delegate callback](/ios/online/payment-action#param-delegate) you implement:

- `didSucceed(paymentController:, instrument: TokenizedResponse)`: receives a `TokenizedResponse` directly. No 3DS access.
- `didSucceed(paymentController:, response: PaymentSheetResponse)`: receives a `PaymentSheetResponse` that wraps the token on `tokenizedResponse` and the 3DS outcome on `threeDSResponse`. Preferred when 3DS is enabled.


Token Expiration
Tokens expire **30 minutes** after creation. Pass the token ID to your backend and create a Payment Instrument immediately.

```swift
TokenizedResponse {
    id: String                      // e.g. "TKeD6uad8xZc52Rqg1VhvSBw"
    fingerprint: String             // e.g. "FPRrcobjtdU98gr4sjiqYR1Qg"
    created: Date
    updated: Date
    expires: Date                   // 30 minutes after creation
    instrument: PaymentInstrumentType
    isoCurrency: ISOCurrency
}
```

| Field | Description |
|  --- | --- |
| `id` | Token ID. Pass this to the Finix API to create a Payment Instrument. |
| `fingerprint` | Unique fingerprint for the underlying payment instrument. |
| `created` | Timestamp when the token was created. |
| `updated` | Timestamp when the token was last updated. |
| `expires` | Timestamp when the token expires (30 minutes after creation). |
| `instrument` | Instrument type: payment card or bank account (a `PaymentInstrumentType` enum). |
| `isoCurrency` | Currency of the token (an `ISOCurrency` enum). |


The 3D Secure result does **not** live on `TokenizedResponse`. If you need it, implement the `response:` success callback and read `response.threeDSResponse`. See [PaymentSheetResponse](#paymentsheetresponse) below.

## PaymentSheetResponse

Wraps a `TokenizedResponse` with the optional 3D Secure outcome. Passed to the preferred `didSucceed(paymentController:, response: PaymentSheetResponse)` callback.

```swift
PaymentSheetResponse {
    tokenizedResponse: TokenizedResponse
    threeDSResponse: ThreeDSResponse?
}
```

| Field | Description |
|  --- | --- |
| `tokenizedResponse` | The underlying [TokenizedResponse](#tokenizedresponse). Use `tokenizedResponse.id` to create a Payment Instrument. |
| `threeDSResponse` | The 3D Secure outcome when [ThreeDSConfiguration](/ios/online/configuration#threedsconfiguration) is set on `Configuration` and 3DS runs. `nil` when 3DS wasn't configured. See [ThreeDSResponse](#threedsresponse). |


## ThreeDSResponse

Attached to `PaymentSheetResponse.threeDSResponse` after a 3D Secure session completes. Pass `sessionId` to your backend together with the token ID so the backend can reference the authenticated session when creating the Payment Instrument or Authorization.

```swift
ThreeDSResponse {
    sessionId: String                                 // e.g. "3d_secure_session_xxx"
    sourceId: String
    state: ThreeDSStatus                              // pending | succeeded | failed
    authenticationType: ThreeDSAuthenticationType?    // frictionless | challenge | attempt
    cardholderAuthentication: String?                 // CAVV
    electronicCommerceIndicator: String?              // ECI
    transactionId: String?
    version: String?
    failureCode: ThreeDSFailureCode?
    failureMessage: String?
    authenticationUrl: String?
    createdAt: Date
    updatedAt: Date

    // Computed properties
    isAuthenticated: Bool
    liabilityShift: Bool
    canProceedWithPayment: Bool
    isRetryable: Bool
    isTerminal: Bool
    needsChallenge: Bool
}
```

| Field | Description |
|  --- | --- |
| `sessionId` | The 3D Secure session ID (e.g. `3d_secure_session_xxx`). Forward this to your backend alongside the token. |
| `state` | Session state at the time the response was captured. In most cases this is `pending` because the value reflects the initial session-creation response rather than the final authentication outcome. Don't branch on this; if `didSucceed` fires with a non-nil `sessionId`, forward it to your backend. Issuer-reported authentication failures reach `didFail` as `ThreeDSAuthenticationFailed` (see [3D Secure error codes](/ios/online/payment-action#threeds-error-codes)). |
| `authenticationType` | How authentication completed: `frictionless` (no challenge), `challenge` (buyer completed a `WKWebView` challenge), or `attempt` (issuer attempted authentication). |
| `cardholderAuthentication` | The CAVV (Cardholder Authentication Verification Value) issued by the card network, when provided. |
| `electronicCommerceIndicator` | The ECI value issued by the card network, when provided. |
| `failureCode` / `failureMessage` | Populated when the issuer reported a specific failure reason (`ThreeDSFailureCode`). Combine with `isRetryable` to decide whether to prompt the buyer to try again. |
| `isAuthenticated` | `true` when the cardholder was successfully authenticated. |
| `liabilityShift` | `true` when liability for chargebacks shifts from the merchant to the issuer. |
| `canProceedWithPayment` | `true` when the SDK considers the result safe to proceed with (authenticated or ATTEMPT with liability shift). |


```swift
enum ThreeDSStatus: Int {
    case pending
    case succeeded
    case failed
}
```

```swift
enum ThreeDSAuthenticationType: Int {
    case frictionless
    case challenge
    case attempt
}
```

Implement the `response:` success callback. When `threeDSResponse` is non-nil, 3DS ran. Forward `sessionId` to your backend alongside the token ID.

```swift
func didSucceed(paymentController: PaymentInputController, response: PaymentSheetResponse) {
    let tokenId = response.tokenizedResponse.id
    if let threeDS = response.threeDSResponse {
        createPayment(tokenId: tokenId, threeDSSessionId: threeDS.sessionId)
    } else {
        createPayment(tokenId: tokenId, threeDSSessionId: nil)
    }
}
```

If 3DS fails, `didFail` is called instead with a [3DS error code](/ios/online/payment-action#3d-secure-error-codes).

Pass the token ID (`response.tokenizedResponse.id` from the preferred callback, or `instrument.id` from the legacy callback) to your backend, then call the Finix API to create a Payment Instrument. Once created, use the Payment Instrument ID for all subsequent Finix API calls.