Application Scenarios
If the API request is successful, a URL will be returned (InvoiceHtml). Place this URL into the address bar of a browser, and the e-invoice will be displayed, which could be printed or to be saved in image or in PDF file.
API URLs:
- Stage: https://einvoice-stage.ecpay.com.tw/B2CInvoice/InvoicePrint
- Production: https://einvoice.ecpay.com.tw/B2CInvoice/InvoicePrint
HTTPS format
- Content Type :application/json
- HTTP Method :POST
Request by Merchant (Json format)
PlatformID String(10)
- This parameter is specifically designed for platform vendors collaborating with ECPay. It can only be utilized after applying for and activating the service.
- If you are a general vendor, please leave the PlatformID empty.
- When using this parameter, the MerchantID must be filled in with the specific store code bound to your PlatformID to prevent operation failures.
- Please note that only the MerchantID of a bound sub-merchant can be used to avoid operational failures. For binding operations, please contact your business representative.
MerchantID String(10)
Required
RqHeader Object
Required
Request header
Timestamp Number
Required
- Please convert the transmission time to a timestamp (GMT+8).
- ECPay will use this parameter to convert the current time to Unix TimeStamp to verify the time interval of this connection.
Special Notes:
- If ECPay receives the API call more than 10 minutes after the timestamp sent by merchants, this request will fail. Reference information is as follows:http://www.epochconverter.com/。
- Merchants are advised to frequently synchronize their server’s time to the nearest time zone server.
Data String
Required
- Message payload
- This is the encrypted data in JSON format.
AES Encryption Description
Example
{
"MerchantID": "2000132",
"RqHeader": {
"Timestamp": 1525168923
},
"Data": "..."
}
Message payload of Data (JSON format): please urlencode the JSON string first and then do AES encryption
MerchantID String(10)
Required
InvoiceNo String(10)
Required
- The e-invoice numbers
- The data includes 2 letter track alphabets (i.e. InvoiceHeader) and 8 digits.
InvoiceDate String(20)
Required
- Date of e-invoice created
- Format: yyyy-MM-dd
PrintStyle Int
- The formatting of e-invoice (i.e. how you want the e-invoice to be printed.)
- Values including:
1: single-sided printing (default).
2: double-sided printing.
3: printing with thermal paper.
4: B2B A4 (Only invoices with Tax ID Number can be used)
5: B2B A5 (Only invoices with Tax ID Number can be used)
IsReprintInvoice String(1)
Y:Display as “電子發票證明聯補印”
Special Notes:
The parameter [PrintStyle] for invoice print format is effective only when set to:
1. Standard Print (Single-sided), default
2. Standard Print (Double-sided)
3. Thermal Paper Print
This parameter has no effect on B2B invoice formats, which do not support reprinting.
If this parameter is omitted or `[PrintStyle]` is set to 4 or 5, it will uniformly display as “電子發票證明聯”
Any value other than “Y” is considered equivalent to omitting this parameter.
IsShowingDetail Int
1:Show details
2:Hide details
Special Notes:
- Invoices with TaxNumber will always show the details and will not refer to the setting of this parameter.
- If this parameter is not set, invoices “with TaxNumber” will “show” details by default, and invoices “without TaxNumber” will “not show” details by default
- When [PrintStyle] is B2B A4 or B2B A5, all details will be shown and will not refer to the setting of this parameter.
Example
{
"MerchantID": "2000132",
"InvoiceNo": "UV11100016",
"InvoiceDate": "2018-10-28"
}
Response format
- Content Type :application/json
- HTTP Method :POST
Response by ECPay (Json format)
PlatformID String(10)
MerchantID String(10)
Required
Response header
Timestamp Number
Unix timestamp(GMT+8)
TransCode Int
- Response code to indicate whether the payload is successfully accepted
- Possible values:
1: Payload (i.e. MerchantID, RqHeader, and Data) is successfully accepted by ECPay.
Others: failed.
TransMsg String(200)
Response message to indicate whether the payload is successfully accepted
Data String
- Message payload
- Respond with relevant data, this is the encrypted JSON format data
AES Encryption Description
Example
{
"MerchantID": "2000132",
"RpHeader": {
"Timestamp": 1525169058
},
"TransCode": 1,
"TransMsg": "",
"Data": "..."
}
Message payload of Data (JSON format): please do AES decryption to the Data first and then perform urldecode
RtnCode Int
- Return codes to indicate whether the API is successfully executed or not.
- Possible values:
1: API is successfully executed.
Others: failed.
RtnMsg String(200)
Return messages indicating whether the API is successfully executed or not.
InvoiceHtml String(500)
The URL is valid for 1 hour from the time of calling this print API
Example
{
"RtnCode": 1,
"RtnMsg": "成功",
"InvoiceHtml": "https://aa.aa.aa"
}
YAML
The provided YAML file is used to define the configuration, structure, operations, and infrastructure management information of the API, making it easier for developers to understand and use the API.
openapi: 3.1.0
info:
title: ECPay Invoice Print API
version: 1.0.0
servers:
- url: https://einvoice-stage.ecpay.com.tw
description: Testing Environment
- url: https://einvoice.ecpay.com.tw
description: Production Environment
paths:
/B2CInvoice/InvoicePrint:
post:
summary: Invoice Print
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- MerchantID
- RqHeader
- Data
properties:
PlatformID:
type: string
maxLength: 10
description: Platform ID for partnered platforms
MerchantID:
type: string
maxLength: 10
description: Merchant ID
RqHeader:
type: object
required:
- Timestamp
properties:
Timestamp:
type: integer
description: Unix timestamp (GMT+8)
Data:
type: string
description: Encrypted data containing request details
responses:
'200':
description: Successful Response
content:
application/json:
schema:
type: object
properties:
PlatformID:
type: string
maxLength: 10
description: Platform ID for partnered platforms
MerchantID:
type: string
maxLength: 10
description: Merchant ID
RpHeader:
type: object
properties:
Timestamp:
type: integer
description: Unix timestamp (GMT+8)
TransCode:
type: integer
description: Transmission code
TransMsg:
type: string
maxLength: 200
description: Transmission message
Data:
type: string
description: Encrypted data containing response details
components:
schemas:
requestBody.Data:
type: object
required:
- MerchantID
- InvoiceNo
- InvoiceDate
properties:
MerchantID:
type: string
maxLength: 10
description: Merchant ID
InvoiceNo:
type: string
maxLength: 10
description: Invoice number
InvoiceDate:
type: string
description: Invoice issue date in 'yyyy-MM-dd' or 'yyyy/MM/dd' format
PrintStyle:
type: integer
description: Print style (1 is single-sided, 2 is double-sided, 3 is thermal, 4 is B2B A4, 5 is B2B A5)
IsShowingDetail:
type: integer
description: Show details (1 is Yes, 2 is No)
responses.Data:
type: object
properties:
RtnCode:
type: integer
description: Response code
RtnMsg:
type: string
maxLength: 200
description: Response message
InvoiceHtml:
type: string
description: URL for invoice print (valid for 1 hour)