Airwallex logo

WeChat Mini Program

Accept WeChat Pay from your WeChat mini program, where you control and build the integration by yourself using WeChat Mini Program Payment API. Wechat - mini program

Step 1. Initialize a payment Intent

After the customer adds items into their cart and checkout, you should create a payment intent on your server-side. You will need to pass the id and client_secret in response to a mini-program for the customer to complete the payment. \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer your_bearer_token 
  -d '{
    "request_id": "ed11e38a-7234-11ea-aa94-7fd44ffd1b89",
    "amount": 100,
    "currency": "CNY",
    "merchant_order_id": "85d7b0e0-7235-11ea-862e-9f6aa1adfca6"
    "return_url": ""

Step 2. Accepting payments

When a customer selects Pay in WeChat mini program, you may call the following API endpoints to get the data which you need to call WeChat Mini program API (WeChat Mini program API ) from the response.

  • Obtain required mini program payment data to process payment
curl{id}/confirm \
  -H 'Content-Type: application/json' \
  -H 'client-secret: Ss3thJHPE6TyI4r-8BJFlqNz1mA7DblVuN0c8GOthnchp7Sf-_JuQnuX3sqzv7_0EiTMOs2kcGopFrMoFC0w7IzPCErJ1a0P7sFnpwB6uz-H2h_6rDhhSd2tKJF-l2myVOXQV4Zou3s_OsX6thLiUKI=" \
  -d '{
    "request_id": "ed11e38a-7234-11ea-aa94-7fd44ffd1b89",
    "payment_method": {
      "type": "wechatpay",
      "wechatpay": {
        "flow": "miniprog",
        "open_id": "xxxxxx"

Before confirming to pay with WeChat Pay in Mini Program, you need the open_id of the customer.

To get an open ID, follow below instructions:

  1. Invoke wx.login and then get a code from the response.
  2. Invoke jscode2session from server-side to get an open ID

After confirming, you will get next_action in response.

  "next_action": {
    "type": "call_sdk",
    "data": {
      "appId": "wxce926ea78004260e",
      "timeStamp": "1585294167",
      "nonceStr": "Ut3ZbuIY90JFUYtYtaoA6Ic6to1TS9oI",
      "package": "prepay_id=xxxxxxxx",
      "signType": "HMACSHA256",
      "paySign":  "D48E9B7B2CF14C1478E598872BCE52D509EE95B63D0933EAA419595560485589"
  • Pass the data to WeChat Mini Program Payment API

Pass data in next_action you get in the previous step to WeChat Mini Program Payment API wx.requestPayment . After the customer completes payment, WeChat will redirect the customer to your mini program and do a callback.

  • Wait for notification

Airwallex will notify you of the payment result asynchronously via webhook. Please refer to webhook documentation to configure your webhook accordingly. Although subscribing to different events is optional, it is recommended to subscribe to the ‘payment_intent.succeeded’ which indicates that the shopper has successfully paid for an order via WeChat Pay.

  • Query the PaymentIntent status (Optional)

You may also query the status of a payment anytime via the PaymentIntents API.

GET /payment_intents/{id}