1. Obtain Invoicing Platform ID

2. Creating Invoice Card Templates

3. Uploading PDF Files

4. Querying Uploaded PDF Files

5. Adding E-Invoice Cards to the User's Cards & Offers

6. Updating Invoice Card Status

7. Invoice Status Update Event Push

8. Decrypting Code

9. Error Codes

10. List of Invoice Reimbursement Status


# 1. Obtain Invoicing Platform ID

API description

The invoicing platform can use this API to obtain its own pre-invoicing URL and then the s_pappid. The invoicing platform provides this s_pappid to merchants, who then use it to identify the invoicing platform in the Weixin e-Invoice solution.

Request method

Request URL: https://api.weixin.qq.com/card/invoice/seturl?access_token={access_token}

Request method: POST

Request parameters

The request parameters use JSON format and the provided data is empty, i.e. {}.

Response

The returned result is in JSON format and contains the following fields:

Parameter Type Required Description
errcode string Yes Error code
errmsg string Yes Error message
invoice_url string No The specific authorization link for this invoicing platform. The invoicing platform must provide the s_pappid in the invoice_url to the merchants it serves. When requesting authorization links, merchants will provide this parameter to Weixin to identify the invoicing platform they use.

Sample code

Request
{}
Response
{
	"errcode": 0,
	"errmsg": "ok",
	"invoice_url": "https://mp.weixin.qq.com/bizmall/authinvoice?action=list&s_pappid=d3xxxxxxxxxxxxxGLSS0wrL14No8c1"
}

# 2. Creating Invoice Card Templates

API description

Invoicing platforms can use this API to create a merchant invoice card template and configure the custom fields in the template. The creation of an invoice card template generates a card_id, which is used to reference the template. Invoice card templates are used as the basis of invoice card creation.

Request method

Request URL: https://api.weixin.qq.com/card/invoice/platform/createcard?access_token={access_token}

Request method: POST

Request parameters

The request parameters use JSON format and contain the following fields:

Parameter Type Required Description
invoice_info Object Yes The invoice template object

invoice_info is an Object and includes the following fields:

Parameter Type Required Description
base_info object Yes The basic information of the invoice card template
payee string Yes The full name of the payee (biller) displayed in the invoice details . We suggest using only one invoice card template for each payee.
type string Yes The invoice type

base_info is an Object and includes the following fields:

Parameter Type Required Description
logo_url string Yes The invoicing merchant's logo. For details, see Adding Permanent Assets.
title string Yes The payee, displayed in the list and limited to 9 Chinese characters (18 English characters). We suggest using the merchant's short name.
custom_url_name string No Invoicing platform's custom entry button title, which is used with the custom_url field. The length is limited to 5 Chinese characters (10 English characters).
custom_url string No The external redirection link of the invoicing platform's customer entry. The invoice external redirection link carries invoice parameters to identify the invoice the link came from.
custom_url_sub_title string No Tips shown to the right of the entry button, with a maximum length of 6 Chinese characters (12 English characters).
promotion_url_name string No Custom entry button to the promotional page
promotion_url string No The external redirection link of the entry. The invoice external redirection link carries invoice parameters to identify the invoice the link came from.
promotion_url_sub_title string No Tips shown to the right of the entry button, with a maximum length of 6 Chinese characters (12 English characters).

Response

The returned result is in JSON format and contains the following fields:

Parameter Type Required Description
errcode string Yes Error code
errmsg string Yes Error message
card_id string No The ID of the invoice card template returned when the error code is 0. When an invoice is generated for the merchant, this is a required parameter for calling the "Add Cards" API.

Sample code

Request:
{
	"invoice_info": {
		"base_info": {
			"logo_url": "http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0",
			"title": "xx company",
			"custom_url_name": "xyz",
			"custom_url": "xyz",
			"custom_url_sub_title": "xyz",
			"promotion_url_name": "puname",
			"promotion_url": "purl",
			"promotion_url_sub_title": "ptitle",
		},
		"type": " Guangdong VAT invoice ",
		"payee": " Test - Payee",
	}
}
Response:
{
	"errcode": 0,
	"errmsg": "ok",
	"card_id": "pjZ8Yt9WoOePThU0NfUKz5-tBEWU"
}

# 3. Uploading PDF Files

API description

The merchant or invoicing platform can call this API to upload PDF files. After the PDF file is successfully uploaded, the invoice file ID is obtained. This can subsequently be used with the "Add Card" API to link the PDF file with a user's invoice card and then add them to the user's Cards & Offers.

Note: If an uploaded PDF file is not linked with any invoice card and sent to the user's Cards & Offers within three days, it is erased. If the merchant or invoicing platform needs to link a PDF file with an invoice card after three days, they must upload it again.

Request method

Request URL: https://api.weixin.qq.com/card/invoice/platform/setpdf?access_token={access_token}

Request method: POST

Request parameters

The data format is multipart/form-data and uses the following parameters:

Parameter Required Description
pdf Yes The identifier of the media file in form-data, including the information such as filename, filelength, and content-type.

Response

The returned result is in JSON format and contains the following fields:

Parameter Type Required Description
errcode Int Yes Error code
errmsg String Yes Error message
s_media_id String Yes A 64-bit integer to link a PDF file with an invoice card for adding the invoice card to the user's Cards & Offers. s_media_id is valid for 3 days. If s_media_id is not linked with an invoice card within 3 days, the PDF file will be automatically deleted.

Sample code

Request:
 ------WebKitFormBoundary2exwM16BY25kVBgf Content-Disposition: form-data; name="pdf"; filename="1133090578170938.pdf" Content-Type: application/pdf Pdf content ------WebKitFormBoundary2exwM16BY25kVBgf—
Response:
{
	"errcode":0,
    "errmsg":"ok",
    "s_media_id":"3015806758683707"
}

# 4. Querying Uploaded PDF Files

API description

This API is used by merchants and invoicing platforms to query the invoices or proofs of purchase (in PDF) they have uploaded.

Request method

Request URL: https://api.weixin.qq.com/card/invoice/platform/getpdf?action=get_url&access_token={access_token}

Request method: POST

Request parameters

The request parameters use JSON format and contain the following fields:

Parameter Type Required Description
action String Yes Enter "get_url".
s_media_id string Yes The s_media_id of the invoice

Response

The returned result is in JSON format and contains the following fields:

Parameter Type Required Description
errcode Int Yes Error code
errmsg String Yes Error message
pdf_url String Yes The URL of the PDF file, which is valid for two hours.
pdf_url_expire_time Int Yes Validity period of the pdf_url (7200 sec)

Sample code

Request:
{
	"action": "get_url",
	"s_media_id": "75195574948725301"
}
Response:
{
	"errcode": 0,
	"errmsg": "ok",
	"pdf_url": "https://mp.weixin.qq.com/intp/invoice/getpdf?action=media_pdf&media_key=dFRnTkV6WCswNjB1V1czZ0tVU3MhaX4yb2pxeEVSY0teSCtuflY6UXAifD5rL09kTjFpOFVWKyJGNCgxTCtkJER6VjFlRCtVU2JKcS5FZw",
	"pdf_url_expire_time": 7200
}

# 5. Adding E-Invoice Cards to the User's Cards & Offers

API description

This API is called by invoicing platforms and self-deployed platform merchants. For users who have authorized invoicing requests, the invoicing platform can use this API to create invoice cards based on invoices and add them to the users' Weixin Cards & Offers.

Please note that, if the authorization page is triggered by a merchant and the card addition action is made by an invoicing platform, the merchant must send the ID of the invoice to be saved in Weixin Cards & Offers and the order_id to the invoicing platform in the invoice request.

Note: You must call this API using the invoicing platform Official Account appid that was used to call the "Obtain s_pappid" API. Otherwise, an error will occur and card addition will fail.

Request method

Request URL: https://api.weixin.qq.com/card/invoice/insert?access_token={access_token}

Request method: POST

Request parameters

The request parameters use JSON format and contain the following fields:

Parameter Type Required Description
order_id string Yes The invoice order_id, i.e., the order No. the merchant provides to the user who authorized invoicing.
card_id String Yes The invoice card_id
appid String Yes The appid used for the authorization for this order. It is generally the appid of the merchant.
card_ext Object Yes The specific content of the invoice

card_ext is an Object and includes the following content:

Parameter Type Required Description
nonce_str String Yes The random string used to prevent duplicates
user_card Object Yes A structured field of user information

user_card includes an invoice_user_data object, which contains the following content:

Parameter Type Required Description
fee Int Yes The amount of the invoice, in cents.
title String Yes The invoice title
billing_time Int Yes The invoicing time of the invoice, expressed as a 10-digit timestamp (utc+8).
billing_no String Yes The invoice number
billing_code String Yes The invoice code.
info List No The product details structure, explained below.
fee_without_tax Int Yes The amount excluding tax, in cents.
tax Int Yes The tax amount, in cents.
s_pdf_media_id String Yes After the invoice PDF file is uploaded to the Weixin Invoicing Platform, an invoice s_media_id is generated, which can be used to directly link the invoice PDF file with an invoice card. For information about uploading, see "[3. Uploading PDF Files] (#3)".
s_trip_pdf_media_id String No Other proofs of purchase (in PDF), such as itineraries and bank slips. For information about PDF file uploading, see "3. Uploading PDF Files".
check_code String Yes The verification code, in the upper-right corner of the invoice PDF file under the invoice issuance date.
buyer_number String No The buyer's taxpayer ID
buyer_address_and_phone String No The buyer's address and phone number
buyer_bank_account String No The buyer's bank and bank account
seller_number String No The seller's taxpayer ID
seller_address_and_phone String No The seller's address and phone number
seller_bank_account String No The seller's bank and bank account
remarks String No Remarks, in the lower-right corner of the invoice.
cashier String No The payee, in the lower-left corner of the invoice.
maker String No The invoicer, at the bottom of the invoice.

info is an Object list, and each Object in the list includes the following information:

Parameter Type Required Description
name String Yes The item name
num Int No The item quantity
unit String No The item unit
price Int Yes The item's unit price

Response

The returned result is in JSON format and contains the following fields:

Parameter Type Required Description
errcode Int Yes Error code
errmsg String Yes Error message
code String Yes The invoice code
openid String Yes The invoice user's openid
unionid String No This field only appears after the user links an Official Account to a Weixin Open Platform account.

Sample code

Request:
{
	"order_id": "111163",
	"card_ext": {
		"nonce_str": "j!Re1WxaHv",
		"user_card": {
			"invoice_user_data": {
				"info": [
					{
						"price": 10000,
						"num": 3,
						"name": "Toothpaste",
						"unit": "Tube"
					}
				],
				"billing_no": "4545145712",
				"billing_code": "4541212454512",
				"billing_time": "1468306058",
				"tax": 123,
				"s_pdf_media_id": "s_pdf_media_id_abc123",
				"fee": 123,
				"title": "Guan Ge's invoice",
				"fee_without_tax": 2345
				"buyer_number":"123456789012345678"
			}
		}
	},
	"card_id": "pjZ8Yt9WoOePThU0NfUKz5-tBEWU",
	"appid": "wxc0b84a53ed8e8d29"
}
Response:
{
	"errcode": 0,
	"errmsg": "ok",
	"code": "682xxxx661927",
	"openid": "ojZ8Ytz4lESxxxx_R1TvB2Kds"
}

# 6. Updating Invoice Card Status

API description

When the invoicing platform is aware of a change to invoice statuses (such as invoice offset or reimbursement), it must update the relevant invoice card statuses in users' Cards & Offers. This ensures the availability of the invoice card and avoids invalid reimbursement or repeated reimbursement.

This API is used by invoicing platforms to make updates in response to information from other channels or invoice reimbursement status changes. For information about the company reimbursement APIs, see the section on company e-invoice reimbursement.

In Weixin, invoice offset means to write off the invoice. To do this, call this API and set the invoice card status to "INVOICE_REIMBURSE_CANCEL".

For more information about the invoice status, see the list of invoice status.

Request method

Request URL: https://api.weixin.qq.com/card/invoice/platform/updatestatus?access_token={access_token}

Request method: POST

Request parameters

The request parameters use JSON format and contain the following fields:

Parameter Type Required Description
card_id String Yes The invoice ID
code String Yes The invoice code
reimburse_status String Yes The invoice reimbursement status

Response

The returned result is in JSON format and contains the following fields:

Parameter Type Required Description
errcode Int Yes Error code
errmsg String Yes Error message

Sample code

Request:
{
	"card_id": "pjZ8Yt7Um2jYxzneP8GomnxoVFWo",
	"code": "186921658591",
	"reimburse_status": "INVOICE_REIMBURSE_INIT"
}
Response:
{
	"errcode": 0,
	"errmsg": "ok"
}

# 7. Invoice Status Update Event Push

API description

After Weixin learns that users have submitted invoices for reimbursement, Weixin will push the invoice status change to the invoicing platform and merchant to ensure that all parties have the same invoice status. Invoicing platforms or self-deployed platform merchants can configure the time receiving URL to parse push event types and obtain status change messages.

The event will be sent to the URL entered by the developer in the Official Accounts Platform Developer Center, as shown below.

If the Weixin server does not receive the response within five seconds, the connection is broken and the request is initiated again. A maximum of three retries are made. We recommend that you use FromUserName + CreateTime to de-duplicate requests. If the merchant's server cannot ensure the request is processed within five seconds, it can return an empty string. When receiving the string, the Weixin server will not take any action or make a retry.

Response

The returned result is in XML format and contains the following fields:

Parameter Type Required Description
ToUserName String Yes The Official Account ID
FromUserName String Yes User's openid
CreateTime Int Yes Creation time of the event
MsgType String Yes Always set to "event".
Event String Yes Always set to "update_invoice_status"
Status String Yes The invoice reimbursement status
CardId String Yes The invoice ID
Code String Yes The invoice code

Sample code

<xml>
	<ToUserName><![CDATA[gh_9e1765b5568e]]></ToUserName>
	<FromUserName><![CDATA[ojZ8Ytz4lESgdWZ34L_R1TvB2Kds]]></FromUserName>
	<CreateTime>1478068440</CreateTime> <MsgType><![CDATA[event]]></MsgType>
	<Event><![CDATA[update_invoice_status]]></Event>
	<Status><![CDATA[INVOICE_REIMBURSE_INIT]]></Status>
	<CardId><![CDATA[pjZ8Yt7Um2jYxzneP8GomnxoVFWo]]></CardId>
	<Code><![CDATA[186921658591]]></Code>
</xml>

# 8. Decrypting Code

API description

To allow merchants to extend the invoice services, we support adding external redirect URL in the invoice page (promotion_url and custom_url in invoice creation), with the fields encrypt_code and card_id.

For example, if the specified URL is: http://www.qq.com, when A user taps the URL, the redirect URL is: http://www.qq.com?encrypt_code=ENCRYPT_CODE&card_id=CARDID.

encrypt_code is an encrypted code, which needs to be decoded to a real code with the decoding API. The real code is the same as the code returned by calling the "Add Cards" API.

Request method

Request URL: https://api.weixin.qq.com/card/code/decrypt?access_token={access_token}

Request method: POST

Request parameters

The request parameters use JSON format. Included parameters are as below:

Parameter Type Required Description
encrypt_code String Yes The encrypted invoice code in the suffix of an external URL that a user initiates access to from an invoice card, which directs to a specific invoice card.

Response

The returned result is in JSON format and contains the following fields:

Parameter Type Required Description
errcode Int Yes Error code
errmsg String Yes Error message
code String Yes The real invoice card code obtained via decryption

Sample code

Request:
{
	"encrypt_code":"XXIzTtMqCxwOaawoE91+VJdsFmv7b8g0VZIZkqf4GWA60Fzpc8ksZ/5ZZ0DVkXdE"
}
Response:
{
	"errcode":0,
	"errmsg":"ok",
	"code":"751234212312"
}

# 9. Error Codes

Error Code Error Message Description
0 OK Successful
72015 unauthorized create invoice No permission for this operation. Check whether you have activated the permission.
72017 invalid invoice title Inconsistent invoice title
72023 invoice has been lock The invoice has been locked by another Official Account. Generally, this means the invoice has entered a subsequent reimbursement process and the Official Account/OA Company Account/App of the reimbursing company has locked the invoice.
72024 invoice status error Incorrect invoice status
72025 invoice token error Invalid wx_invoice_token
72028 invoice never set pay mch info WeChat Pay merchant information is not set.
72029 invoice never set auth field Authorization fields not set
72030 invalid mchid Invalid mchid
72031 invalid params Parameter error. The request may contain an invalid parameter name or a parameter value that fails the verification of backend.
72035 biz reject insert Invoicing has been rejected for the invoice. If an order_id has been used as a parameter when calling the "Reject Invoicing" API, an error occurs when the order_id is used again to add the e-invoice to Cards & Offers.
72036 invoice is busy The invoice is being modified. Try again later.
72038 invoice order never auth No authorization granted for the order. There may be a mismatch among the invoicing platform appid, merchant appid, and order_id.
72039 invoice must be lock first The order has not been locked.
72040 invoice pdf error Invalid PDF. Provide an authentic and valid PDF.
72042 billing_code and billing_no repeated Duplicate invoice ID and code
72043 billing_code or billing_no size error Incorrect invoice ID and code
72044 scan text out of time The invoice title QR code timed out.
40078 invalid card status No authorization granted for the card_id. If this error is reported in a sandbox environment, the reason is that the Weixin account calling the API is not added to the test list. If this error is reported in an official environment, the possible reasons include: the Official Account calling the API has not activated the Cards & Offers permission; or the gap between the creation time of card_id and the time of adding the e-invoice to Cards & Offers is too small.

# 10. List of Invoice Reimbursement Status

Status Description
INVOICE_REIMBURSE_INIT Initial invoice status. Not locked.
INVOICE_REIMBURSE_LOCK Invoice locked
INVOICE_REIMBURSE_CLOSURE Invoice written off
INVOICE_REIMBURSE_CANCEL Invoice offset