E-invoices
Issue electronic invoices through WeChat Pay for paid orders under your app. The seller is the platform company, and the invoice amount is the amount actually paid as recorded by the platform. Signing works the same as for payments.
E-invoicing must be enabled by the platform. Contact us before integrating.
Flow
- Your server calls Apply for an invoice.
- The user fills in the invoice title in WeChat.
- WeChat issues the invoice into the user's WeChat card wallet.
- The platform sends the result to your server as a callback.
Because the user must enter the title in WeChat, the whole flow is asynchronous.
Apply for an invoice
| Field | Required | Description |
|---|---|---|
| Common signing parameters | Yes | appId / timestamp / nonce / sign |
outTradeNo | Yes | Platform order number of a paid order |
merchantFapiaoNo | No | Your invoice request number, used as the idempotency key. Defaults to outTradeNo |
openid | Yes | The user's openid under the Official Account or mini-program |
source | No | MINIPROGRAM (default) or WEB |
sellerName | No | Seller name; defaults to the platform configuration |
extra | No | Pass-through field |
On success, data contains fapiaoApplyId, merchantFapiaoNo, outTradeNo, totalAmount (in fen, 1/100 CNY), miniprogramAppid, miniprogramPath, miniprogramUserName, expireIn (1800 seconds) and status (待填写抬头, awaiting title).
Use the miniprogram* values to open WeChat's invoicing mini-program so the user can enter the title. The link is valid for 30 minutes; call again with the same merchantFapiaoNo to get a new one.
Common errors: 订单不存在 (order not found), 订单未支付,不能开票 (order unpaid), openid不能为空 (openid required), source非法,仅支持WEB或MINIPROGRAM (invalid source).
Query an invoice
Parameters: the common signing parameters plus either fapiaoApplyId or merchantFapiaoNo. Only these are used for verification.
Returns invoice details including fapiaoApplyId, merchantFapiaoNo, outTradeNo, totalAmount (fen), status, statusCode, buyerType, buyerName, buyerTaxpayerId, fapiaoNumber, fapiaoCode, checkCode, fapiaoTime, fapiaoMediaUrl, failReason and extra.
| statusCode | Callback status | Meaning |
|---|---|---|
| 0 | CREATED | Awaiting invoice title |
| 1 | TITLE_SUBMITTED | Title submitted |
| 2 | ISSUE_ACCEPTED | Issuance accepted |
| 3 | ISSUED | Issued |
| 4 | FAILED | Failed |
| 5 | REVERSE_ACCEPTED | Reversal accepted |
| 6 | REVERSED | Reversed |
Reverse an invoice
| Field | Required | Description |
|---|---|---|
| Common signing parameters | Yes | |
fapiaoApplyId | Yes | Invoice request ID |
reverseReason | Yes | Reason for reversal |
Only ISSUED invoices can be reversed; otherwise the response is 仅已开票成功的发票可以冲红. Success returns {"fapiaoApplyId": "...", "status": "冲红已受理"} (reversal accepted); the final result arrives by callback.
Invoice callback
When an invoice becomes ISSUED, FAILED or REVERSED, the platform sends a JSON POST to your app's notifyUrl (the same URL as payment callbacks). Signing, retries and the 2xx requirement are identical to the payment callback.
| Field | Description |
|---|---|
appId, merchantFapiaoNo, fapiaoApplyId, outTradeNo | Identifiers |
status | Status enum, see the table above |
statusCode | Numeric status |
fapiaoNumber, fapiaoCode, checkCode, fapiaoTime | Present when issued |
failReason | Present when failed |
timestamp, nonce, sign | Same as payment callbacks |
Tell invoice callbacks from payment callbacks by the presence of fapiaoApplyId.