Latest update time:2020.04.30 Release notes
1. The same notification may be sent to the merchant system for multiple times. The merchant system must be able to process repeated notifications properly. It is recommended that when a notification is received and processed, check the status of the corresponding business data first, and then analyze whether it is processed. If not, then process it; if yes, return the processed result. Before the status check and process of business data, perform concurrent control of these data with data locks to avoid data corruption caused by reentrant functions.
2. If the wechat pay callback is not received after all notification frequencies (4 hours), the merchant need to call the 【Query Order API】to confirm the order status.
Note: The merchant's system must perform signature verification for the payment result notification, and verify whether the returned order amount is consistent with that of the merchant side, to prevent any possible capital loss caused by "false notifications" due to data leakage.
Request URL: The URL is set by the notify_url parameter submitted in the [Order Placement API for QR Code Pay] and must use the https protocol. If the URL cannot be accessed, the merchant will not receive any WeChat notifications. The URL must be directly accessible without any parameters. For example: notify_url: http://pay.weixin.qq.com/wxpay/123456789
Request method: POST
Applicable object:Common modeInstitutional mode
API Rules: https://wechatpay-api.gitbook.io/wechatpay-api-v3
After the user completes the payment, WeChat will send both the payment result and the user information to the merchant. The merchant needs to receive and process the information, and return the successful response. Notification will only be sent if the payment is successful.
When notifying the interaction to the backend, if the response received by WeChat is unsuccessful or timeout, WeChat considers it as a notification failure and will send it again by following certain strategies to maximize the success rate, but WeChat does not guarantee a successful notification. (Notification frequency:15s/15s/30s/3m/10m/20m/30m/30m/30m/60m/3h/3h/3h/6h/6h - in total 24h4m)
For payment result notifications, access the notification URL set up by the merchant with the `POST` method, and the notification data is transmitted through the request body (BODY) in the `JSON` format. The notification data contains the details of the encrypted payment result.
The procedure of how to decrypt the notification data is described as follows.
1、Obtain APIv3 Secret from the merchant platform and record it as key.
2、For the algorithm described in `resource.algorithm` (which is AEAD_AES_256_GCM), obtain the corresponding `parameters nonce` and `associated_data`.
3、Decrypt the `resource.ciphertext` with `key`, `nonce`, and `associated_data` to obtain the resource object in JSON form.
Note: For the information on the API of the algorithm `AEAD_AES_256_GCM`, see rfc5116. The length of the `key` used for WeChat Pay is 32 bytes, the length of the random string `nonce` is 12 bytes, and the length of the `associated_data` is less than 16 bytes or may be zero.
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
Notification ID | id | string(32) | Yes | The unique notification ID Example:EV-2018022511223320873 |
Notification creation time | create_time | string(64) | Yes | Notification creation time, in RFC3339 format. For example, 2018-06-08T10:34:56+08:00 represents BJT 10:34:56 June 8, 2018. Example:2018-06-08T10:34:56+08:00 |
Notification type | event_type | string(32) | Yes | Notification type. The type of a successful payment notification is TRANSACTION.SUCCESS. Example:TRANSACTION.SUCCESS |
Notification data type | resource_type | string(32) | Yes | The type of the notification resource data. The type of resource data for a successful payment notification is encrypt-resource. Example:encrypt-resource |
+ Notification data | resource | object | Yes | Resource data of a notification |
Encryption does not guarantee that the notification request comes from wechat pay. Wechat pay will sign the notification sent to the merchant and put the signature value in the Wechatpay-Signature of Notification's HTTP header. The merchant should verify the signature to confirm that the request is from wechat pay, not other third parties. For the algorithm of signature verification, please refer to 【Wechat Pay API V3 Signature Scheme】
{
"id":"EV-2018022511223320873",
"create_time":"20180225112233",
"resource_type":"encrypt-resource",
"event_type":"TRANSACTION.SUCCESS",
"resource" : {
"algorithm":"AEAD_AES_256_GCM",
"ciphertext": "...",
"nonce": "...",
"associated_data": ""
}
}
List of decrypted resource objects:
{
"id": "1008450740201411110005820873",
"sp_appid": "wx2421b1c4370ec43b",
"sp_mchid": "10000100",
"sub_mchid": "20000100",
"out_trade_no": "20150806125346",
"payer": {
"sp_openid": "oUpF8uN95-Ptaags6E_roPHg7AG0"
},
"amount" : {
"total": 528800,
"currency": "HKD",
"payer_total": 518799,
"payer_currency": "CNY",
"exchange_rate" : {
"type": "SETTLEMENT_RATE",
"rate": 8000000
}
},
"trade_type": "MICROPAY",
"trade_state": "SUCCESS",
"trade_state_desc": "Payment successful",
"bank_type": "CCB_DEBIT",
"attach": "Payment test",
"success_time": "2018-06-08T10:34:56+08:00",
"promotion_detail":[
{
"promotion_id":"109519",
"name":"Single-item discount-6",
"scope":"SINGLE",
"type":"DISCOUNT",
"amount":1,
"currency":"HKD",
"activity_id":"931386",
"wechatpay_contribute_amount":1,
"merchant_contribute_amount":0,
"other_contribute_amount":0,
"goods_detail":[
{
"goods_id":"iphone6s_16G",
"goods_remark":"Product remarks",
"quantity":1,
"price":528800
}
]
}
]
}
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
Merchant ID | mchid | string(32) | Yes | Merchant ID assigned by WeChat Pay Note: Only forCommon mode Example:1900000109 |
APPID | appid | string(32) | Yes | APPID corresponding to the mobile app applied for by the merchant on the WeChat Open Platform Note: Only forCommon mode Example:wx8888888888888888 |
Institution's Merchant ID | sp_mchid | string(32) | Yes | Institution's Merchant ID assigned by WeChat Pay Note: Only forInstitutional mode Example:1900000100 |
Sub-merchant ID | sub_mchid | string(32) | Yes | Merchant ID assigned to sub-merchants by WeChat Pay Note: Only forInstitutional mode Example:1900000109 |
Organization APPID | sp_appid | string(32) | Yes | APPID corresponding to the Service Account applied for by the institution on the WeChat Official Accounts Platform Note: Only forInstitutional mode Example:wx8888888888888888 |
Contracted merchant APPID | sub_appid | string(32) | No | APPID corresponding to the mobile app applied for by the sub-merchant on the WeChat Open Platform Note: Only forInstitutional mode Example:wx8888888888888888 |
Merchant order No. | out_trade_no | string(32) | Yes | Returned merchant's order No. Example:1217752501201407033233368018 |
WeChat Pay order No. | id | string(32) | Yes | WeChat Pay order No. Example:1217752501201407033233368018 |
Merchant data | attach | string(127) | No | Additional data, which will be returned unchanged in the query API and payment notifications. This field is mainly used for the custom data in the orders of the merchant. Example:Custom data |
Transaction type | trade_type | string(16) | Yes | In-APP Pay Example:APP |
Paying bank | bank_type | string(32) | Yes | Bank type, which is the bank ID in string format. See Bank Type for the list of values. Example:CMC |
Payment completion time | success_time | string(64) | Yes | Payment completion time, in RFC3339 format. For example, 2018-06-08T10:34:56+08:00 represents BJT 10:34:56 June 8, 2018. Example:2018-06-08T10:34:56+08:00 |
Transaction status | trade_state | string(32) | Yes | SUCCESS: Payment successful REFUND: Transferred to refund NOTPAY: Unpaid CLOSED: Closed REVOKED: Revoked (Quick Pay) USERPAYING: Payment in progress PAYERROR: Payment failed (other reasons, for example, failed to be returned by the bank) Example:SUCCESS |
Transaction status description | trade_state_desc | string(256) | Yes | Descriptions on the current order status and instructions for the next operation. Example:Payment failed. Place another order and pay it again. |
+ Payer | payer | object | Yes | Payer information. For more information, see the description below. |
+Order amount | amount | object | Yes | Information on the order amount. For more information, see the description below. |
+ Scenario information | scene_info | object | No | The scenario information object. For more information, see the description below. |
+ Discount feature | promotion_detail | array | No | Discount feature info. For more information, see the description below. |
After the merchant's backend has properly processed the notification, HTTP status code 200 or 204 needs to be returned. No specific content is required for 204.If other HTTP status codes are returned, WeChat Pay will deem the notification as a failure, and will send the notification regularly by following the aforesaid policies.
Note:If the merchant's backend fails to process a response, WeChat Pay will record the response message. It is recommended to return in the following format.
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
Returned status code | code | string(32) | Yes | For more information, see the returned status code description below. Example:SUCCESS |
Returned message | message | string(256) | No | Returned message, which presents the cause of the error. Example:System error |
{
"code": "SYSTEM_ERROR",
"message": "System failure"
}
HTTP status code | code | message | Additional info |
---|---|---|---|
200 | SUCCESS | Processed successfully | |
200 | NOT_NOTIFY_ANY_MORE | The service was not successfully processed, but no further notification is required. | Merchant system overload protection. This status code is returned when no further notification from WeChat Pay system is required. The merchant needs to confirm the status of order via the Query Order API. |
204 | 204 HTTP status code. No specific content is required. | ||
400 | PARAM_ERROR | Invalid parameter | Invalid parameter |
400 | DECRYPT_ERROR | Decryption failed | Decryption failed |
401 | CHECK_SIGN_ERROR | Signature verification failed | Signature verification failed |
429 | FREQUENCY_LIMITED | The rate limit is exceeded. | The rate limit is exceeded. |
500 | BIZ_ERR_NEED_RETRY | Service error. Try again. | Service error. Try again. |
500 | SYSTEM_ERROR | System failure | System failure |
Customer Service Tel
Business Development
9:00-18:00
Monday-Friday GMT+8
Technical Support
WeChat Pay Global
ICP证