> ## Documentation Index
> Fetch the complete documentation index at: https://adyen-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# WeChat Pay Component

> Add WeChat Pay to an existing Components integration.

This page explains how to add to your existing Android Components integration.

**If you are using Android Components v5.0.0 or later:**

This payment method requires no additional configuration.

Follow the [Components integration guide](https://adyen-preview.mintlify.site/online-payments/build-your-integration/sessions-flow.md) and use the following module and Component names:

* To [import the module](https://adyen-preview.mintlify.site/online-payments/build-your-integration/sessions-flow.md#import): **instant**
* To [launch and show the Component](https://adyen-preview.mintlify.site/online-payments/build-your-integration/sessions-flow.md#launch-and-show): **InstantPaymentComponent**

WeChat Pay is supported from Android Components version 3.5.0 and later. For more information, see [release notes](https://adyen-preview.mintlify.site/online-payments/release-notes.md).

Our WeChat Pay Component triggers the app switch from your app to the WeChat app on the shopper's device.

## Requirements

| Requirement | Description |
| - | - |
| **Integration type** | Make sure that you have built an Advanced flow [Android Components integration](https://adyen-preview.mintlify.site/online-payments/build-your-integration/advanced-flow.md). |
| **Setup steps** | Before you begin, [add in your Customer Area](https://adyen-preview.mintlify.site/payment-methods/add-payment-methods). |

## Preparation

1. [Create a developer account](https://adyen-preview.mintlify.site/payment-methods/wechat-pay/wechat-pay-in-app-payments/enable-wechat-pay#create-developer-account) on the WeChat Open Platform.
2. [Register your mobile app](https://adyen-preview.mintlify.site/payment-methods/wechat-pay/wechat-pay-in-app-payments/enable-wechat-pay#register-mobile-app) with WeChat.

## Start a payment with WeChat Pay

To start a payment with WeChat Pay, you need to:

1. Specify in your [/paymentMethods](https://docs.adyen.com/api-explorer/Checkout/latest/post/paymentMethods) request:

   * [countryCode](https://docs.adyen.com/api-explorer/Checkout/latest/post/paymentMethods): Any supported country/region. For example, **CN**.
   * [amount.currency](https://docs.adyen.com/api-explorer/Checkout/latest/post/paymentMethods#request-amount): Any supported currency. For example, **CNY**.

2. Deserialize the response from the [/paymentMethods](https://docs.adyen.com/api-explorer/Checkout/latest/post/paymentMethods) call and get the object with `type`: **wechatpaySDK**.

3. Add the WeChat Pay module:

   a. Import the WeChat Pay module to your `build.gradle` file.

   ```groovy theme={null}
   implementation "com.adyen.checkout:wechatpay:<latest-version>"
   ```

   Check the [latest version on GitHub](https://github.com/Adyen/adyen-android).

   b. Check if WeChat is available on the shopper's device.

   ```kotlin theme={null}
      // WeChatPayProvider is not an actual provider, it only checks whether WeChat Pay is available.
      val weChatPayProvider = WeChatPayProvider()
      weChatPayProvider.isAvailable(application, paymentMethod, null) { isAvailable: Boolean, paymentMethod: PaymentMethod, _ ->
          if (isAvailable) {
              // show WeChat pay as a payment option in your app
          }
      }
   ```

   c. If WeChat is available and the shopper chooses to pay with WeChat Pay, make a [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) request from your server.

## Make a payment

1. From your server, make a [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) request:

   #### curl

   ```bash theme={null}
   curl https://checkout-test.adyen.com/v72/payments \
   -H 'x-api-key: ADYEN_API_KEY' \
   -H 'content-type: application/json' \
   -d '{
     "merchantAccount":"ADYEN_MERCHANT_ACCOUNT",
     "reference":"YOUR_ORDER_NUMBER",
     "amount":{
       "currency":"CNY",
       "value":1000
     },
     "paymentMethod":{
       "type":"wechatpaySDK"
     },
     "returnUrl":"https://your-company.example.com/checkout?shopperOrder=12xy.."
   }'
   ```

   #### Java

   ```java theme={null}
   // Adyen Java API Library v27.0.0
   import com.adyen.Client;
   import com.adyen.enums.Environment;
   import com.adyen.model.checkout.*;
   import java.time.OffsetDateTime;
   import java.util.*;
   import com.adyen.model.RequestOptions;
   import com.adyen.service.checkout.*;

   // For the live environment, additionally include your liveEndpointUrlPrefix.
   Client client = new Client("ADYEN_API_KEY", Environment.TEST);

   // Create the request object(s)
   Amount amount = new Amount()
     .currency("CNY")
     .value(1000L);

   PaymentDetails paymentDetails = new PaymentDetails()
     .type(PaymentDetails.TypeEnum.WECHATPAYSDK);

   PaymentRequest paymentRequest = new PaymentRequest()
     .reference("YOUR_ORDER_NUMBER")
     .amount(amount)
     .merchantAccount("ADYEN_MERCHANT_ACCOUNT")
     .paymentMethod(new CheckoutPaymentMethod(paymentDetails))
     .returnUrl("https://your-company.example.com/checkout?shopperOrder=12xy..");

   // Send the request
   PaymentsApi service = new PaymentsApi(client);
   PaymentResponse response = service.payments(paymentRequest, new RequestOptions().idempotencyKey("UUID"));
   ```

   #### PHP

   ```php theme={null}
   // Adyen PHP API Library v19.0.0
   use Adyen\Client;
   use Adyen\Environment;
   use Adyen\Model\Checkout\Amount;
   use Adyen\Model\Checkout\CheckoutPaymentMethod;
   use Adyen\Model\Checkout\PaymentRequest;
   use Adyen\Service\Checkout\PaymentsApi;

   $client = new Client();
   $client->setXApiKey("ADYEN_API_KEY");
   // For the live environment, additionally include your liveEndpointUrlPrefix.
   $client->setEnvironment(Environment::TEST);


   // Create the request object(s)
   $amount = new Amount();
   $amount
     ->setCurrency("CNY")
     ->setValue(1000);

   $checkoutPaymentMethod = new CheckoutPaymentMethod();
   $checkoutPaymentMethod
     ->setType("wechatpaySDK");

   $paymentRequest = new PaymentRequest();
   $paymentRequest
     ->setReference("YOUR_ORDER_NUMBER")
     ->setAmount($amount)
     ->setMerchantAccount("ADYEN_MERCHANT_ACCOUNT")
     ->setPaymentMethod($checkoutPaymentMethod)
     ->setReturnUrl("https://your-company.example.com/checkout?shopperOrder=12xy..");

   $requestOptions['idempotencyKey'] = 'UUID';

   // Send the request
   $service = new PaymentsApi($client);
   $response = $service->payments($paymentRequest, $requestOptions);
   ```

   #### C\#

   ```cs theme={null}
   // Adyen .net API Library v17.0.0
   using Adyen;
   using Environment = Adyen.Model.Environment;
   using Adyen.Model;
   using Adyen.Model.Checkout;
   using Adyen.Service.Checkout;

   // For the live environment, additionally include your liveEndpointUrlPrefix.
   var config = new Config()
   {
       XApiKey = "ADYEN_API_KEY",
       Environment = Environment.Test
   };
   var client = new Client(config);

   // Create the request object(s)
   Amount amount = new Amount
   {
     Currency = "CNY",
     Value = 1000
   };

   PaymentDetails paymentDetails = new PaymentDetails
   {
     Type = PaymentDetails.TypeEnum.WechatpaySDK
   };

   PaymentRequest paymentRequest = new PaymentRequest
   {
     Reference = "YOUR_ORDER_NUMBER",
     Amount = amount,
     MerchantAccount = "ADYEN_MERCHANT_ACCOUNT",
     PaymentMethod = new CheckoutPaymentMethod(paymentDetails),
     ReturnUrl = "https://your-company.example.com/checkout?shopperOrder=12xy.."
   };

   // Send the request
   var service = new PaymentsService(client);
   var response = service.Payments(paymentRequest, requestOptions: new RequestOptions { IdempotencyKey = "UUID"});
   ```

   #### NodeJS (JavaScript)

   ```js theme={null}
   // Adyen Node API Library v18.0.0
   // Require the parts of the module you want to use
   const { Client, CheckoutAPI } = require('@adyen/api-library');
   // Initialize the client object
   // For the live environment, additionally include your liveEndpointUrlPrefix.
   const client = new Client({apiKey: "ADYEN_API_KEY", environment: "TEST"});

   // Create the request object(s)
   const paymentRequest = {
     merchantAccount: "ADYEN_MERCHANT_ACCOUNT",
     reference: "YOUR_ORDER_NUMBER",
     amount: {
       currency: "CNY",
       value: 1000
     },
     paymentMethod: {
       type: "wechatpaySDK"
     },
     returnUrl: "https://your-company.example.com/checkout?shopperOrder=12xy.."
   }

   // Send the request
   const checkoutAPI = new CheckoutAPI(client);
   const response = checkoutAPI.PaymentsApi.payments(paymentRequest, { idempotencyKey: "UUID" });
   ```

   #### Go

   ```go theme={null}
   // Adyen Go API Library v10.4.0
   import (
     "context"
     "github.com/adyen/adyen-go-api-library/v9/src/common"
     "github.com/adyen/adyen-go-api-library/v9/src/adyen"
     "github.com/adyen/adyen-go-api-library/v9/src/checkout"
   )
   // For the live environment, additionally include your liveEndpointUrlPrefix.
   client := adyen.NewClient(&common.Config{
     ApiKey:      "ADYEN_API_KEY",
     Environment: common.TestEnv,
   })

   // Create the request object(s)
   amount := checkout.Amount{
     Currency: "CNY",
     Value: 1000,
   }

   paymentDetails := checkout.PaymentDetails{
     Type: common.PtrString("wechatpaySDK"),
   }

   paymentRequest := checkout.PaymentRequest{
     Reference: "YOUR_ORDER_NUMBER",
     Amount: amount,
     MerchantAccount: "ADYEN_MERCHANT_ACCOUNT",
     PaymentMethod: checkout.PaymentDetailsAsCheckoutPaymentMethod(&paymentDetails),
     ReturnUrl: "https://your-company.example.com/checkout?shopperOrder=12xy..",
   }

   // Send the request
   service := client.Checkout()
   req := service.PaymentsApi.PaymentsInput().IdempotencyKey("UUID").PaymentRequest(paymentRequest)
   res, httpRes, err := service.PaymentsApi.Payments(context.Background(), req)
   ```

   #### Python

   ```py theme={null}
   # Adyen Python API Library v12.5.1
   import Adyen

   adyen = Adyen.Adyen()
   adyen.client.xapikey = "ADYEN_API_KEY"
   # For the live environment, additionally include your liveEndpointUrlPrefix.
   adyen.client.platform = "test" # The environment to use library in.

   # Create the request object(s)
   json_request = {
     "merchantAccount": "ADYEN_MERCHANT_ACCOUNT",
     "reference": "YOUR_ORDER_NUMBER",
     "amount": {
       "currency": "CNY",
       "value": 1000
     },
     "paymentMethod": {
       "type": "wechatpaySDK"
     },
     "returnUrl": "https://your-company.example.com/checkout?shopperOrder=12xy.."
   }

   # Send the request
   result = adyen.checkout.payments_api.payments(request=json_request, idempotency_key="UUID")
   ```

   #### Ruby

   ```rb theme={null}
   # Adyen Ruby API Library v9.5.1
   require "adyen-ruby-api-library"

   adyen = Adyen::Client.new
   adyen.api_key = 'ADYEN_API_KEY'
   # For the live environment, additionally include your liveEndpointUrlPrefix.
   adyen.env = :test # Set to "live" for live environment

   # Create the request object(s)
   request_body = {
     :merchantAccount => 'ADYEN_MERCHANT_ACCOUNT',
     :reference => 'YOUR_ORDER_NUMBER',
     :amount => {
       :currency => 'CNY',
       :value => 1000
     },
     :paymentMethod => {
       :type => 'wechatpaySDK'
     },
     :returnUrl => 'https://your-company.example.com/checkout?shopperOrder=12xy..'
   }

   # Send the request
   result = adyen.checkout.payments_api.payments(request_body, headers: { 'Idempotency-Key' => 'UUID' })
   ```

   #### NodeJS (TypeScript)

   ```ts theme={null}
   // Adyen Node API Library v18.0.0
   // Require the parts of the module you want to use
   import { Client, CheckoutAPI, Types } from "@adyen/api-library";
   // Initialize the client object
   // For the live environment, additionally include your liveEndpointUrlPrefix.
   const client = new Client({apiKey: "ADYEN_API_KEY", environment: "TEST"});

   // Create the request object(s)
   const amount: Types.checkout.Amount = {
     currency: "CNY",
     value: 1000
   };

   const paymentDetails: Types.checkout.PaymentDetails = {
     type: Types.checkout.PaymentDetails.TypeEnum.WechatpaySDK
   };

   const paymentRequest: Types.checkout.PaymentRequest = {
     reference: "YOUR_ORDER_NUMBER",
     amount: amount,
     merchantAccount: "ADYEN_MERCHANT_ACCOUNT",
     paymentMethod: paymentDetails,
     returnUrl: "https://your-company.example.com/checkout?shopperOrder=12xy.."
   };

   // Send the request
   const checkoutAPI = new CheckoutAPI(client);
   const response = checkoutAPI.PaymentsApi.payments(paymentRequest, { idempotencyKey: "UUID" });
   ```

   The [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) response includes an `action` object that contains information about the app switch.

2. Pass the `action` object to your client app.

   **/payments response**

   ```json theme={null}
   {
       "resultCode": "Pending",
       "action": {
           "paymentMethodType": "wechatpaySDK",
           "type": "sdk",
           "sdkData": {
               "appid": "wx3aed7fe146f6a57a",
               "noncestr": "cPY0e83ny4hWyf5O",
               "packageValue": "Sign=WXPay",
               "partnerid": "205287714",
               "prepayid": "wx015678064827111da2e4f0b11005864100",
               "sign": "169FD3F1E193446D90C45573EBDD4020",
               "timestamp": "1573033086"
           }
       },
       "details": [
           {
               "key": "resultCode",
               "type": "text"
           }
       ],
       ...
   }
   ```

## Handle the app switch

1. To switch the shopper to the WeChat app, initialize the WeChat Pay Action Component, and pass the `action` object.

   ```kotlin theme={null}
     val weChatPayActionConfiguration = WeChatPayActionConfiguration.Builder(this, "YOUR_CLIENT_KEY")
         // When you are ready to accept live payments, change the value to one of our live environments.
         .setEnvironment(Environment.TEST)
         .build()

     val weChatPayActionComponent = WeChatPayActionComponent.PROVIDER.get(this, application, weChatPayActionConfiguration)
     weChatPayActionComponent.handleAction(this@YourActivity, action)
   ```

   After the shopper has completed the payment, the WeChat app redirects them back to your app, and provides an `Intent` object containing the result of the payment.

2. Get the result of the WeChat Pay SDK from the `Activity`. Pass the `intent` back to the WeChat Pay Action Component. Depending on your activity's [launchMode](https://developer.android.com/guide/topics/manifest/activity-element#lmode), you can get this intent in either `onCreate` or `onNewIntent`.

   ```kotlin theme={null}
   private fun handleIntent(intent: Intent) {
       if (WeChatPayUtils.isResultIntent(intent)) {
           weChatPayActionComponent.handleIntent(intent)
       }
   }
   ```

   The Component notifies the `observer` with the `actionComponentData`.

3. Pass the `actionComponentData` to your server.

   ```kotlin theme={null}
   wechatPayActionComponent.observe(this) { actionComponentData ->
     // Send a /payments/details/ call containing the `actionComponentData`
     sendPaymentDetails(actionComponentData)
   }
   ```

## Check the payment result

When the shopper returns to your app, the Component provides the `actionComponentData`.

1. Pass the `actionComponentData` to your server.
2. From your server, [make a `/payments/details` request](https://adyen-preview.mintlify.site/online-payments/build-your-integration/advanced-flow#send-additional-payment-details) containing the `actionComponentData`.

## Present the payment result

Use the `resultCode` that you received in the [/payments/details](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/details) response to present the payment result to your shopper.

The `resultCode` values you can receive for WeChat Pay are:

| resultCode | Description | Action to take |
| - | - | - |
| **Authorised** | The payment was successful. | Inform the shopper that the payment has been successful. You will receive the funds in 2-3 days. |
| **Error** | There was an error when the payment was being processed. | Inform the shopper that there was an error processing their payment. The response contains a `refusalReason`, indicating the cause of the error. |
| **Pending** or **Received** | The payment order was successfully received. | Inform the shopper that you have received their order, and are waiting for the payment to clear. You will receive the final result of the payment in an [AUTHORISATION webhook](https://adyen-preview.mintlify.site/development-resources/webhooks/webhook-types). If successful, you will receive the funds in 2 days. |
| **Refused** | The payment was refused by the shopper's bank. | Ask the shopper to try the payment again using a different payment method. |

## Test and go live

WeChat Pay currently has no test platform. If you have a personal WeChat account you can test your integration by either:

* Canceling the transaction when you are asked to verify the payment (**recommended**).
* Making live WeChat Pay payments with a low value.

You can check the status of a WeChat Pay payment in your [Customer Area](https://ca-live.adyen.com/) > **Transactions** > **Payments**.

Before you can accept live WeChat Pay payments, you need to submit a request for WeChat Pay in your [live Customer Area](https://ca-live.adyen.com/).

## See also

* [WeChat Open Platform](https://open.weixin.qq.com/)
* [WeChat for Android](https://play.google.com/store/apps/details?id=com.tencent.mm)
* [Android Components integration guide](https://adyen-preview.mintlify.site/online-payments/build-your-integration/sessions-flow.md)
* [Webhooks](https://adyen-preview.mintlify.site/development-resources/webhooks.md)
* [API Explorer](https://docs.adyen.com/api-explorer/Checkout/latest/overview)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.