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

# 電子發票查詢

{% hint style="danger" %}
**電子發票系統目前仍在測試中，尚未正式上線**
{% endhint %}

## 說明

查詢附屬於交易的電子發票資訊

## Request

### Header

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

### Data

| 欄位           | 必填  | 型別     | 型別                  | 型別        |
| ------------ | --- | ------ | ------------------- | --------- |
| StoreOrderNo | YES | String | 2018010110074205610 | 所要查詢的訂單編號 |

## Response

### Header

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

### Data

| 欄位          | 型別         | 範例       | 說明                       |
| ----------- | ---------- | -------- | ------------------------ |
| TerminalID  | String     | 09900000 | 發票印表機終端號碼                |
| PrinterID   | String     | 12340001 | 發票印表機裝置號碼                |
| InvoiceData | JSON       |          | 電子發票資訊 (請見下方InvoiceData) |
| Receipt     | JSON Array |          | 明細內容 (請見下方Receipt)       |
| Status      | String     |          | 訂單狀況                     |
| TakeNumber  | String     |          | 此API叫用次數(每呼叫一次累加一次)      |

#### InvoiceData

| 欄位             | 型別     | 範例            | 說明                 |
| -------------- | ------ | ------------- | ------------------ |
| Date           | String | 20190123      | 交易日期, 格式: yyyyMMdd |
| Time           | String | 135845        | 交易時間, 格式: HHmmss   |
| PosOrderNumber | String | mypo190123002 | 交易訂單號碼             |
| Term           | String | 10802         | 發票期別               |
| Number         | String | IT00030100    | 發票號碼               |
| Amount         | String | 100           | 未稅金額               |
| TaxAmount      | String | 5             | 稅金                 |
| TotalAmount    | String | 105           | 含稅總額               |
| BuyerID        | String | 43427600      | 買受方統編              |
| SellerID       | String | 54390300      | 賣方統編               |
| RandomNumber   | String | 6963          | 隨機碼                |
| Encrypt        | String |               |                    |
| CheckMacValue  | String |               |                    |

#### Receipt

矩陣內容

| 欄位           | 型別     | 範例    | 說明   |
| ------------ | ------ | ----- | ---- |
| RowNum       | String | 1     | 序號   |
| Description  | String | 總匯三明治 | 商品描述 |
| Quantity     | String | 2     | 數量   |
| UnitAmount   | String | 55    | 單價   |
| Amount       | String | 110   | 總價   |
| Unit         | String | 個     | 單位   |
| Remark       | String |       | 備註   |
| RelateNumber | String |       |      |

## API Example

### Request

```
{
  "Header": {
    "Method": "00000",
    "ServiceType": "InvoiceQuery",
    "MchId": "S2PT10000",
    "TradeKey": "9af15b336e6a9...6529a0",
    "CreateTime": "20190124163350"
  },
  "Data": "{\"StoreOrderNo\":\"mypo20190123002\"}"
}
```

### Response

```
{
  "Header": {
    "StatusCode": "0000",
    "StatusDesc": "執行成功",
    "ServiceType": "InvoiceQuery",
    "MchId": "S2PT10000",
    "ResponseTime": "20190124163351"
  },
  "Data": {
    "TerminalID": "12345678",
    "PrinterID": "12345678",
    "InvoiceData": {
      "Date": "20190123",
      "Time": "135845",
      "PosOrderNumber": "mypo190123002",
      "Term": "10802",
      "Number": "IT00030100",
      "Amount": "1",
      "TaxAmount": "0",
      "TotalAmount": "1",
      "BuyerID": "43427600",
      "SellerID": "54390300",
      "RandomNumber": "6963",
      "Encrypt": "dZA0OAoeOjXZQPoWLGKUeQ==",
      "CheckMacValue": ""
    },
    "Receipt": [
      {
        "RowNum": "1",
        "Description": "Food-8397",
        "Quantity": "1",
        "UnitAmount": "1",
        "Amount": "1",
        "Unit": "筆",
        "Remark": "None",
        "RelateNumber": "1"
      }
    ],
    "Status": "1",
    "TakeNumber": "9"
  }
}
```


---

# 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/invoice-query.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.
