> ## 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 In-app for API Only

> Accept WeChat Pay payments from mobile app with your existing API-only integration.

Accept WeChat Pay in-app payments using our APIs, and build your integration using WeChat Pay mobile SDKs.

## Requirements

| Requirement | Description |
| - | - |
| **Integration type** | Make sure that you have built an [API-only integration](https://adyen-preview.mintlify.site/online-payments/build-your-integration/advanced-flow.md). |
| **Setup steps** | Before you begin, [add in your test 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.
3. [Integrate WeChat's mobile SDKs](https://adyen-preview.mintlify.site/payment-methods/wechat-pay/wechat-pay-in-app-payments/enable-wechat-pay#integrate-wechats-mobile-sdks) for iOS or Android.

## Build your payment form for WeChat Pay

Check if WeChat is available in the shopper's device, and then show WeChat Pay as an available payment method in your mobile app.

We provide logos for WeChat Pay which you can use on your payment form. For more information, refer to [Downloading logos](https://adyen-preview.mintlify.site/online-payments/build-your-integration/advanced-flow.md#downloading-logos).

You can also submit a [/paymentMethods](https://docs.adyen.com/api-explorer/Checkout/latest/post/paymentMethods) request specifying:

* [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**.

In the response, you receive `paymentMethod.type`: **wechatpaySDK**.

## Make a payment

When the shopper selects to pay with WeChat Pay:

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

   * `paymentMethod.type`: **wechatpaySDK**

   #### 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 contains:

   * `action`: Object containing information that you will need when invoking the WeChat Pay SDK.

   **/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"
           }
       ],
       ...
   }
   ```

2. Pass the values in the `sdkData` object to the WeChat Pay SDK. The WeChat Pay SDK launches the WeChat app, where the shopper can proceed to complete the payment.

3. Get the result from the WeChat Pay SDK.

## Check the payment result

When the shopper completes the payment on the WeChat app, make a [/payments/details](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/details) to check the payment result.

In your [/payments/details](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/details) request, provide the following:

* `resultCode`: Value you received from the WeChat Pay SDK.

* `paymentData`: Encoded payment data. If you received `resultCode`: **AuthenticationNotRequired** in the [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) response, use the `threeDSPaymentData` from the same response. If you received `resultCode`: **AuthenticationFinished** in the [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) response, use the `action.paymentData` from the same response.

  #### curl

  ```bash theme={null}
  curl https://checkout-test.adyen.com/v72/payments/details \
  -H 'x-api-key: ADYEN_API_KEY' \
  -H 'content-type: application/json' \
  -d '{
     "details": {
        "{hint:Result from WeChat Pay SDK}resultCode{/hint}": "0"
     },
     "{hint:Encoded payment data}paymentData{/hint}": "Ab02b4c0!BQABAgCSZT7t..."
  }'
  ```

  #### 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)
  PaymentCompletionDetails paymentCompletionDetails = new PaymentCompletionDetails()
    .resultCode("0");

  PaymentDetailsRequest paymentDetailsRequest = new PaymentDetailsRequest()
    .details(paymentCompletionDetails);

  // Send the request
  PaymentsApi service = new PaymentsApi(client);
  PaymentDetailsResponse response = service.paymentsDetails(paymentDetailsRequest, 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\PaymentCompletionDetails;
  use Adyen\Model\Checkout\PaymentDetailsRequest;
  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)
  $paymentCompletionDetails = new PaymentCompletionDetails();
  $paymentCompletionDetails
    ->setResultCode("0");

  $paymentDetailsRequest = new PaymentDetailsRequest();
  $paymentDetailsRequest
    ->setDetails($paymentCompletionDetails);

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

  // Send the request
  $service = new PaymentsApi($client);
  $response = $service->paymentsDetails($paymentDetailsRequest, $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)
  PaymentCompletionDetails paymentCompletionDetails = new PaymentCompletionDetails
  {
    ResultCode = "0"
  };

  PaymentDetailsRequest paymentDetailsRequest = new PaymentDetailsRequest
  {
    Details = paymentCompletionDetails
  };

  // Send the request
  var service = new PaymentsService(client);
  var response = service.PaymentsDetails(paymentDetailsRequest, 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 paymentDetailsRequest = {
    details: {
      resultCode: "0"
    }
  }

  // Send the request
  const checkoutAPI = new CheckoutAPI(client);
  const response = checkoutAPI.PaymentsApi.paymentsDetails(paymentDetailsRequest, { 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)
  paymentCompletionDetails := checkout.PaymentCompletionDetails{
    ResultCode: common.PtrString("0"),
  }

  paymentDetailsRequest := checkout.PaymentDetailsRequest{
    Details: paymentCompletionDetails,
  }

  // Send the request
  service := client.Checkout()
  req := service.PaymentsApi.PaymentsDetailsInput().IdempotencyKey("UUID").PaymentDetailsRequest(paymentDetailsRequest)
  res, httpRes, err := service.PaymentsApi.PaymentsDetails(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 = {
    "details": {
      "resultCode": "0"
    }
  }

  # Send the request
  result = adyen.checkout.payments_api.payments_details(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 = {
    :details => {
      :resultCode => '0'
    }
  }

  # Send the request
  result = adyen.checkout.payments_api.payments_details(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 paymentCompletionDetails: Types.checkout.PaymentCompletionDetails = {
    resultCode: "0"
  };

  const paymentDetailsRequest: Types.checkout.PaymentDetailsRequest = {
    details: paymentCompletionDetails
  };

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

## 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 for iOS](https://itunes.apple.com/app/wechat/id414478124)
* [WeChat for Android](https://play.google.com/store/apps/details?id=com.tencent.mm)
* [API only integration guide](https://adyen-preview.mintlify.site/online-payments/build-your-integration/advanced-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.