# WeChat Pay

> Integrate one-time WeChat Pay payments for web QR codes, H5, mini programs, and apps, then confirm the server-side result.

## Basic information

Customers pay with WeChat Pay in the client scenario enabled for your application.

- Integration paths: [Checkout](/payments/online-payments/checkout), [Web SDK](/payments/online-payments/sdk), [Direct API](/payments/online-payments/api)
- Transaction type: One-time online payment
- `lpmsInfo.lpmsType`: `WeChat`

| Payer wallet market | Order currency |
| --- | --- |
| 🇨🇳 CN (mainland China WeChat Pay) | GBP, USD, EUR, CNY, JPY, HKD |

Before integrating, ask Onerway to confirm the payer wallet, order currency, and client scenario enabled for your application. The wallet market and each order currency above require that confirmation; the table is not a list of generally available configurations. Confirm the client scenarios for Checkout and Web SDK with Onerway; Direct API scenarios are described below. Available currencies and payment scenarios depend on your account configuration and the availability query for the current order.

## Before you begin

Complete [Setup](/payments/get-started/setup) and confirm the scenarios enabled for your merchant account. Follow [Query available payment methods](/payments/online-payments/payment-methods/local-payment-methods#query-available-payment-methods) and that API's own parameters for order availability. The Direct API `paymentMode` values are not a replacement for the query API's parameter definitions. See [Currency and amount validation](/payments/get-started/currency-and-amount); confirm your account's transaction limits and settlement currencies with Onerway.

## Create a payment

### Checkout

Confirm that your client scenario is enabled with Onerway before integrating.

Follow [Checkout integration](/payments/online-payments/checkout) to create the payment and send the customer to the returned `redirectUrl`. Onerway handles payment selection and customer interaction. After the customer returns to your site, confirm the server-side result as described below.

### Web SDK

Confirm that your client scenario is enabled with Onerway before integrating.

Follow [Web SDK integration](/payments/online-payments/sdk) to create an SDK order, initialize the SDK with the returned `paymentId`, and mount the payment component. The SDK handles customer interaction. Handle payment events and subsequent actions as described in that guide, and confirm the final result on your server.

### Direct API

Provide the WeChat AppID for your chosen client to Onerway for configuration. This is a WeChat identifier, distinct from the Onerway `appId` used in API requests. For mini program payments, you must obtain the customer's `openid` under the same mini program AppID and submit it in `lpmsInfo.walletAccountId`.

For H5, provide Onerway with the domain of the page that initiates payment. Onerway registers it with WeChat Pay. This is the originating page's domain, not the domain of the returned WeChat payment URL; configuring a return URL alone does not complete domain registration.

| Scenario (`paymentMode`) | Customer action and response field |
| --- | --- |
| Website QR code (`WEB`) | `QrCode`: display the code in `data.codeForm` |
| Mobile browser H5 (`WAP`) | `RedirectURL`: open `data.redirectUrl` |
| Mini program (`MINI_PROGRAM`) | `ShowContext`: invoke payment with `data.presentContext` |
| Native app (`IN_APP`) | `ShowContext`: invoke payment with `data.presentContext` |

Call [Create direct transaction](/payments/api-reference/endpoints/direct-create-transaction) with `productType=LPMS`, `subProductType=DIRECT`, `txnType=SALE`, and `lpmsInfo.lpmsType=WeChat`. Set `paymentMode` for the customer's environment. See [`paymentMode`](/payments/api-reference/endpoints/direct-create-transaction#request-paymentMode) and [`lpmsInfo.walletAccountId`](/payments/api-reference/endpoints/direct-create-transaction#request-lpmsInfo-walletAccountId) for scenario selection and the mini program customer identifier.

In the request examples for [Create direct transaction](/payments/api-reference/endpoints/direct-create-transaction), select the illustrative WeChat Pay WEB, H5, mini program, or app request. Replace its placeholders with your own order and client data.

Use `actionType` to choose the customer action. A response can include a `redirectUrl` alongside `presentContext`; when `actionType=ShowContext`, use the client parameters as described below.

In the response examples for [Create direct transaction](/payments/api-reference/endpoints/direct-create-transaction), select the corresponding WeChat Pay scenario: WEB, H5, mini program, or app. See [`codeForm`](/payments/api-reference/endpoints/direct-create-transaction#response-data-codeForm), [`redirectUrl`](/payments/api-reference/endpoints/direct-create-transaction#response-data-redirectUrl), and [`presentContext`](/payments/api-reference/endpoints/direct-create-transaction#response-data-presentContext) for the field definitions.

#### Web QR code

For `QrCode`, `codeForm` is a JSON object; do not call `JSON.parse` on it. Inspect `codeForm.codeDetails` and select a supported representation using each entry's `codeValueType` and `displayType`:

- For a `QRCODE` entry with `displayType=TEXT`, encode `codeValue` as a QR code for the customer to scan in WeChat.
- For a `QRCODE` entry with `displayType=IMAGE`, display the image at the returned `codeValue` URL.

Do not depend on a fixed number or order of entries. If `expireTime` is present, use it to handle expiry; do not assume a fixed validity period.

#### H5

For `RedirectURL`, open `data.redirectUrl` from the registered mobile web page in a browser outside WeChat. Test on the actual domain that initiates payment, including its Referer behavior. See the [WeChat Pay H5 troubleshooting guide](https://pay.wechatpay.cn/doc/v3/merchant/4012791845) for domain and Referer checks.

#### Mini program

For `ShowContext`, map the returned `presentContext` object to [`wx.requestPayment`](https://pay.wechatpay.cn/doc/v3/partner/4012085827). Map `timestamp` to `timeStamp` and `noncestr` to `nonceStr`; pass `package`, `signType`, and `paySign` unchanged. The returned `appid` must match the mini program invoking payment. Do not generate a replacement signature in the client.

#### App

Pass the returned `presentContext` parameters to the official WeChat OpenSDK for your platform. They include `appid`, `partnerid`, `prepayid`, `package`, `noncestr`, `timestamp`, and `sign`. Match the SDK's field names and types, retaining the supplied values and signature. Follow the client-side App payment section of the [WeChat Pay development guide](https://pay.wechatpay.cn/doc/v3/partner/4012088031) for SDK setup and invocation.

## Customer action and final result

### Confirm the transaction result

A scan, a browser return, or a successful client callback does not prove payment success. Use the transaction's `status` from the verified [payment result webhook](/payments/api-reference/webhooks/payment-result), or [Query transactions](/payments/api-reference/endpoints/query-transactions) when reconciling the result. See [Webhooks](/payments/get-started/webhooks) for verification, acknowledgement, and duplicate handling.

Only `status=S` confirms a successful payment; `status=F` indicates failure. Handle other values according to the API reference and retain a pending state where applicable.

## Refunds and disputes

Confirm refund availability, refund restrictions, and the applicable dispute process with Onerway for your account. When refunds are enabled, follow [Refunds](/payments/online-payments/scenarios/refunds). Do not assume that every WeChat Pay feature is available through your Onerway configuration.

## Testing and go-live

Confirm the available test environment, test accounts, and enabled client scenarios with Onerway before following [Testing](/payments/get-started/testing).

1. Test Checkout redirects or SDK customer interaction for the integration path you use. For Direct API, test each client scenario you will launch: scan the rendered QR code for WEB; open the H5 link from the registered domain; invoke mini program payment with the matching AppID and `openid`; invoke the app SDK using the returned parameters.
2. For each scenario, complete a payment and verify that the order becomes paid only after a verified notification or server query reports `status=S`.
3. Test cancellation, an interrupted return, and a missing notification. Confirm that frontend events alone do not mark the order paid and that transaction queries can reconcile the result.
4. Before launch, confirm production scenario enablement, currencies, limits, and the notification endpoint. For Direct API, check AppID configuration and any H5 domain registration required for your chosen client. Test refunds if enabled for your account.
