Take payments with WeChat Pay
This guide explains how to let users pay for your Casdoor products with WeChat Pay. Casdoor supports Native payment, with a QR code, and JSAPI payment, inside the WeChat app.
Learning outcomes
- Get the API key, the certificate, the IDs, and the WeChat Pay public key from WeChat Pay.
- Add WeChat Pay as a payment provider and add it to a product.
- Turn on payment inside the WeChat app.
What you need
- A WeChat Pay merchant account. See Preparation before access.
- A product in Casdoor
Get the credentials
-
On the WeChat Pay merchant platform, go to Account Settings > API Security > Set APIv3 Secret and copy the API key v3. See APIv3 key settings.

-
Go to Account Settings > API Security > API Certificate and download the merchant API certificate. The download contains the certificate
apiclient_cert.pemand its private keyapiclient_key.pem.
-
On the Certs page of Casdoor, add a cert. Paste the content of
apiclient_cert.peminto Certificate and the content ofapiclient_key.peminto Private key. Casdoor reads the serial number from the certificate. You can also put the serial number itself into Certificate.
-
Note your merchant ID and your App ID.
-
Find out how WeChat Pay signs its responses for your merchant account. Go to Account Settings > API Security:
- If the page has a WeChat Pay public key (微信支付公钥) section, your account uses the public key mode. New merchant accounts use this mode. Download the public key file
pub_key.pemand copy the public key ID, which starts withPUB_KEY_ID_. - If the page has a Platform certificate (平台证书) section and no public key, your account uses the platform certificate mode. You don't need anything else: Casdoor downloads the platform certificates with your merchant certificate.
- If the page has a WeChat Pay public key (微信支付公钥) section, your account uses the public key mode. New merchant accounts use this mode. Download the public key file
Add the provider in Casdoor
-
In the Casdoor admin console, go to Identity > Providers and add a provider.
-
Set Category to
Paymentand Type toWeChat Pay. -
Fill in the fields:
Casdoor field Public key mode Platform certificate mode Client ID Merchant ID Merchant ID Client secret API Key v3 API Key v3 App ID App ID App ID Public key ID The ID that starts with PUB_KEY_ID_Empty Cert The cert above The cert above Public key The content of pub_key.pemEmpty When both Public key ID and Public key are set, Casdoor verifies the responses of WeChat Pay with this public key. Otherwise it downloads the platform certificates, which fails with
RESOURCE_NOT_EXISTSfor an account in the public key mode.
-
Save the provider.
Add the provider to a product
Add the provider to the Payment providers of the product and save it.

Pay inside the WeChat app
For JSAPI payment, users sign in with WeChat in the built-in browser of the WeChat app and then pay there. Configure a WeChat OAuth provider for the same official account as the payment provider, and add both to the application.

Troubleshooting
| Error | Cause and fix |
|---|---|
RESOURCE_NOT_EXISTS when paying | The merchant account uses the public key mode and has no platform certificate. Fill in Public key ID and Public key. |
invalid header field value for Authorization | An older Casdoor version reads Certificate as the serial number, so the PEM breaks the request header. Upgrade Casdoor, or put the serial number of the merchant certificate into Certificate. |
SIGN_ERROR | The private key, the serial number, or the merchant ID don't belong together. Check that the cert holds the certificate and private key of this merchant. |