No momento, esta página não está disponível em português
Payment-method icon

Mini Program for API-only

How to offer WeChat Pay through WeChat Mini Program with an API-only integration.

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:

  1. Create a Mini Program account with WeChat.
  2. 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.

CnNlcXVlbmNlRGlhZ3JhbQpwYXJ0aWNpcGFudCBXZUNoYXQgTWluaSBQcm9ncmFtCnBhcnRpY2lwYW50IE1lcmNoYW50IFNlcnZlcgpwYXJ0aWNpcGFudCBBZHllbgoKICAgIG5vdGUgb3ZlciBXZUNoYXQgTWluaSBQcm9ncmFtOiBVc2Ugd3gucmVxdWVzdCgpIHRvIG1ha2UgYSAvcGF5bWVudHMgcmVxdWVzdAogICAgV2VDaGF0IE1pbmkgUHJvZ3JhbS0+Pk1lcmNoYW50IFNlcnZlcjogRXhlY3V0ZSB3eC5yZXF1ZXN0KCkgLSBwYXNzIG9wZW5pZCwgY3VycmVuY3kgYW5kIHZhbHVlCiAgICBNZXJjaGFudCBTZXJ2ZXItPj5BZHllbjogSFRUUCBQT1NUIC9wYXltZW50cwogICAgQWR5ZW4tPj5NZXJjaGFudCBTZXJ2ZXI6IFBheW1lbnQgcmVzcG9uc2UKICAgIE1lcmNoYW50IFNlcnZlci0+PldlQ2hhdCBNaW5pIFByb2dyYW06IEZvcndhcmQgcmVzcG9uc2UgYmFjayB0byBtaW5pIHByb2dyYW0KICAgIG5vdGUgb3ZlciBXZUNoYXQgTWluaSBQcm9ncmFtOiBVc2Ugd3gucmVxdWVzdFBheW1lbnQoKSB0byBtYWtlIGEgL3BheW1lbnRzL2RldGFpbHMgcmVxdWVzdAogICAgV2VDaGF0IE1pbmkgUHJvZ3JhbS0+Pk1lcmNoYW50IFNlcnZlcjogRXhlY3V0ZSB3eC5yZXF1ZXN0UGF5bWVudCgpIC0gcGFzcyBwYXltZW50RGF0YSwgZGV0YWlscwogICAgTWVyY2hhbnQgU2VydmVyLT4+QWR5ZW46IEhUVFAgUE9TVCAvcGF5bWVudHMvZGV0YWlscwogICAgQWR5ZW4tPj5NZXJjaGFudCBTZXJ2ZXI6IFBheW1lbnQgZGV0YWlscyByZXNwb25zZQogICAgTWVyY2hhbnQgU2VydmVyLT4+V2VDaGF0IE1pbmkgUHJvZ3JhbTogRm9yd2FyZCByZXN1bHQgYmFjayB0byBtaW5pIHByb2dyYW0KICAgIG5vdGUgb3ZlciBXZUNoYXQgTWluaSBQcm9ncmFtOiBIYW5kbGUgcmVkaXJlY3QKICAgIG5vdGUgb3ZlciBXZUNoYXQgTWluaSBQcm9ncmFtOiBTaG93IHBheW1lbnQgcmVzdWx0CgogICAgQWR5ZW4tPj5NZXJjaGFudCBTZXJ2ZXI6IFdlYmhvb2sgYXV0aG9yaXNhdGlvbiBtZXNzYWdlIChhc3luY2hyb25vdXMpCgo=

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

  1. Use wx.login() to get jsCode in the success callback.
  2. 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

  1. Use the WeChat function wx.request() to make a request to your server.

  2. 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 in redirect.data.package.


  1. 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:

  1. Use wx.request() (also used in step 3) to check the payment result.

  2. Make a /payments/details request.

    The value for paymentStatus is returned in res.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.

See also