# diagnosis

> The diagnosis API is called by your POS to check the payment terminal status. Ensure to call this API before creating any payment request to ensure the payment terminal is ready to accept payment requests.

The **diagnosis** API is called by your POS to check the payment terminal status. Ensure to call this API before creating any payment request to ensure the payment terminal is ready to accept payment requests.

## Method signature

When calling this method, please use the following standard method signature format.

```kotlin
fun diagnosis(
    diagnosisRequest: DiagnosisRequest,
    options: RequestOptions? = null,
    callBack: DiagnosisResultListener? = null
)
```

## Parameters

| **Parameter name** | **Type** | **Required** | **Description** |
| --- | --- | --- | --- |
| _diagnosisRequest_ | [DiagnosisRequest](https://docs.antom.com/ac/omnichannel/usb_structures.md#fkynD) | Yes | Indicates the object that contains parameters for querying the global status of the payment terminal. |
| _options_ | [RequestOptions](https://docs.antom.com/ac/omnichannel/usb_structures.md#A6GQM) | No | Indicates the object that contains optional parameters in the API requests. |
| _callback_ | [DiagnosisResultListener](#zisnH) | No | The callback that is used to return the query result. See [_callback_](#zisnH) for details. |

#### _callback_

| **Parameter name** | **Type** | **Required** | **Description** |
| --- | --- | --- | --- |
| _result_ | [DiagnosisResultData](#kBVIg) | No | Indicates the result of querying the payment terminal status. |

## Return values

| **Parameter name** | **Type** | **Required** | **Description** |
| --- | --- | --- | --- |
| _result_ | [Result](https://docs.antom.com/ac/omnichannel/usb_structures.md#qrMZE) | Yes | Result of the API call. |
| _networkStatus_ | String | Yes | Network connection status. Valid values are: - `Y`: Connected. - `N`: Not connected. Please check the network status and router, and reconnect the terminal device to the network. |
| _printerStatus_ | String | Yes | Printer status. Valid values are: - `Y`: Connected. - `N`: Not connected. Please check the terminal printer. |
| _globalStatus_ | String | Yes | Overall device status, used to prepare to receive requests. Valid values are: - `Y`: Connected. - `N`: Not connected. Please restart the terminal device. |

## Result codes

| **_resultCode_** | **_resultStatus_** | **_resultMessage_** | **Further action** |
| --- | --- | --- | --- |
| `SUCCESS` | `S` | Success. | No action is required. |
| `PROCESS_FAIL` | `F` | A general business failure occurred. Do not retry. | Contact Antom Technical Support to troubleshoot the issue. |
| `PROCESS_FAIL` | `F` | The data format is invalid. | Contact Antom Technical Support to troubleshoot the issue. |
| `PROCESS_FAIL` | `F` | The public key pairing failed. | Contact Antom Technical Support to troubleshoot the issue. |
| `TERMINAL_BUSY` | `F` | The payment terminal is busy. | Try again later. |
| `DEVICE_NOT_CONNECT` | `F` | The USB connection failed. | - Check whether the initialization connection has been completed in your code. If not, perform initialization connection. - Check whether both ends of the USB connection are securely connected in your code. If not, connect the two devices again. |
| `TIMEOUT_EXCEPTION` | `U` | Response timeout. | Check whether the payment terminal app is active. If not, activate it again. |
| `UNKNOWN_EXCEPTION` | `U` | The API call failed, which is caused by unknown reasons. | Call the API again. |
| `UNKNOWN_EXCEPTION` | `U` | Failed to decrypt the data returned by the payment terminal. | Contact Antom Technical Support to troubleshoot the issue. |
| `UNKNOWN_EXCEPTION` | `U` | The message format is invalid. | Contact Antom Technical Support to troubleshoot the issue. |

## Samples

The following sample code shows how to call the **diagnosis** API:

```kotlin
PaymentManager.diagnosis(
    DiagnosisRequest(),
    RequestOptions(5000L),
    object : DiagnosisResultListener {
        override fun result(result: DiagnosisResultData) {
            responseTextView.post {
                responseTextView.text = result.toString()
            }
        }

    }
)
```

The following code shows a sample of the response:

```json
{
    "result":{
        "resultCode": "SUCCESS",
        "resultStatus": "S",
        "resultMessage": "Success."
    },
    "networkStatus": "Y",
    "printerStatus": "Y",
    "globalStatus": "Y"
}
```