Make WeChat Pay available to your shopper on WeChat Mini Program with an API only integration.
Requirements
Requirement | Description |
---|---|
Integration type | Make sure that you have built an API-only integration. |
Setup steps | Before you begin, add WeChat Pay Mini Program in your test Customer Area. |
Preparation
Before you can accept WeChat Pay payments in your Mini Program:
- Create a Mini Program account with WeChat.
-
Contact our Support Team or your implementation manager and provide your:
- Mini Program AppID
- Entity name
- Currency
These details are required to ensure that payments made with your Mini Program are settled to your Adyen account.
Overview of payment flow
The diagram shows the flow of a Mini Program payment.
Follow the steps below to enable Mini Program payments.
Make all calls to Adyen from your server, not from your Mini Program.
Step 1: Allow Adyen domains
Allow-list the following domains in your Mini Program settings:
https://[YOUR_MERCHANT_PREFIX]-checkout-live.adyenpayments.com
Find your merchant prefix
in the Customer Area, by selecting Developers > API URLs. Select the data center closest to your server.
Step 2: Get the user's openid
- Use wx.login() to get
jsCode
in the success callback. -
Use wx.request() to make the following call that returns the user's
openid
in the response:https://api.weixin.qq.com/sns/jscode2session?appid=${appId}&secret=${secret}&js_code=${jsCode}&grant_type=authorization_code
Parameter Description appID Available in your Mini Program Account. secret Available in your Mini Program Account. jsCode Obtained during the wx.login() call. grant_type Set to authorization_code.
Refer to the WeChat Mini Program Login documentation for a detailed flow.
Step 3: Make a payment request
-
Use the WeChat function wx.request() to make a request to your server.
-
Make a /payments request.
When the /payments request is received by Adyen, a POST request is automatically sent from Adyen to the WeChat Server to place the order and to get the
prepay_id
, which is required to execute wx.requestPayment() and to trigger the payment on WeChat.The value for
prepay_id
is returned as part of the /payments response, and is contained inredirect.data.package
.
- Use the WeChat function wx.requestPayment() to handle the redirect received in the /payments response.
Step 4: Check the payment result
When the shopper completes the payment:
-
Use wx.request() (also used in step 3) to check the payment result.
-
Make a /payments/details request.
The value for
paymentStatus
is returned inres.errMsg
and is one of these:- requestPayment:ok
- requestPayment:fail cancel
- requestPayment:fail (detail message)
Receive the /payments/details response.
Step 5: Show the payment result
Use the resultCode
that you received in the /payments/details response to present the payment result to your shopper.
The resultCode
values you can receive for WeChat Pay are:
resultCode | Description | Action to take |
---|---|---|
Authorised | The payment was successful. | Inform the shopper that the payment has been successful. You will receive the funds in 2-3 days. |
Error | There was an error when the payment was being processed. | Inform the shopper that there was an error processing their payment. The response contains a refusalReason , indicating the cause of the error. |
Pending or Received |
The payment order was successfully received. | Inform the shopper that you have received their order, and are waiting for the payment to clear. You will receive the final result of the payment in an AUTHORISATION webhook. If successful, you will receive the funds in 2 days. |
Refused | The payment was refused by the shopper's bank. | Ask the shopper to try the payment again using a different payment method. |
Test and go live
WeChat Pay does not have a test platform. If you have a personal WeChat account, test the following scenarios:
- Cancel the transaction when you are asked to verify the payment (recommended).
- Make a live WeChat Pay payment with a low value.
Check the status of a WeChat Pay payment in your Customer Area > Transactions > Payments.