> For the complete documentation index, see [llms.txt](https://intella.gitbook.io/scan2pay/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://intella.gitbook.io/scan2pay/api-specification/easycard-api/settlement.md).

# 結帳

{% hint style="warning" %}
每日關帳前需要叫用結帳
{% endhint %}

{% hint style="warning" %}
若需要系統端在午夜自動呼叫結帳，請聯繫intella
{% endhint %}

## Request

### Header

| 欄位          | 必填  | 型別        | 範例             | 說明                   |
| ----------- | --- | --------- | -------------- | -------------------- |
| Method      | YES | String(5) | 31800          | 支付方式, 悠遊卡使用31800     |
| ServiceType | YES | String    | **Settlement** | 服務代碼                 |
| MchId       | YES | String    | Account0001    | 特店帳號                 |
| TradeKey    | YES | String    | sha256...hash  | 交易密碼(sha256編碼)       |
| CreateTime  | YES | String    | 20180101120000 | 建立日期, yyyyMMddHHmmss |

### Data

| 欄位       | 必填  | 型別     | 範例       | 說明         |
| -------- | --- | ------ | -------- | ---------- |
| DeviceId | YES | String | 01301234 | 終端機(讀卡機)編號 |
| Retry    | YES | String | 0        | 重試次數, 請帶入0 |

## Response

### Header

| 欄位           | 型別        | 範例             | 說明                                                   |
| ------------ | --------- | -------------- | ---------------------------------------------------- |
| StatusCode   | String(4) | 0000           | [交易結果代碼](/scan2pay/appendix/scan2pay-error-codes.md) |
| StatusDesc   | String    | 交易成功           | 交易結果代碼說明                                             |
| Method       | String(5) | 31800          | 支付方式, 悠遊卡使用31800                                     |
| ServiceType  | String    | Settlement     | 服務代碼                                                 |
| MchId        | String    | Account0001    | 特店帳號                                                 |
| ResponseTime | String    | 20180101120000 | 交易回應時間, yyyyMMddHHmmss                               |

### Data

| 欄位                  | 型別     | 範例           | 說明                                                   |
| ------------------- | ------ | ------------ | ---------------------------------------------------- |
| TerminalTXNNumber   | String | 233856       |                                                      |
| HostSerialNumber    | String | 233856       |                                                      |
| TerminalID          | String | 08100DE0A57E |                                                      |
| SettlementStatus    | String | 0            |                                                      |
| **TxReserveAmount** | String | 0            | 加值總金額                                                |
| **TxTradeAmount**   | String | 20000        | 扣款總金額                                                |
| **TxRefundAmount**  | String | 200          | 退款總金額                                                |
| **TxCancelAmount**  | String | 0            | 加值取消總金額                                              |
| **TxReserveCount**  | String | 0            | 加值筆數                                                 |
| **TxTradeCount**    | String | 200          | 扣款筆數                                                 |
| **TxRefundCount**   | String | 2            | 退款筆數                                                 |
| **TxCancelCount**   | String | 0            | 加值取消筆數                                               |
| **TXNResult**       | String | Success      | 交易結果                                                 |
| Retry               | String | 0            |                                                      |
| ErrorCode           | String | 000000       | [交易結果代碼](/scan2pay/appendix/easycard-error-codes.md) |
| NewAESKey           | String |              |                                                      |

## API Example

### Request

```
{
  "Header": {
    "Method": "31800",
    "ServiceType": "Settlement",
    "MchId": "myMchId",
    "TradeKey": "9af15b336e6a9619928537df30b2e6a2376569fcf9d7e773eccede65606529a0",
    "CreateTime": "20180715105152"
  },
  "Data": "{\"DeviceId\":\"01304187\",\"Retry\":\"0\"}"
}
```

### Response

```
{
  "Header": {
    "StatusCode": "0000",
    "StatusDesc": "STATUS_SUCCESS",
    "Method": "31800",
    "ServiceType": "Settlement",
    "MchId": "myMchId",
    "ResponseTime": "20180715105156"
  },
  "Data": {
    "TerminalTXNNumber": "105153",
    "HostSerialNumber": "105153",
    "TerminalID": "5B100DE00F97",
    "SettlementStatus": "0",
    "TxReserveAmount": 0,
    "TxTradeAmount": 20,
    "TxRefundAmount": 10,
    "TxCancelAmount": 0,
    "TxReserveCount": 0,
    "TxTradeCount": 2,
    "TxRefundCount": 1,
    "TxCancelCount": 0,
    "TXNResult": "Success",
    "Retry": "0",
    "ErrorCode": "000000",
    "NewAESKey": ""
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://intella.gitbook.io/scan2pay/api-specification/easycard-api/settlement.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
