> 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/refund.md).

# 卡片退款

Refund - 進行購貨退款

{% hint style="info" %}
此API為必要串接
{% endhint %}

## Request

### Header

| 欄位          | 必填  | 型別        | 範例             | 說明                   |
| ----------- | --- | --------- | -------------- | -------------------- |
| Method      | YES | String(5) | 31800          | 支付方式, 悠遊卡使用31800     |
| ServiceType | YES | String    | **Refund**     | 服務代碼                 |
| 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         |
| Amount       | YES | String | 10            | 退款金額, 必須與原訂單交易金額一致 |
| StoreOrderNo | YES | String | PO180101001   | 原交易的訂單編號           |
| RefundKey    | YES | String | sha256...hash | 退款密碼(sha256編碼)     |

## Response

### Header

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

### Data

| 欄位                   | 型別     | 範例               | 說明                                                   |
| -------------------- | ------ | ---------------- | ---------------------------------------------------- |
| **EZCardID**         | String | 934528053        | 卡號(隱碼)                                               |
| EZCardType           | String | 00               |                                                      |
| PersonalProfile      | String | 00               |                                                      |
| CardNumberForPrint   | String | 934528053        |                                                      |
| **Amount**           | String | 10               | 退款金額                                                 |
| **Balance**          | String | 4000             | 扣款後金額                                                |
| **BeforeTXNBalance** | String | 3990             | 扣款前金額                                                |
| TerminalTXNNumber    | String | 231741           |                                                      |
| HostSerialNumber     | String | 231741           |                                                      |
| Time                 | String | 231741           |                                                      |
| Date                 | String | 20180612         |                                                      |
| ExpiryDate           | String | 20191230         |                                                      |
| CPUPurseVersion      | String | 00               |                                                      |
| BankCode             | String | 00               |                                                      |
| AreaCode             | String | 01               |                                                      |
| AutoTopUpAmount      | String | 0                |                                                      |
| **TXNResult**        | String | Success          | 交易結果                                                 |
| Retry                | String | 0                |                                                      |
| ErrorCode            | String | 000000           | [交易結果代碼](/scan2pay/appendix/easycard-error-codes.md) |
| DongleDeviceID       | String | 08100DE0A57E     |                                                      |
| RRNumber             | String | 18061223174102   |                                                      |
| TXNType              | String | Refund           |                                                      |
| NewAESKey            | String | 38e5c9f5...b830  |                                                      |
| DeviceNumber         | String | 0830000001304104 |                                                      |
| request              | JSON   |                  |                                                      |

## API Example

### Request

```
{
  "Header": {
    "Method": "31800",
    "ServiceType": "Refund",
    "MchId": "myMchId",
    "TradeKey": "9af15b336e6a9619928537df30b2e6a2376569fcf9d7e773eccede65606529a0",
    "CreateTime": "20180715104821"
  },
  "Data": "{\"DeviceId\":\"01304187\",\"Retry\":\"0\",\"Amount\":\"10\",\"StoreOrderNo\":\"PO20180715005\",\"RefundKey\":\"9af15b336e6a9619928537df30b2e6a2376569fcf9d7e773eccede65606529a0\"}"
}
```

### Response

```
{
  "Header": {
    "StatusCode": "0000",
    "StatusDesc": "STATUS_SUCCESS",
    "Method": "31800",
    "ServiceType": "Refund",
    "MchId": "myMchId",
    "ResponseTime": "20180715104826"
  },
  "Data": {
    "EZCardID": "1917740208",
    "EZCardType": "08",
    "PersonalProfile": "00",
    "CardNumberForPrint": "1917740208",
    "Amount": "10",
    "Balance": "472",
    "BeforeTXNBalance": "462",
    "TerminalTXNNumber": "104822",
    "HostSerialNumber": "104822",
    "Time": "104822",
    "Date": "20180715",
    "ExpiryDate": "20250810",
    "CPUPurseVersion": "00",
    "BankCode": "32",
    "AreaCode": "01",
    "AutoTopUpAmount": "0",
    "request": {
      "Amount": "10",
      "Retry": "0",
      "BatchNumber": "18071511",
      "SameCard": "0",
      "ServiceType": "Refund",
      "TerminalID": "09900000",
      "DeviceID": "01304187",
      "TerminalTXNNumber": "104822",
      "HostSerialNumber": "104822",
      "Time": "104822",
      "Date": "20180715",
      "AESKey": "574660f677ee8314812ad829a6b48bf7"
    },
    "TXNResult": "Success",
    "Retry": "0",
    "ErrorCode": "000000",
    "DongleDeviceID": "5B100DE00F97",
    "RRNumber": "18071510482289",
    "TXNType": "Refund",
    "NewAESKey": "afdf360efd1b506300ad6a76229fd03f",
    "DeviceNumber": "0990000001304187"
  }
}
```
