> 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/jiao-yi-ding-dan-qu-xiao.md).

# 交易訂單取消

## 說明

取消 15 分鐘內交易中的訂單，超過 15 分鐘後需以[退款](/scan2pay/api-specification/refund.md)進行

## Request

### Header

| 欄位          | 必填  | 型別          | 範例              | 說明                                          |
| ----------- | --- | ----------- | --------------- | ------------------------------------------- |
| Method      | YES | String(5)   | 00000           | 請填入00000 (不指定支付方式)                          |
| ServiceType | YES | String(32)  | **CancelOrder** | 所選用的Scan2Pay服務代碼                            |
| MchId       | YES | String(32)  | Account0001     | 由intella所提供的特店帳號                            |
| TradeKey    | YES | String(128) | sha256...hash   | 由intella所提供的交易密碼, 此密碼須先經過SHA256加密，再進行Hex編碼。 |
| CreateTime  | YES | String(14)  | 20180101120000  | Request建立時間, 格式為yyyyMMddHHmmss              |

### Data

| 欄位           | 必填  | 型別         | 範例            | 說明                                    |
| ------------ | --- | ---------- | ------------- | ------------------------------------- |
| StoreOrderNo | YES | String(20) | PO180101001   | 原交易的訂單編號                              |
| RefundKey    | YES | String(32) | sha256...hash | 由intella所提供的退款密碼, 此密碼須先經過SHA256編碼後再填入 |

## Response

### Header

| 欄位           | 型別        | 範例              | 說明                                                   |
| ------------ | --------- | --------------- | ---------------------------------------------------- |
| StatusCode   | String(4) | 0000            | [交易結果代碼](/scan2pay/appendix/scan2pay-error-codes.md) |
| StatusDesc   | String    | 交易成功            | 交易結果代碼說明                                             |
| Method       | String(5) | 00000           | 支付方式代碼                                               |
| ServiceType  | String    | **CancelOrder** | 所選用的Scan2Pay服務代碼                                     |
| MchId        | String    | Account0001     | 特店帳號                                                 |
| ResponseTime | String    | 20180101120000  | 交易回應時間, 格式為yyyyMMddHHmmss                            |

### Data

| 欄位           | 型別         | 範例          | 說明     |
| ------------ | ---------- | ----------- | ------ |
| StoreOrderNo | String(20) | PO180101001 | 特店訂單編號 |

## API Example

### Request

```
{
  "Header": {
    "Method": "00000",
    "ServiceType": "CancelOrder",
    "MchId": "myMchId",
    "TradeKey": "9af15b336e6a9619928537df30b2e6a2376569fcf9d7e773eccede65606529a0",
    "CreateTime": "20180715102813"
  },
  "Data": "{\"StoreOrderNo\":\"PO-20180715-001\",\"RefundKey\":\"9af15b336e6a9619928537df30b2e6a2376569fcf9d7e773eccede65606529a0\"}"
}
```

### Response

```
{
  "Header": {
    "StatusCode": "0000",
    "StatusDesc": "執行成功",
    "Method": "00000",
    "ServiceType": "CancelOrder",
    "MchId": "myMchId",
    "ResponseTime": "20180715102816"
  },
  "Data": {
    "StoreOrderNo": "PO-20180715-001"
  }
}
```
