# Query Transaction States (/global/en/docs/Terminal/CodeDevelopment/Query-Transaction-States)

## Transaction Query

**API reference**\
[MessageStatusParam Object](doc-id:677a5c7f)

The Transaction Query API allows you to retrieve the status and details of a transaction. It can be used both for querying completed transactions and monitoring transactions in progress.

### Query Historical Transactions

When there is no ongoing transaction, you can use this API to query the result of completed transactions.

This is typically used in the following scenarios:

- **Response recovery**\
  When the original transaction response is lost or not received in time, this API can be used for reconciliation or recovery purposes.

- **Transaction verification**\
  To confirm the final transaction status for reporting, reconciliation, or settlement processing.

### Monitor Ongoing Transactions

During transaction processing, you can call this API to check the current execution status via the processStatus field.

This enables the client to:

- **Track transaction progress**\
  Monitor intermediate states such as card reading, PIN entry, or online processing.
- **Improve user experience**\
  Provide clearer feedback to users by displaying the current payment stage.
- **Handle exceptions properly**\
  Decide whether to continue waiting, or take appropriate action in cases such as timeout or user cancellation.

```java
MessageStatusParam param = MessageStatusParam.newBuilder()
        .orgExchangeIdentification("000000001")
        .initiatingPartyIdentification("Cashier1")
        .build();
RetailerManager.getInstance()
        .provideSystemService()
        .newMessageStatusExchange(param)
        .startAsyncExchange(new Exchange.RetailerSDKCallback<MessageStatusResult>() {
            @Override
            public void onError(int code, String msg) {
                Log.e(TAG, "failed: " + code + ", " + msg);
            }
            @Override
            public void onResult(MessageStatusResult result) {
                Log.i(TAG, "result: " + GsonUtils.toJson(result));
            }
        });             
```