Skip to main content

Mobile App - WeChat Pay

Accept WeChat Pay on your mobile app on your shopper’s Android or iOS phone. You will need to integrate with the WeChat Pay mobile SDK.

Step 0. Authentication

How to obtain access token Authentication Reference

Step 1. Initialize a Payment Intent

When a shopper selects to pay with WeChat Pay, call the Payment Create API to get the data which will be passed to WeChat Pay SDK to invoke the WeChat Pay app.

POST /mch-api/v1/pa/payment_intents/create

  • Example Request
{
"amount": "1",
"currency": "HKD",
"merchant_order_id": "P9297895081903",
"payment_method": {
"type": "wechat",
"wechat": {
"sub_appid": "wxce926ea78004260e",
"flow": "mobile_app"
}
},
"description": "App Payment",
"notify_url": "https://put_your_site_here/example_url"
}
  • Request
REQUEST BODYDetailsTypeRequiredExample
amountPayment amount. This is the order amount you would like to charge your customerstring(32)required
currencyAmount currencystring(32)requiredTWD
settlement_currencyUsing this settlement currency in this order. If not set, we will using default settlement currencystring(3)optionalHKD
merchant_order_idThe order ID created in merchant's order system that corresponds to this PaymentIntent. Maximum length is 32.string(32)required
descriptionThe description of the orderstringrequired
notify_urlThe URL that is used to receive the payment result notification from CBTISstringoptional

You will get a response similar to the following.

{
"code": 0,
"data": {
"order_id": "C991289984923795789123",
"merchant_order_id": "P9297895081903",
"amount": "1",
"currency": "HKD",
"create_time": "2023-08-31T04:44:05.928696203+08:00",
"next_action": {
"type": "call_sdk",
"data": {
"appId": "wxce926ea78004260e",
"partnerId": "subMerchantId",
"prepayId": "wx07175429162447bc24fd2df6d4303c0000",
"package": "Sign=WXPay",
"nonceStr": "GMRIbt9xxgPhNfRlhLnijtXaYbIX8yMA",
"timeStamp": "1585293957",
"sign": "qK9sPC5sjcsxfxpRDhpUpJqLcI1tI9eirUzEpseqVITdVHbSwAs5g78rMOPkhQVtfbh8THa3pxhUyEGP5XE7UB2gcUecMdwm2aiWoypsHJuPZAVnmGzPm4kMgj5n61XRiZcTlFAyovaztgno3T5cIDTfr0t3HQEVxo1n6vFVp4O4XLpRJ6KSLckEFSaHN27GdSh91chaZL7SpEY1KlrvykyO0Wt6/HPU+RZNIIKH3S1bRwoV5ZrQZmwELDj7TLKK0mK32z8SA6guLp2geqz45KziUWzIqA51ZM7YUZP5TPRxBu1XqTqZe5RzRIAn9SDhA7DbqDk0pgoiK5g=="
}
},
"status": "PENDING"
},
"message": "ok",
"rid": "3647575c0e1049439e484a231864da2c"
}

Pass what you get in the previous step to the WeChat Pay mobile SDK by following the WeChat Pay official integration guide . After the shopper completes the payment, WeChat will redirect the shopper to your app and do a callback.

Step 2. Get payment notify

Once you fill in the notify_url field when creating an order, after the user completes the payment, our system will prompt you with information about the user's completed payment.

How to verify our notify message Webhook Verify Reference

  • Example Webhook
{
"notify_type": "payment_success",
"data": {
"order_id": "C991289984923795789123",
"merchant_order_id": "P9297895081903"
}
}

Step 3. Retrieve a payment

Retrieve a Refund by ID.

POST /mch-api/v1/pa/payment_intents/query

  • Example Request
{
"order_id": "P991289984923795789123",
"merchant_order_id": "P9297895081903"
}
  • Request
REQUEST BODYDetailsTypeRequiredExample
order_idPlatform order id from payment request.string(32)conditional (required if merchant_order_id is empty)
merchant_order_idMerchant order id from your creation of payment.string(32)conditional (required if order_id is empty)
  • Example Response
{
"code": 0,
"data": {
"order_id": "C991289984923795789123",
"merchant_order_id": "P9297895081903",
"amount": "50",
"currency": "TWD",
"status": "SUCCEEDED",
"create_time": "2023-08-31T04:44:05.928696203+08:00",
"pay_time": "2023-08-31T04:44:05.928696203+08:00"
},
"message": "ok",
"rid": "3647575c0e1049439e484a231864da2c"
}
  • Explain of status
STATUS CODEDetails
PENDINGThe Payment is pending the final result from the provider. No further action is required.
SUCCEEDEDThe Payment has succeeded. The payment transaction is complete.
CANCELLEDPayment canceled or timeout, user has not completed the payment and the order has been closed.