# Process ID

The Process ID module determines whether a submitted identity document is authentic. It analyzes the images captured by the [ID Capture](https://developer.incode.com/docs/module-id-scan) module against known parameters for the document type, runs a set of authenticity checks, and produces a validation result and the OCR data used by later steps. Process ID has no capture UI of its own; the user-facing capture happens in the ID Capture step that runs before it.

The Process ID module (`addIdProcess`) runs the server-side processing; the [ID OCR](https://developer.incode.com/docs/module-id-info) module (`addOcr`) presents the optionally editable review screen to the user. When ID Capture uses `scanStep: .both`, processing runs automatically and a separate `addIdProcess` call is not required.

For an overview of this module and how it works, see [ID Validation](https://developer.incode.com/docs/id-validation-module).

How you use this module depends on your integration pattern. When the app defines the steps in code, you add the module to an `IncdOnboardingFlowConfiguration` as shown below; when the flow is defined in Dashboard, you reference it by session token and let the back end drive the steps. See [Integration Approaches](https://developer.incode.com/docs/ios-flow-configuration).

**Availability:** All variants.

## Add Process ID

1. Add an [ID Capture](https://developer.incode.com/docs/module-id-scan) module before Process ID. Process ID validates the document captured there.
2. Add Process ID with `addIdProcess(idCategory:)`.
   ```swift
   let flow = IncdOnboardingFlowConfiguration()

   flow.addIdProcess(idCategory: .primary) // Validate a document captured in a previous step.
   ```
3. Add an [ID OCR](https://developer.incode.com/docs/module-id-info) module (`addOcr()`) after Process ID to read or edit the extracted fields.

### Example

The example below adds ID Capture, then Process ID, then ID OCR. It then listens for the validation result on `IncdOnboardingDelegate`.

```swift
let flow = IncdOnboardingFlowConfiguration()

// 1. Capture the document. With scanStep: .both, processing runs automatically.
flow.addIdScan(scanStep: .front, idCategory: .primary)

// 2. Validate a captured document explicitly (required when you capture a single side).
flow.addIdProcess(idCategory: .primary)

// 3. Read/edit the OCR data the processing step returns.
flow.addOcr(isEditable: true, idRank: .firstID)

IncdOnboardingManager.shared.startOnboarding(
    sessionConfig: IncdOnboardingSessionConfiguration(token: "<SESSION_TOKEN>"),
    flowConfig: flow,
    delegate: self
)
```

```swift
extension MyViewController: IncdOnboardingDelegate {
    func onIdProcessed(_ result: IdProcessResult) {
        // ID validated. Read result.ocrData.
    }

    func onError(_ error: IncdFlowError) {
        // Validation could not be completed.
    }
}
```

## Configuration Options

Configure the module with `addIdProcess()`.

| Option       | Type         | Notes                                                                                   |
| ------------ | ------------ | --------------------------------------------------------------------------------------- |
| `idCategory` | `IDCategory` | Sets which captured document this step validates: `.primary` (default) or `.secondary`. |

When a flow captures two documents, use `addIdProcess(idCategory: .primary)` and `addIdProcess(idCategory: .secondary)` on separate steps to validate each captured document.

`addIdProcess(idCategory:enableIdSummaryScreen:)` is deprecated, and `enableIdSummaryScreen` will be removed. Use `addIdProcess(idCategory:)`.

## Result

Process ID delivers an `IdProcessResult` to `onIdProcessed(_:)` on the `IncdOnboardingDelegate`:

```swift
func onIdProcessed(_ result: IdProcessResult)
func onError(_ error: IncdFlowError)
```

`IdProcessResult` fields:

- `ocrData: OmniGetOCRDataResponse?`: The OCR data extracted from the processed ID, such as `name`, `address`, `birthDate`, `expirationDate`, `issueDate`, and `gender`; `nil` when unavailable.
- `extendedOcrJsonData: Data?`: The full extended OCR payload as raw JSON; `nil` when unavailable.

If validation cannot be completed, the error surfaces through `onError(_ error: IncdFlowError)`.
