# WeChat Pay

https://docs.wisecp.com/en/wechat-pay-module

Let clients pay by scanning a WeChat Pay QR code on your site, and close the invoice as soon as WeChat Pay confirms the payment.

## Reaching the Screen

Go to **Settings → Financial → Payment Gateways**, open **All Modules** and click the WeChat Pay card: `{admin}/modules/payment?module=WeChatPay`

Tick **Status** and save to list the method on the payment step as **Pay with WeChat Pay**. Use [Payment Gateways](https://docs.wisecp.com/en/payment-modules) to order the methods clients see.

## What Is on the Screen

The card holds your merchant numbers, the keys that sign and verify every message, the payment window and the shared gateway settings.

On the payment step the client clicks **Show the WeChat Pay Code** and scans the QR code with the WeChat app. The page continues on its own once the payment is confirmed.

WeChat Pay has no saved cards and no subscriptions. Every invoice is paid with a new code.

## Before You Configure It

- A WeChat Pay merchant account on API v3 and an APPID bound to its merchant number.
- Your merchant API certificate, the APIv3 key and the WeChat Pay public key, all under **Account Center → API Security** in the merchant platform.
- Invoices in Chinese yuan. For any other currency, set **Converting Currency** to CNY.
- A site served over HTTPS. WeChat Pay accepts only an HTTPS notification address.

## Fields

- **Status**: Turns the module on. While it is off the other fields stay locked and clients are never offered the method.
- **Merchant ID**: Required. Your merchant number, shown under Account Center → Merchant Information.
- **App ID**: Required. The official account, mini program or open platform APPID bound to the merchant number.
- **Merchant Certificate Serial**: Required. The serial of your merchant API certificate, not the platform certificate.
- **Merchant Private Key**: Required. The whole content of apiclient_key.pem, including the BEGIN and END lines.
- **APIv3 Key**: Required. The 32-character key set under API Security. Notifications are encrypted with it.
- **WeChat Pay Public Key ID**: Required. The PUB_KEY_ID_ value, or the certificate serial if you still use a platform certificate.
- **WeChat Pay Public Key**: Required. The downloaded public key, or a platform certificate, pasted whole.
- **Payment Window (Minutes)**: How long the code stays payable, from 5 to 120 minutes. The default is 120.
- **Use Backup Domain**: Sends requests to WeChat Pay's backup host, for when the main host is unreachable from your server. Off by default.

Saving with **Status** ticked checks the credentials. An empty field, an APIv3 key that is not 32 characters or an unreadable key stops the save with a message.

For commission, currency conversion, amount and country limits, see [Payment Configuration](https://docs.wisecp.com/en/payment-modules). **Callback URL**, **Success URL** and **Failed URL** cannot be edited. Each order carries its notification address, so there is nothing to register in the merchant platform.

## Tasks

### Connect your merchant account

1. Collect the merchant number, APPID, certificate serial, private key, APIv3 key and public key from the merchant platform.
2. Open the WeChat Pay card under **All Modules** and tick **Status**.
3. Fill in every field. Paste the two keys whole, including their BEGIN and END lines.
4. Click **Save Changes**. Once the keys pass the check, the method appears on the payment step.

### Run a first payment

1. Place a small order in CNY as a client and choose **Pay with WeChat Pay**.
2. Click **Show the WeChat Pay Code**, then scan the code in WeChat and pay.
3. The page continues on its own, and the invoice is marked as paid. Refund the payment afterwards if it was only a test.

### Refund a payment

1. Open the invoice from [Invoice Detail](https://docs.wisecp.com/en/invoice-detail-overview).
2. Under **Summary → Change Status**, select **Refunded** and **Refund via payment gateway**. Click **Update Status**.
3. WeChat Pay returns the order amount, and the invoice is marked as refunded.

WeChat Pay accepts up to 50 refunds per payment, at least one minute apart. Repeating the same invoice's refund does not send it twice.

## Things to Watch

> **A combined payment is refunded per invoice**
> 
> When one WeChat Pay order paid several invoices, only the refunded invoice's share goes back, and the shares add up exactly to the order. If the share cannot be worked out, nothing is sent and the panel says so. Refund it in your merchant platform instead, then mark the invoice **Refunded** with **Add as expense**. Version 5.0-beta.4 and earlier refund the whole order.

> **An accepted refund can still be on its way**
> 
> The invoice is marked as refunded once WeChat Pay accepts the refund. The money can reach the client later, while WeChat Pay is still processing it.

## Required Privileges

Settings require **Payment Gateways** (`MODULES_PAYMENT_SETTINGS`). Invoice changes require **Billing → Edit** (`INVOICES_OPERATION`).

## Related Articles

- [Payment Configuration](https://docs.wisecp.com/en/payment-modules)
- [Invoice Detail](https://docs.wisecp.com/en/invoice-detail-overview)
