--- title: "WeChat Pay Component" description: "Add WeChat Pay to an existing Components integration." url: "https://docs.adyen.com/payment-methods/wechat-pay/wechat-pay-in-app-payments/android-component" source_url: "https://docs.adyen.com/payment-methods/wechat-pay/wechat-pay-in-app-payments/android-component.md" canonical: "https://docs.adyen.com/payment-methods/wechat-pay/wechat-pay-in-app-payments/android-component" last_modified: "2019-07-04T10:57:00+02:00" language: "en" --- # WeChat Pay Component Add WeChat Pay to an existing Components integration. [View source](/payment-methods/wechat-pay/wechat-pay-in-app-payments/android-component.md) 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](/online-payments/build-your-integration/sessions-flow?platform=Android\&integration=Components) and use the following module and Component names: * To [import the module](/online-payments/build-your-integration/sessions-flow/?platform=Android\&integration=Components#import): **instant** * To [launch and show the Component](/online-payments/build-your-integration/sessions-flow?platform=Android\&integration=Components#launch-and-show): **InstantPaymentComponent** WeChat Pay is supported from Android Components version 3.5.0 and later. For more information, see [release notes](/online-payments/release-notes). 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](/online-payments/build-your-integration/advanced-flow/?platform=Android\&integration=Components). | | **Setup steps** | Before you begin, [add in your Customer Area](/payment-methods/add-payment-methods). | ## Preparation 1. [Create a developer account](/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](/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 implementation "com.adyen.checkout:wechatpay:" ``` Check the [latest version on GitHub](https://github.com/Adyen/adyen-android). b. Check if WeChat is available on the shopper's device. ```kotlin // 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 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 // 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 // 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 // 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 // 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 // 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 # 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 # 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 // 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 { "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 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 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 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](/online-payments/build-your-integration/advanced-flow/?platform=Android\&integration=Components#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](/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](/online-payments/build-your-integration/sessions-flow?platform=Android\&integration=Components) * [Webhooks](/development-resources/webhooks) * [API Explorer](https://docs.adyen.com/api-explorer/#/CheckoutService/latest/overview)