taiwan-invoice-skill 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,452 @@
1
+ ---
2
+ name: taiwan-invoice
3
+ description: Taiwan E-Invoice API integration specialist for ECPay, SmilePay, and Amego. Use when developing invoice systems, implementing B2C/B2B invoice issuance, invoice printing, allowance creation, or working with Taiwan E-Invoice APIs. Handles encryption (AES, MD5), API requests, and service provider differences.
4
+ user-invocable: true
5
+ ---
6
+
7
+ # Taiwan E-Invoice Development Skill
8
+
9
+ > 此技能涵蓋台灣電子發票 API 整合開發,包含綠界 (ECPay)、速買配 (SmilePay)、光貿 (Amego) 三家服務商。
10
+
11
+ ## 快速導覽
12
+
13
+ ### 相關文件
14
+ 使用此技能時,請參考專案中的 API 規格文件:
15
+ - `references/ECPAY_API_REFERENCE.md` - 綠界 API 規格
16
+ - `references/SMILEPAY_API_REFERENCE.md` - 速買配 API 規格
17
+ - `references/AMEGO_API_REFERENCE.md` - 光貿 API 規格
18
+ - [EXAMPLES.md](EXAMPLES.md) - 程式碼範例集
19
+
20
+ ### 智能工具
21
+ - `scripts/search.py` - BM25 搜索引擎(查詢 API、錯誤碼、欄位映射)
22
+ - `scripts/recommend.py` - 加值中心推薦系統
23
+ - `scripts/generate-invoice-service.py` - 服務代碼生成器
24
+ - `data/` - CSV 數據檔(providers, operations, error-codes, field-mappings, tax-rules, troubleshooting)
25
+
26
+ ### 何時使用此技能
27
+ - 開發電子發票開立功能
28
+ - 整合台灣電子發票服務商 API
29
+ - 實作 B2C(二聯式)或 B2B(三聯式)發票
30
+ - 處理發票列印、作廢、折讓等功能
31
+ - 處理加密簽章(AES、MD5)
32
+ - 解決發票 API 整合問題
33
+
34
+ ## 智能搜索與推薦
35
+
36
+ ### 搜索引擎 (search.py)
37
+
38
+ 使用 BM25 算法在資料庫中搜索相關資訊:
39
+
40
+ ```bash
41
+ # 搜索加值中心
42
+ python scripts/search.py "ecpay" --domain provider
43
+
44
+ # 搜索錯誤碼
45
+ python scripts/search.py "10000016" --domain error
46
+
47
+ # 搜索欄位映射
48
+ python scripts/search.py "MerchantID" --domain field
49
+
50
+ # 搜索稅務規則
51
+ python scripts/search.py "B2B 稅額計算" --domain tax
52
+
53
+ # 搜索疑難排解
54
+ python scripts/search.py "列印空白" --domain troubleshoot
55
+
56
+ # JSON 輸出
57
+ python scripts/search.py "折讓" --format json
58
+ ```
59
+
60
+ **搜索域:**
61
+ | 域 | 說明 | CSV 檔案 |
62
+ |-----|------|----------|
63
+ | `provider` | 加值中心比較 | providers.csv |
64
+ | `operation` | API 操作端點 | operations.csv |
65
+ | `error` | 錯誤碼查詢 | error-codes.csv |
66
+ | `field` | 欄位映射 | field-mappings.csv |
67
+ | `tax` | 稅務計算規則 | tax-rules.csv |
68
+ | `troubleshoot` | 疑難排解 | troubleshooting.csv |
69
+
70
+ ### 推薦系統 (recommend.py)
71
+
72
+ 根據需求自動推薦最適合的加值中心:
73
+
74
+ ```bash
75
+ # 高交易量電商
76
+ python scripts/recommend.py "電商 高交易量 穩定"
77
+ # → 推薦 ECPay (市佔率高,穩定性佳)
78
+
79
+ # 快速整合需求
80
+ python scripts/recommend.py "簡單 快速 小型專案"
81
+ # → 推薦 SmilePay (整合最簡單)
82
+
83
+ # API 設計優先
84
+ python scripts/recommend.py "API 設計 MIG標準"
85
+ # → 推薦 Amego (MIG 4.0 最新標準)
86
+
87
+ # JSON 輸出
88
+ python scripts/recommend.py "穩定 文檔完整" --format json
89
+ ```
90
+
91
+ **推薦關鍵字:**
92
+ - **ECPay**: 穩定、市佔、文檔、SDK、高交易量、電商
93
+ - **SmilePay**: 簡單、快速、小型、測試、無加密、便宜
94
+ - **Amego**: API、設計、新、MIG、標準
95
+
96
+ ### 代碼生成器 (generate-invoice-service.py)
97
+
98
+ 自動生成服務商專用代碼:
99
+
100
+ ```bash
101
+ # 生成 TypeScript 服務
102
+ python scripts/generate-invoice-service.py ECPay --output ts
103
+
104
+ # 生成 Python 服務
105
+ python scripts/generate-invoice-service.py SmilePay --output py
106
+
107
+ # 輸出到檔案
108
+ python scripts/generate-invoice-service.py Amego --output ts > amego-service.ts
109
+ ```
110
+
111
+ ---
112
+
113
+ ## 發票類型
114
+
115
+ ### B2C 二聯式發票
116
+ - 買受人無統編
117
+ - `BuyerIdentifier` = `0000000000`
118
+ - 金額為**含稅價**
119
+ - 可使用載具或捐贈
120
+ - 示例:一般消費者購物
121
+
122
+ ### B2B 三聯式發票
123
+ - 買受人有 8 碼統編
124
+ - `BuyerIdentifier` = 實際統編(需驗證格式)
125
+ - 金額為**未稅價**,需另計稅額
126
+ - **不可**使用載具或捐贈
127
+ - 示例:公司採購
128
+
129
+ ## 各服務商特性比較
130
+
131
+ | 特性 | 綠界 ECPay | 速買配 SmilePay | 光貿 Amego |
132
+ |------|-----------|-----------------|------------|
133
+ | 測試/正式 URL | 不同 URL | 不同 URL | **相同 URL** |
134
+ | 認證方式 | AES 加密 + HashKey/HashIV | Grvc + Verify_key | MD5 簽章 + App Key |
135
+ | 列印方式 | POST 表單提交 | GET URL 參數 | API 取得 PDF URL |
136
+ | B2B 金額欄位 | SalesAmount (未稅) | UnitTAX=N | DetailVat=0 |
137
+ | 傳輸格式 | JSON (AES 加密) | URL Parameters | JSON (URL Encode) |
138
+
139
+ ## 開發實作步驟
140
+
141
+ ### 1. 服務實作架構
142
+
143
+ 創建服務時遵循以下結構:
144
+
145
+ ```typescript
146
+ // lib/services/invoice-provider.ts - 介面定義
147
+ export interface InvoiceService {
148
+ issueInvoice(userId: string, data: InvoiceIssueData): Promise<InvoiceIssueResponse>
149
+ voidInvoice(userId: string, invoiceNumber: string, reason: string): Promise<InvoiceVoidResponse>
150
+ printInvoice(userId: string, invoiceNumber: string): Promise<InvoicePrintResponse>
151
+ }
152
+
153
+ // lib/services/{provider}-invoice-service.ts - 各服務商實作
154
+ export class ECPayInvoiceService implements InvoiceService {
155
+ private async encryptData(data: any, hashKey: string, hashIV: string): Promise<string> {
156
+ // AES-128-CBC 加密實作
157
+ }
158
+
159
+ async issueInvoice(userId: string, data: InvoiceIssueData) {
160
+ // 1. 取得使用者設定
161
+ // 2. 準備 API 資料
162
+ // 3. 加密簽章
163
+ // 4. 發送請求
164
+ // 5. 解密回應
165
+ // 6. 回傳標準格式
166
+ }
167
+ }
168
+ ```
169
+
170
+ ### 2. 金額計算邏輯
171
+
172
+ **含稅總額 → 未稅金額 + 稅額:**
173
+
174
+ ```typescript
175
+ function calculateInvoiceAmounts(totalAmount: number, isB2B: boolean) {
176
+ if (isB2B) {
177
+ // B2B: 需分拆稅額
178
+ const taxAmount = Math.round(totalAmount - (totalAmount / 1.05))
179
+ const salesAmount = totalAmount - taxAmount
180
+ return { salesAmount, taxAmount, totalAmount }
181
+ } else {
182
+ // B2C: 含稅總額
183
+ return { salesAmount: totalAmount, taxAmount: 0, totalAmount }
184
+ }
185
+ }
186
+
187
+ // 範例
188
+ const amounts = calculateInvoiceAmounts(1050, true)
189
+ // { salesAmount: 1000, taxAmount: 50, totalAmount: 1050 }
190
+ ```
191
+
192
+ ### 3. 加密實作
193
+
194
+ **綠界 (ECPay) - AES 加密:**
195
+
196
+ ```typescript
197
+ import crypto from 'crypto'
198
+
199
+ function encryptECPay(data: object, hashKey: string, hashIV: string): string {
200
+ // 1. JSON 轉字串並 URL Encode
201
+ const jsonString = JSON.stringify(data)
202
+ const urlEncoded = encodeURIComponent(jsonString)
203
+
204
+ // 2. AES-128-CBC 加密
205
+ const cipher = crypto.createCipheriv('aes-128-cbc', hashKey, hashIV)
206
+ let encrypted = cipher.update(urlEncoded, 'utf8', 'base64')
207
+ encrypted += cipher.final('base64')
208
+
209
+ return encrypted
210
+ }
211
+
212
+ function decryptECPay(encryptedData: string, hashKey: string, hashIV: string): object {
213
+ const decipher = crypto.createDecipheriv('aes-128-cbc', hashKey, hashIV)
214
+ let decrypted = decipher.update(encryptedData, 'base64', 'utf8')
215
+ decrypted += decipher.final('utf8')
216
+
217
+ const urlDecoded = decodeURIComponent(decrypted)
218
+ return JSON.parse(urlDecoded)
219
+ }
220
+ ```
221
+
222
+ **光貿 (Amego) - MD5 簽章:**
223
+
224
+ ```typescript
225
+ function generateAmegoSign(data: object, time: number, appKey: string): string {
226
+ const dataString = JSON.stringify(data)
227
+ const signString = dataString + time + appKey
228
+ return crypto.createHash('md5').update(signString).digest('hex')
229
+ }
230
+ ```
231
+
232
+ ### 4. 服務商綁定
233
+
234
+ **關鍵:開立發票時必須記錄使用的服務商,列印時才能正確調用**
235
+
236
+ ```typescript
237
+ // 開立時儲存服務商
238
+ await prisma.financialRecord.update({
239
+ where: { id: recordId },
240
+ data: {
241
+ invoiceNo: result.invoiceNumber,
242
+ invoiceProvider: actualProvider, // 'ECPAY' | 'SMILEPAY' | 'AMEGO'
243
+ invoiceRandomNum: result.randomNumber, // **重要**:列印時需要
244
+ invoiceDate: new Date(),
245
+ }
246
+ })
247
+
248
+ // 列印時使用開立時的服務商
249
+ const service = record.invoiceProvider
250
+ ? InvoiceServiceFactory.getService(record.invoiceProvider)
251
+ : await InvoiceServiceFactory.getServiceForUser(userId)
252
+ ```
253
+
254
+ ### 5. 列印回應處理
255
+
256
+ 前端需根據回應類型處理:
257
+
258
+ ```typescript
259
+ // 後端回應格式
260
+ interface InvoicePrintResponse {
261
+ success: boolean
262
+ type?: 'html' | 'redirect' | 'form'
263
+ htmlContent?: string // 綠界
264
+ printUrl?: string // 速買配/光貿
265
+ formUrl?: string
266
+ formParams?: Record<string, string>
267
+ }
268
+
269
+ // 前端處理範例
270
+ if (result.type === 'html') {
271
+ const win = window.open('', '_blank')
272
+ win.document.write(result.htmlContent)
273
+ } else if (result.type === 'redirect') {
274
+ window.open(result.url, '_blank')
275
+ } else if (result.type === 'form') {
276
+ // 動態建立表單提交
277
+ const form = document.createElement('form')
278
+ form.method = 'POST'
279
+ form.action = result.formUrl
280
+ form.target = '_blank'
281
+ // ... 添加參數
282
+ form.submit()
283
+ }
284
+ ```
285
+
286
+ ## 常見問題排除
287
+
288
+ ### 問題 1: 開立發票失敗,錯誤訊息不明確
289
+
290
+ **診斷步驟:**
291
+ 1. 檢查 logger 輸出,查看 `raw` 欄位完整錯誤
292
+ 2. 確認環境變數(測試/正式)是否正確
293
+ 3. 驗證必填欄位是否完整
294
+
295
+ **綠界常見錯誤:**
296
+ - `10000006`: RelateNumber 重複 → 訂單編號已使用
297
+ - `10000016`: 金額計算錯誤 → 檢查 B2C/B2B 金額計算
298
+ - `10000019`: 打統編不可使用載具 → 移除 CarrierType
299
+
300
+ **速買配常見錯誤:**
301
+ - `-10066`: AllAmount 驗算錯誤 → 檢查是否傳入 TotalAmount
302
+ - `-10084`: orderid 格式錯誤 → 限制 30 字元
303
+ - `-10053`: 載具號碼錯誤 → 驗證手機條碼格式
304
+
305
+ **光貿常見錯誤:**
306
+ - `1002`: OrderId 已存在 → 使用唯一訂單編號
307
+ - `1007`: 金額計算錯誤 → 檢查 DetailVat 設定
308
+ - `1012`: 打統編發票不可使用載具或捐贈
309
+
310
+ ### 問題 2: 列印時顯示「查詢不到該發票」
311
+
312
+ **解決方案:**
313
+ 確認 `invoiceProvider` 欄位有正確儲存,列印時使用開立時的服務商。
314
+
315
+ ```typescript
316
+ // 正確:使用發票記錄中的服務商
317
+ const service = record.invoiceProvider
318
+ ? InvoiceServiceFactory.getService(record.invoiceProvider)
319
+ : await InvoiceServiceFactory.getServiceForUser(userId)
320
+
321
+ // 錯誤:使用使用者當前預設服務商
322
+ const service = await InvoiceServiceFactory.getServiceForUser(userId)
323
+ ```
324
+
325
+ ### 問題 3: B2B 發票金額錯誤
326
+
327
+ **各服務商金額欄位:**
328
+
329
+ ```typescript
330
+ // 綠界 ECPay
331
+ const b2bData = {
332
+ SalesAmount: 1000, // 未稅銷售額
333
+ TaxAmount: 50, // 稅額
334
+ TotalAmount: 1050, // 總計
335
+ ItemPrice: 100, // 商品單價(未稅)
336
+ ItemAmount: 1000, // 商品小計(未稅)
337
+ ItemTax: 50 // 商品稅額
338
+ }
339
+
340
+ // 速買配 SmilePay
341
+ const b2bData = {
342
+ AllAmount: '1050', // 含稅總額
343
+ SalesAmount: '1000', // 未稅銷售額(選填,但建議填)
344
+ TaxAmount: '50', // 稅額(選填)
345
+ UnitTAX: 'N', // **重要**:單價未稅
346
+ UnitPrice: '100', // 商品單價(未稅)
347
+ Amount: '1000' // 商品小計(未稅)
348
+ }
349
+
350
+ // 光貿 Amego
351
+ const b2bData = {
352
+ DetailVat: 0, // **重要**:0=未稅
353
+ SalesAmount: 1000, // 未稅銷售額
354
+ TaxAmount: 50, // 稅額
355
+ TotalAmount: 1050, // 總計
356
+ ProductItem: [{
357
+ UnitPrice: 100, // 商品單價(未稅)
358
+ Amount: 1000 // 商品小計(未稅)
359
+ }]
360
+ }
361
+ ```
362
+
363
+ ### 問題 4: 速買配列印空白
364
+
365
+ **原因:** 回傳 `method: 'GET'` 時錯誤使用 `type: 'form'`
366
+
367
+ **解決:**
368
+ ```typescript
369
+ // 正確
370
+ if (printData.method === 'GET' && printData.url) {
371
+ return { type: 'redirect', url: printData.url }
372
+ }
373
+
374
+ // 錯誤
375
+ return { type: 'form', url: printData.url, params: printData.params }
376
+ ```
377
+
378
+ ### 問題 5: 時間戳記逾時
379
+
380
+ **綠界錯誤 10000005:** 時間戳記超過 10 分鐘
381
+
382
+ **解決:**
383
+ ```typescript
384
+ // 確保使用當前時間戳
385
+ const timestamp = Math.floor(Date.now() / 1000)
386
+
387
+ // 光貿:誤差容許 ±60 秒
388
+ const time = Math.floor(Date.now() / 1000)
389
+ ```
390
+
391
+ ## 測試帳號
392
+
393
+ ### 綠界測試環境
394
+ ```
395
+ MerchantID: 2000132
396
+ HashKey: ejCk326UnaZWKisg
397
+ HashIV: q9jcZX8Ib9LM8wYk
398
+ URL: https://einvoice-stage.ecpay.com.tw
399
+ ```
400
+
401
+ ### 速買配測試環境
402
+ ```
403
+ Grvc: SEI1000034
404
+ Verify_key: 9D73935693EE0237FABA6AB744E48661
405
+ 測試統編: 80129529
406
+ URL: https://ssl.smse.com.tw/api_test/SPEinvoice_Storage.asp
407
+ ```
408
+
409
+ ### 光貿測試環境
410
+ ```
411
+ 統編: 12345678
412
+ App Key: sHeq7t8G1wiQvhAuIM27
413
+ 後台: https://invoice.amego.tw/
414
+ 測試帳號: test@amego.tw
415
+ 測試密碼: 12345678
416
+ ```
417
+
418
+ ## 開發檢查清單
419
+
420
+ 使用此清單確保實作完整:
421
+
422
+ - [ ] 實作 `InvoiceService` 介面
423
+ - [ ] 處理 B2C / B2B 金額計算差異
424
+ - [ ] 實作加密/簽章機制(AES 或 MD5)
425
+ - [ ] 儲存 `invoiceProvider` 欄位
426
+ - [ ] 儲存 `invoiceRandomNum`(列印時需要)
427
+ - [ ] 處理列印回應類型(html/redirect/form)
428
+ - [ ] 實作錯誤處理與 logger
429
+ - [ ] 測試環境驗證
430
+ - [ ] 處理載具與捐贈互斥邏輯
431
+ - [ ] 驗證統編格式(8 碼數字)
432
+
433
+ ## 新增服務商步驟
434
+
435
+ 1. 在 `lib/services/` 建立 `{provider}-invoice-service.ts`
436
+ 2. 實作 `InvoiceService` 介面的所有方法
437
+ 3. 在 `InvoiceServiceFactory` 註冊新服務商
438
+ 4. 在 `prisma/schema.prisma` 的 `InvoiceProvider` enum 新增選項
439
+ 5. 執行 `prisma migrate` 或 `prisma db push`
440
+ 6. 更新前端設定頁面(`app/settings/invoice/page.tsx`)
441
+ 7. 撰寫單元測試
442
+
443
+ ## 參考資料
444
+
445
+ 詳細 API 規格請查看 `references/` 目錄:
446
+ - [綠界 ECPay API 規格](./references/ECPAY_API_REFERENCE.md)
447
+ - [速買配 SmilePay API 規格](./references/SMILEPAY_API_REFERENCE.md)
448
+ - [光貿 Amego API 規格](./references/AMEGO_API_REFERENCE.md)
449
+
450
+ ---
451
+
452
+ 最後更新:2026/01/29
@@ -0,0 +1,41 @@
1
+ provider,code,message_zh,message_en,category,solution
2
+ ECPay,10000001,參數錯誤,Parameter error,通用,檢查必填欄位是否完整
3
+ ECPay,10000002,發票號碼重複,Duplicate invoice number,開立,使用不同的 RelateNumber
4
+ ECPay,10000003,特店編號錯誤,Invalid merchant ID,認證,確認 MerchantID 正確
5
+ ECPay,10000004,加密驗證失敗,Encryption verification failed,認證,檢查 HashKey/HashIV 和加密流程
6
+ ECPay,10000005,時間戳記逾時,Timestamp expired,認證,確保時間戳在 10 分鐘內
7
+ ECPay,10000006,RelateNumber 重複,Duplicate RelateNumber,開立,使用唯一的訂單編號
8
+ ECPay,10000007,發票不存在,Invoice not found,查詢,確認發票號碼正確
9
+ ECPay,10000008,發票已作廢,Invoice already voided,作廢,發票已被作廢無法重複操作
10
+ ECPay,10000009,發票已折讓,Invoice has allowance,作廢,需先作廢折讓才能作廢發票
11
+ ECPay,10000010,折讓金額超過發票金額,Allowance exceeds invoice amount,折讓,調整折讓金額
12
+ ECPay,10000011,買方統編格式錯誤,Invalid buyer identifier,開立,統編需為 8 碼數字
13
+ ECPay,10000016,金額計算錯誤,Amount calculation error,開立,檢查 SalesAmount + TaxAmount = TotalAmount
14
+ ECPay,10000018,載具與捐贈不可同時存在,Carrier and donation conflict,開立,二擇一
15
+ ECPay,10000019,打統編不可使用載具,B2B cannot use carrier,開立,移除載具設定
16
+ ECPay,10000020,打統編不可捐贈,B2B cannot donate,開立,設定 Donation=0
17
+ ECPay,6000015,買方識別碼資料不存在,Buyer identifier not found,開立,測試環境 B2B 需預先註冊統編
18
+ SmilePay,0,開立成功,Success,成功,
19
+ SmilePay,-1001,商家帳號缺少參數,Missing merchant parameters,認證,檢查 Grvc 和 Verify_key
20
+ SmilePay,-10011,查無商家帳號,Merchant not found,認證,確認帳號正確
21
+ SmilePay,-10012,尚未開放B2B功能,B2B not enabled,權限,聯繫速買配開通
22
+ SmilePay,-10013,尚未開放B2C功能,B2C not enabled,權限,確認使用測試環境 URL
23
+ SmilePay,-10033,B2C開立需再48hr內,B2C must issue within 48hr,開立,調整 InvoiceDate
24
+ SmilePay,-10034,B2B開立需再168hr內,B2B must issue within 168hr,開立,調整 InvoiceDate
25
+ SmilePay,-10066,商品總金額驗算錯誤,Amount calculation error,開立,確認 AllAmount = Sum(Amount)
26
+ SmilePay,-10071,無可用字軌,No available track,開立,聯繫速買配配置字軌
27
+ SmilePay,-10072,自訂發票編號重複,Duplicate data_id,開立,使用唯一的 data_id
28
+ SmilePay,-10084,自訂號碼格式錯誤,Invalid orderid format,開立,orderid 限 30 字元
29
+ SmilePay,-2008,發票目前狀態不允許執行該動作,Invalid invoice status,作廢,檢查發票狀態
30
+ Amego,0,成功,Success,成功,
31
+ Amego,1,參數錯誤,Parameter error,通用,檢查必填欄位
32
+ Amego,2,簽章驗證失敗,Signature verification failed,認證,檢查 MD5 簽章計算
33
+ Amego,3,時間戳記誤差過大,Timestamp error,認證,確保時間戳誤差在 ±60 秒內
34
+ Amego,4,統一編號不存在,Tax ID not found,認證,確認統編正確
35
+ Amego,5,訂單編號重複,Duplicate order ID,開立,使用唯一的 OrderId
36
+ Amego,100,發票號碼不存在,Invoice not found,查詢,確認發票號碼正確
37
+ Amego,101,發票已作廢,Invoice already voided,作廢,發票已被作廢
38
+ Amego,1002,OrderId 已存在,OrderId exists,開立,使用不同的訂單編號
39
+ Amego,1004,BuyerName 不可為空或無效值,Invalid BuyerName,開立,不可填 0/00/000/0000
40
+ Amego,1007,金額計算錯誤,Amount calculation error,開立,檢查金額計算邏輯
41
+ Amego,1012,打統編發票不可使用載具或捐贈,B2B cannot use carrier or donate,開立,移除載具和捐贈設定
@@ -0,0 +1,27 @@
1
+ field_name,description,ecpay_name,smilepay_name,amego_name,type,required_b2c,required_b2b,notes
2
+ merchant_id,商家代號,MerchantID,Grvc,invoice,String,Y,Y,ECPay 10碼 SmilePay 帳號 Amego 統編
3
+ order_id,訂單編號,RelateNumber,data_id,OrderId,String,Y,Y,不可重複 ECPay 50字 SmilePay 50字 Amego 40字
4
+ buyer_identifier,買方統編,CustomerIdentifier,Buyer_id,BuyerIdentifier,String,N,Y,8碼數字 無統編填空(ECPay/SmilePay)或0000000000(Amego)
5
+ buyer_name,買方名稱,CustomerName,Name/CompanyName,BuyerName,String,N,Y,B2C用Name B2B用CompanyName (SmilePay)
6
+ buyer_email,買方信箱,CustomerEmail,Email,BuyerEmailAddress,String,N,N,多組用分號區隔
7
+ buyer_phone,買方電話,CustomerPhone,Phone,BuyerTelephoneNumber,String,N,N,
8
+ buyer_address,買方地址,CustomerAddr,Address,BuyerAddress,String,N,N,
9
+ invoice_type,字軌類別,InvType,Intype,TaxType,String,Y,Y,ECPay: 07一般/08特種 SmilePay: 07/08 Amego: 1-4/9
10
+ tax_type,課稅別,TaxType,TaxType,TaxType,Number,Y,Y,1應稅 2零稅率 3免稅 9混合
11
+ sales_amount,銷售額,SalesAmount,AllAmount/SalesAmount,SalesAmount,Number,Y,Y,B2C含稅 B2B未稅
12
+ tax_amount,稅額,TaxAmount,TaxAmount,TaxAmount,Number,N,Y,B2C為0 B2B需計算
13
+ total_amount,總金額,TotalAmount,AllAmount,TotalAmount,Number,N,Y,SalesAmount + TaxAmount
14
+ carrier_type,載具類別,CarrierType,CarrierType,CarrierType,String,N,N,手機條碼: ECPay=3 SmilePay=3J0002 Amego=3J0002
15
+ carrier_id,載具編號,CarrierNum,CarrierID,CarrierId1,String,N,N,手機條碼以/開頭共8碼
16
+ donation,捐贈註記,Donation,DonateMark,NPOBAN,String,Y,N,ECPay/SmilePay: 0不捐1捐 Amego: 直接填愛心碼
17
+ love_code,愛心碼,LoveCode,LoveKey,NPOBAN,String,N,N,捐贈時必填 7碼
18
+ print,列印註記,Print,,,String,Y,N,ECPay專用 0不列印 1列印 B2B固定1
19
+ invoice_date,發票日期,InvCreateDate,InvoiceDate,InvoiceDate,String,N,N,ECPay可回溯6天 SmilePay B2C 48hr B2B 168hr
20
+ invoice_time,發票時間,,InvoiceTime,InvoiceTime,String,N,N,SmilePay/Amego專用 HH:MM:SS
21
+ item_name,商品名稱,ItemName,Description,Description,String,Y,Y,ECPay 100字 SmilePay 256字 Amego 256字
22
+ item_count,商品數量,ItemCount,Quantity,Quantity,Number,Y,Y,
23
+ item_price,商品單價,ItemPrice,UnitPrice,UnitPrice,Number,Y,Y,B2C含稅 B2B未稅
24
+ item_amount,商品小計,ItemAmount,Amount,Amount,Number,Y,Y,ItemCount * ItemPrice
25
+ item_unit,商品單位,ItemWord,Unit,Unit,String,N,N,6字以內
26
+ item_remark,商品備註,ItemRemark,Remark,Remark,String,N,N,40字以內
27
+ random_number,隨機碼,RandomNumber,RandomNumber,random_number,String,N,N,開立成功後回傳 列印時需要
@@ -0,0 +1,11 @@
1
+ operation,operation_zh,ecpay_b2c_endpoint,ecpay_b2b_endpoint,smilepay_endpoint,amego_endpoint,required_fields,notes
2
+ issue,開立發票,/B2CInvoice/Issue,/B2BInvoice/Issue,/SPEinvoice_Storage.asp,/json/f0401,"MerchantID,RelateNumber,Items,SalesAmount",B2C/B2B 端點不同(ECPay)
3
+ void,作廢發票,/B2CInvoice/Invalid,/B2BInvoice/Invalid,/SPEinvoice_Storage_Modify.asp?types=Cancel,/json/f0501,"InvoiceNo,InvoiceDate,Reason",SmilePay 需帶 CancelReason
4
+ allowance,開立折讓,/B2CInvoice/Allowance,/B2BInvoice/Allowance,/SPEinvoice_Storage_Allowance.asp,/json/g0401,"InvoiceNo,AllowanceAmount,Items",折讓金額不可超過發票金額
5
+ void_allowance,作廢折讓,/B2CInvoice/AllowanceInvalid,/B2BInvoice/AllowanceInvalid,/SPEinvoice_Storage_Modify.asp?types=CancelAllowance,/json/g0501,"AllowanceNo,Reason",
6
+ query,查詢發票,/B2CInvoice/GetIssue,,/SPEinvoice_Storage_Modify.asp,/json/invoice_query,RelateNumber|InvoiceNo,ECPay用RelateNumber 其他用InvoiceNo
7
+ print,列印發票,/Invoice/Print,/Invoice/Print,/SmilePayCarrier/InvoiceDetails.php,/json/invoice_file,"InvoiceNo,InvoiceDate",ECPay用POST表單 SmilePay用GET Amego回傳PDF URL
8
+ check_barcode,驗證手機條碼,/B2CInvoice/CheckBarcode,,,/json/barcode,CarrierNum|barCode,驗證載具是否有效
9
+ check_lovecode,驗證愛心碼,/B2CInvoice/CheckLoveCode,,,/json/barcode,LoveCode,驗證捐贈碼是否有效
10
+ notify,發票通知,/B2CInvoice/InvoiceNotify,,,/json/invoice_file,"InvoiceNo,Email",補寄發票通知
11
+ invoice_list,發票列表,,,,/json/invoice_list,"date_start,date_end",僅Amego支援
@@ -0,0 +1,4 @@
1
+ provider,display_name,auth_method,encryption,test_url,prod_url,test_merchant_id,test_hash_key,test_hash_iv,content_type,features,market_share,api_style
2
+ ECPay,綠界科技,AES-128-CBC,URL Encode + AES 加密,https://einvoice-stage.ecpay.com.tw,https://einvoice.ecpay.com.tw,2000132,ejCk326UnaZWKisg,q9jcZX8Ib9LM8wYk,application/json,完整文檔 | SDK 支援 | 高穩定性,高,RESTful JSON
3
+ SmilePay,速買配,URL Parameter,Verify_key 驗證,https://ssl.smse.com.tw/api_test,https://ssl.smse.com.tw/api,SEI1000034,9D73935693EE0237FABA6AB744E48661,,application/x-www-form-urlencoded,雙協定(GET/POST) | 簡單整合 | XML回應,中,Query String
4
+ Amego,光貿科技,MD5 Signature,JSON + MD5 簽章,https://invoice-api.amego.tw,https://invoice-api.amego.tw,12345678,sHeq7t8G1wiQvhAuIM27,,application/x-www-form-urlencoded,MIG 4.0 | 統編查詢 | PDF下載 | 測試正式共用URL,中,RESTful JSON
@@ -0,0 +1,9 @@
1
+ invoice_type,tax_type,tax_rate,sales_amount_formula,tax_amount_formula,total_amount_formula,item_price_type,validation_rule,example_total,example_sales,example_tax,notes
2
+ B2C,應稅,0.05,含稅總額,0,SalesAmount,含稅,"SalesAmount = TotalAmount, TaxAmount = 0",1050,1050,0,二聯式發票 稅額系統自動計算
3
+ B2B,應稅,0.05,"round(TotalAmount / 1.05)","round(TotalAmount - TotalAmount/1.05)",SalesAmount + TaxAmount,未稅,"SalesAmount + TaxAmount = TotalAmount",1050,1000,50,三聯式發票 需自行計算稅額
4
+ B2C,零稅率,0,含稅總額,0,SalesAmount,含稅,"TaxAmount = 0, 需填 ClearanceMark 和 ZeroTaxRateReason",1000,1000,0,外銷等零稅率情況
5
+ B2B,零稅率,0,未稅總額,0,SalesAmount,未稅,"TaxAmount = 0",1000,1000,0,
6
+ B2C,免稅,0,含稅總額,0,SalesAmount,含稅,"TaxAmount = 0",1000,1000,0,土地/農產品等免稅項目
7
+ B2B,免稅,0,未稅總額,0,SalesAmount,未稅,"TaxAmount = 0",1000,1000,0,
8
+ B2C,混合,0.05,應稅+免稅銷售額,僅應稅部分稅額,SalesAmount + FreeTaxSalesAmount + TaxAmount,含稅,需分別填 SalesAmount 和 FreeTaxSalesAmount,1050,950,50,混合應稅與免稅商品
9
+ B2B,特種稅率,0.25,未稅總額,"SalesAmount * TaxRate",SalesAmount + TaxAmount,未稅,"InvType=08, TaxType=4",1250,1000,250,特種飲食業 25% 稅率
@@ -0,0 +1,17 @@
1
+ issue,symptom,cause,solution,provider,category,severity
2
+ B2B發票開立失敗,回傳錯誤代碼 6000015,ECPay測試環境B2B需預先註冊統編,使用B2C API加統編 或在正式環境測試,ECPay,開立,HIGH
3
+ 金額驗算錯誤,AllAmount與商品小計不符,AllAmount使用了錯誤的來源欄位,B2C用SalesAmount B2B用TotalAmount: AllAmount=TotalAmount||SalesAmount,SmilePay,開立,HIGH
4
+ orderid格式錯誤,回傳-10084錯誤,訂單編號超過30字元限制,orderid限30字元 data_id可50字元防重複,SmilePay,開立,MEDIUM
5
+ 列印發票空白,彈窗開啟但內容空白,SmilePay用GET但系統用POST提交,判斷method 若為GET則用redirect開啟URL,SmilePay,列印,MEDIUM
6
+ B2C列印需隨機碼,列印失敗或顯示錯誤,未儲存開立時回傳的randomNumber,開立成功後儲存randomNumber到invoiceRandomNum欄位,SmilePay,列印,HIGH
7
+ 必填欄位遺漏,開立失敗 參數錯誤,FreeTaxSalesAmount ZeroTaxSalesAmount TaxRate等未填,即使為0也必須填入 TaxRate填"0.05",Amego,開立,HIGH
8
+ 隨機碼未儲存,列印時出錯,未儲存開立時回傳的random_number,開立成功後儲存randomNumber欄位,Amego,列印,HIGH
9
+ B2B金額計算錯誤,稅額不正確,未正確區分含稅/未稅價格,使用DetailVat區分: B2B=0未稅 B2C=1含稅,Amego,開立,HIGH
10
+ 列印錯誤服務商,查詢不到發票,用其他服務商的API查光貿開的發票,開立時儲存invoiceProvider 列印時優先使用,All,列印,HIGH
11
+ 加密驗證失敗,TransCode非1或code=2,HashKey/HashIV錯誤或加密流程問題,確認加密流程: URL Encode→AES-128-CBC(ECPay) 或 MD5簽章(Amego),ECPay/Amego,認證,HIGH
12
+ 時間戳逾時,10分鐘或60秒誤差,伺服器時間與本地時間不同步,使用API查詢伺服器時間 或同步本地時間,ECPay/Amego,認證,MEDIUM
13
+ 載具與捐贈衝突,不可同時存在,同時設定載具和捐贈,二擇一: 有載具則捐贈=0 有捐贈則載具為空,All,開立,MEDIUM
14
+ B2B不可使用載具,統編發票不可用載具,打統編發票設定了載具,B2B發票移除載具設定,All,開立,MEDIUM
15
+ B2B不可捐贈,統編發票不可捐贈,打統編發票設定了捐贈,B2B發票設定Donation=0,All,開立,MEDIUM
16
+ 發票已作廢,無法重複作廢,發票狀態已是作廢,檢查發票狀態後再操作,All,作廢,LOW
17
+ 折讓超過發票金額,折讓金額大於原發票,折讓總額累計超過發票金額,計算剩餘可折讓金額,All,折讓,MEDIUM