Payment Result Notification

Update Time:2025.01.07

Tips:

  • 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.

  • 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.


1. API intro

Applicable object: Common mode Institutional mode

Request URL: The URL is set by the parameter notify_url submitted in [Order Placement API] and the https protocol is required. 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

2. Notification Rules

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)

3. Notification Message

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.

4. Request Parameters

Name

Variable Name

Type

Required

Description

Notification ID

id

string[1,36]

Yes

The unique notification ID
Example: f7c34059-0f2d-5b32-ba33-a42dks0597c5

Notification creation time

create_time

string[1,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[1,32]

Yes

Notification type. The type of a successful payment notification is TRANSACTION.SUCCESS.
Example: TRANSACTION.SUCCESS

Notification data type

resource_type

string[1,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

Brief description of notice

summary

string[1,16]

Yes

Brief description of notice
Example: payment succeeded

Notification data

resource

object

Yes

Resource data of a notification

Notification data

5. Notification Signature

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》。

6. Callback Example

Payment Success Result Notification

1{
2	"id": "f7c34059-0f2d-5b32-ba33-a42dks0597c5",
3	"create_time": "2018-06-08T10:34:56+08:00",
4	"resource_type": "encrypt-resource",
5	"event_type":"TRANSACTION.SUCCESS",
6	"summary": "payment succeeded",
7	"resource": {
8		"algorithm": "AEAD_AES_256_GCM",
9		"ciphertext": "...",
10		"associated_data": "",
11		"nonce": "..."
12	}
13}

List of decrypted resource objects:

1{
2	"id": "1008450740201411110005820873",
3	"sp_appid": "wx2421b1c4370ec43b",
4	"sp_mchid": "10000100",
5	"sub_mchid": "20000100",
6	"out_trade_no": "20150806125346",
7	"payer": {
8		"sp_openid": "oUpF8uN95-Ptaags6E_roPHg7AG0"
9	},
10	"amount": {
11		"total": 528800,
12		"currency": "HKD",
13		"payer_total": 518799,
14		"payer_currency": "CNY",
15		"exchange_rate": {
16			"type": "SETTLEMENT_RATE",
17			"rate": 8000000
18		}
19	},
20	"trade_type": "MICROPAY",
21	"trade_state": "SUCCESS",
22	"trade_state_desc": "Payment successful",
23	"bank_type": "CCB_DEBIT",
24	"attach": "Payment test",
25	"success_time": "2018-06-08T10:34:56+08:00",
26	"promotion_detail": [{
27		"promotion_id": "109519",
28		"name": "Single-item discount-6",
29		"scope": "SINGLE",
30		"type": "DISCOUNT",
31		"amount": 1,
32		"currency": "HKD",
33		"activity_id": "931386",
34		"wechatpay_contribute_amount": 1,
35		"merchant_contribute_amount": 0,
36		"other_contribute_amount": 0,
37		"goods_detail": [{
38			"goods_id": "iphone6s_16G",
39			"goods_remark": "Product remarks",
40			"quantity": 1,
41			"price": 528800
42		}]
43	}]
44}

7. List of decrypted resource objects

Name

Variable Name

Type

Required

Description

Merchant ID

mchid

string[1,32]

Yes

Merchant ID assigned by WeChat Pay
Note: Only for Common mode
Example: 1900000109

APPID

appid

string[1,32]

Yes

APPID corresponding to the mobile app applied for by the merchant on the WeChat Open Platform
Note: Only for Common mode
Example: wx8888888888888888

Institution's Merchant ID

sp_mchid

string[1,32]

Yes

Institution's Merchant ID assigned by WeChat Pay
Note: Only for Institutional mode
Example: 1900000100

Sub-merchant ID

sub_mchid

string[1,32]

Yes

Merchant ID assigned to sub-merchants by WeChat Pay
Note: Only for Institutional mode
Example: 1900000109

Organization APPID

sp_appid

string[1,32]

Yes

APPID corresponding to the Service Account applied for by the institution on the WeChat Official Accounts Platform
Note: Only for Institutional mode
Example: wx8888888888888888

Contracted merchant APPID

sub_appid

string[1,32]

No

APPID corresponding to the mobile app applied for by the sub-merchant on the WeChat Open Platform
Note: Only for Institutional mode
Example: wx8888888888888888

Merchant order No.

out_trade_no

string[1,32]

Yes

Returned merchant's order No.
Example: 1217752501201407033233368018

WeChat Pay order No.

id

string[1,32]

Yes

WeChat Pay order No.
Example: 1217752501201407033233368018

Merchant data

attach

string[1,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[1,16]

Yes

In-APP Pay
Example: APP

Paying bank

bank_type

string[1,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[1,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[1,32]

Yes

SUCCESS: Payment successful
Note: Only orders with successful payment will push the payment result notification, so the return of this field is SUCCESS only
Example: SUCCESS

Transaction status description

trade_state_desc

string[1,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.

Payer

Order amount

amount

object

Yes

Information on the order amount. For more information, see the description below.

Order amount

Discount feature

promotion_detail

array

No

Discount feature info. For more information, see the description below.

Discount feature

8. Response Result

Response for successful request: The HTTP response status code needs to return 200 or 204, there's no need to return the response message.

Response for failed request:The HTTP response status code needs to return 5XX or 4XX, the response message needs to be returned.

The format is as follows:

Name

Variable Name

Type

Required

Description

Returned status code

code

string[1,32]

Yes

For more information, see the returned status code description below.
Example: SUCCESS

Returned message

message

string[1,256]

No

Returned message, which presents the cause of the error.
Example: System error

Scenario 1:Common mode

1200
2{
3	"code": "SUCCESS",
4	"message": "OK"
5}    

Scenario 2:Service Provide Mode/Institution Mode

1{
2    "code": "SYSTEM_ERROR",
3    "message": "ERROR"
4}

 

 

About  WeChat  Pay

Powered By Tencent & Tenpay Copyright©

2005-2025 Tenpay All Rights Reserved.

Contact Us
Wechat Pay Global

WeChat Pay Global

Contact Us

Customer Service Tel

+86 571 95017

9:00-18:00 Monday-Friday GMT+8

Business Development

wxpayglobal@tencent.com

Developer Support

wepayTS@tencent.com

Wechat Pay Global

About Tenpay
Powered By Tencent & Tenpay Copyright© 2005-2025 Tenpay All Rights Reserved.