# Result Codes and Errors

The Get Mini framework reports transaction status and errors through standard `NSError` objects in delegate callbacks and specific status properties within the `RespuestaTransaccionDTO` result.

## SDK Error Codes

Errors are returned via the `NSError` parameter in methods like `onPaymentFinished` or `onInitFinished`. The `code` property corresponds to the library's internal error table.

### Common Library Errors (NSError.code)

| Code | Status Constant | Description |
| :---- | :---- | :---- |
| 0 | `STATUS_OK` | Operation completed successfully. |
| 1 | `STATUS_KO_ACCESO_DATOS` | Error accessing the local database (SQLite). |
| 11 | `STATUS_KO_DATOS_MAL_FIRMADOS` | Message signature is incorrect. |
| 28 | `STATUS_KO_USER_BLOQUEADO` | The user account is blocked. |
| 78 | `STATUS_KO_OPERACION_FALLIDA` | Web Service operation failed. |
| 117 | — | **Denegada por pin online incorrecto** (Incorrect online PIN). |
| 999 | — | Indeterminate error. |
| 1040 | — | PIN pad not operational. |

### TPV-PC Specific Errors

These codes often appear when processing refunds or specific terminal operations.

| Code | TPV-PC Code | Description |
| :---- | :---- | :---- |
| 200 | TPV-PC0009 | Refund amount exceeds the original transaction amount. |
| 232 | TPV-PC0058 | Specified currency does not match terminal currency. |
| 241 | TPV-PC0071 | Merchant does not have Pre-authorizations enabled. |
| 250 | TPV-PC0084 | Card reading error (Check reader or card status). |
| 252 | TPV-PC0087 | System busy. Retry after a few moments. |
| 258 | TPV-PC0094 | No more confirmations allowed for this pre-authorization. |

## Transaction Result Values

For finalized payments, the result is delivered in a `RespuestaTransaccionDTO`. You must evaluate the `estado` and `resultado` fields to determine the outcome.

### Estado (Transaction State)

| Value | Description |
| :---- | :---- |
| "F" | **Finalizada** (The process reached the server and finished). |
| "P" | **En proceso** (Still being processed). |
| "G" | **Denegada** (The transaction was declined). |
| "A" | **Anulada** (The transaction was cancelled/annulled). |
| "T" | **Fallo técnico** (A technical error occurred during processing). |

<Callout type="warning">

`Estado == "F"` does NOT mean the payment was approved. It only means the gateway responded. Always check the `resultado` field.

</Callout>

### Resultado (Decision)

| Value | Description |
| :---- | :---- |
| "Autorizada" | The transaction was approved by the issuer. |
| "Denegada" | The transaction was declined by the issuer or gateway. |

## Authorization Response Codes

The `codigoRespuesta` property in `RespuestaTransaccionDTO` (or `RespuestaBoletaDTO`) contains the host's authorization code (for approved sales) or the specific denial code.

Branch on `resultado`, which returns `"Autorizada"` or `"Denegada"`, rather than on the code value. Log `codigoRespuesta` with the transaction so that the support team can trace a decline.

## Progress Monitoring

The SDK provides real-time updates through two primary callbacks. Use these to update your UI during hardware interaction.

### onInitProcess (Initialization)

Reports progress during `connectAndConfigureDevice`. Messages are typically strings like:
- "Cargando claves..." (Loading keys)
- "Configurando terminal..." (Configuring terminal)

### onPaymentProcess (Payment)

Reports progress during `payWithPinpadBluetooth`. It notifies the UI of state changes such as:
- Waiting for card insertion.
- PIN entry requested.
- Connecting to host for authorization.

## Best Practices for Error Handling

1. **Evaluate NSError first**: If the `NSError` parameter is not nil, the transaction failed before reaching the gateway (e.g., Bluetooth loss or library timeout).
2. **Handle Code 117**: Always provide a specific message for code 117 ("Incorrect PIN") as this is the most common user-correctable error.
3. **Check Merchant Profile**: If you receive errors 241 or 273 consistently, use `PerfilComercioManager` to verify your terminal's enabled features (Pre-authorizations, Manual Entry).
4. **Log IdentificadorRTS**: For any error that occurs after the "Authorizing" phase, log the `identificadorRTS` to facilitate support troubleshooting with Get Mini.