Accept WeChatPay payments

DocsBeta

Last updated: Sept 19th, 3:22am

WeChatPay is a mobile payment and digital wallet service by WeChat based in China that allows users to make mobile payments and online transactions.

Seller Countries Payment type Payment flow Currencies Maximum amount Refunds
Austria (AT)
Belgium (BE)
Denmark (DK)
Finland (FI)
France (FR)
Germany (DE)
Greece (GR)
Hungary (HU)
Iceland (ISL)
Ireland (IE)
Italy (IT)
Liechtenstein (LI)
Luxembourg (LU)
Malta (MT)
Holland (NL)
Norway (NO)
Portugal (PT)
Spain (ES)
Sweden (SE)
Wallet Redirect EUR N/A Within 360 days
United Kingdom (UK) Wallet Redirect GBP N/A Within 360 days

How it works

Alternative,payment,methods,diagram

  1. You add alternative payment methods to your checkout page.
  2. Payer provides their personal details and selects an alternative payment method from your checkout page.
  3. Payer is transferred from your checkout page to the third-party bank to authorize and confirm payment.
  4. Payer returns to your site to see confirmation of purchase.

Know before you code

  • Integration steps for implementing alternate payment methods are similar. If an alternate payment method has been previously integrated, most of the code may be reused.

  • Make sure you're subscribed to the following webhook events:

    • The PAYMENT.CAPTURE.COMPLETED webhook event indicates a successful order capture.
    • The PAYMENT.CAPTURE.DENIED webhook event indicate a failed order capture.
  • After you receive each webhook, fetch the latest order details using Show order details. The up HATEOAS link in the webhook payload indicates the order associated with the capture.

  • When processing WeChatPay payments, you don't need to capture payment for the order.

1. Offer WeChatPay on your checkout page

You'll need to create the user interface to offer WeChatPay and collect the payer's full name. Then you'll use the API calls described in the remainder of this topic to:

  • Create the order with WeChatPay as the payment method, the payer's full name, and the country_code.
  • Redirect the payer to WeChatPay.

Refer to Payment method icons for icons you to use on your checkout page.

2. Create an order with WeChatPay as the payment source

Use the payer information you captured from your user interface to create an order with WeChatPay as the payment source.

Sample request

API endpoint used: Create order

    1curl --location --request POST 'https://api-m.sandbox.paypal.com/v2/checkout/orders' \
    2--header 'Content-Type: application/json' \
    3--header 'Authorization: Bearer ACCESS-TOKEN' \
    4--header 'PayPal-Request-Id: PAYPAL-REQUEST-ID' \
    5--data-raw '{
    6 "intent": "CAPTURE",
    7 "payment_source": {
    8 "wechatpay": {
    9 "country_code": "CN",
    10 "name": "John Doe"
    11 }
    12 },
    13 "processing_instruction": "ORDER_COMPLETE_ON_PAYMENT_APPROVAL",
    14 "purchase_units": [
    15 {
    16 "invoice_id": "Invoice-12345",
    17 "custom_id": "Custom-1234",
    18 "amount": {
    19 "currency_code": "USD",
    20 "value": "49.11"
    21 },
    22 "shipping": {
    23 "name": {
    24 "full_name": "John Doe"
    25 },
    26 "address": {
    27 "address_line_1": "HongKong Rd East, 126",
    28 "address_line_2": "Floor 5",
    29 "admin_area_2": "Qingdao",
    30 "admin_area_1": "rm",
    31 "postal_code": "266071",
    32 "country_code": "CN"
    33 }
    34 }
    35 }
    36 ]
    37}'

    Modify the code

    After you copy the code in the sample request, modify the following:

    • ACCESS-TOKEN - Your access token.
    • PAYPAL-REQUEST-ID - Replace the sample ID with a unique ID that you generate. The PAYPAL-REQUEST-ID helps prevent duplicate authorizations if the API call is disrupted. For more information about idempotent requests, see API idempotency.
    • intent - Set this value to CAPTURE.
    • payment_source - Specify wechatpay, and include the following:
    • country_code
    • name - The payer's full name.
    • experience_context - Specify the following:
    • locale - The preferred language for returned errors
    • return_url - The URL the buyer is returned to after approving the purchase with their selected payment method.
    • cancel_url - The URL the buyer is returned to after canceling an approval with their selected payment method.
    • processing_instruction - Set this value to ORDER_COMPLETE_ON_PAYMENT_APPROVAL.
    • purchase_units: amount - Specify the value of the order and the currency code.

    Step result

    A successful request results in the following:

    • A JSON response body that contains the order ID.
    • HATEOAS links.

    Sample response

      1{
      2 "id": "5V159329PV571861D",
      3 "status": "PAYER_ACTION_REQUIRED",
      4 "payment_source": {
      5 "wechatpay": {
      6 "name": "John Doe",
      7 "country_code": "CN"
      8 }
      9 },
      10 "links": [
      11 {
      12 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/5V159329PV571861D",
      13 "rel": "self",
      14 "method": "GET"
      15 },
      16 {
      17 "href": "https://www.sandbox.paypal.com/payment/wechatpay?token=5V159329PV571861D",
      18 "rel": "payer-action",
      19 "method": "GET"
      20 }
      21 ]
      22}

      3. Redirect payer to WeChatPay

      In your user interface, attach the payer-action redirect URL returned in the Create Order response to the WeChatPay payment button. This sends the payer to their wallet to approve the purchase. After the payer approves the purchase, the payment is automatically captured.

      In the sample, the redirect URL is: "https://www.sandbox.paypal.com/payment/wechatpay?token=5V159329PV571861D".

      Step result

      After completing the wallet transaction:

      • The payer is redirected to the return_url in the Create Order request.

      • The PAYMENT.CAPTURE.COMPLETED webhook event is triggered, indicating successful payment capture.

        After unsuccessful bank approval, the payer is redirected to the cancel_url in the Create Order request.

      4. Listen to webhooks to get the result of payment status

      The following webhooks provide the result of order capture:

      • The PAYMENT.CAPTURE.COMPLETED webhook event indicates a successful order capture.
      • The PAYMENT.CAPTURE.DENIED webhook events indicate a failed order capture.
      • Optional: Use Show order details endpoint to determine the status of an order.
      • The up HATEOAS link indicates the order associated with this capture.

      For more information about webhooks, see:

      Sample PAYMENT.CAPTURE.COMPLETED webhook

        1{
        2 "id": "WH-9LK14475MF9937440-9EG47645TP521822L",
        3 "event_version": "1.0",
        4 "create_time": "2022-05-10T06:04:12.533Z",
        5 "resource_type": "capture",
        6 "resource_version": "2.0",
        7 "event_type": "PAYMENT.CAPTURE.COMPLETED",
        8 "summary": "Payment completed for USD 100.0 USD",
        9 "resource": {
        10 "amount": {
        11 "value": "100.00",
        12 "currency_code": "USD"
        13 },
        14 "update_time": "2022-01-19T06:04:08Z",
        15 "create_time": "2022-01-19T06:04:08Z",
        16 "final_capture": true,
        17 "seller_receivable_breakdown": {
        18 "paypal_fee": {
        19 "value": "3.80",
        20 "currency_code": "USD"
        21 },
        22 "gross_amount": {
        23 "value": "100.00",
        24 "currency_code": "USD"
        25 },
        26 "net_amount": {
        27 "value": "96.20",
        28 "currency_code": "USD"
        29 }
        30 },
        31 "links": [
        32 {
        33 "method": "GET",
        34 "rel": "self",
        35 "href": "https://api-m.sandbox.paypal.com/v2/payments/captures/5R102774VL663561J"
        36 },
        37 {
        38 "method": "POST",
        39 "rel": "refund",
        40 "href": "https://api-m.sandbox.paypal.com/v2/payments/captures/5R102774VL663561J/refund"
        41 },
        42 {
        43 "method": "GET",
        44 "rel": "up",
        45 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/5V159329PV571861D"
        46 }
        47 ],
        48 "id": "5R102774VL663561J",
        49 "status": "COMPLETED"
        50 },
        51 "links": [
        52 {
        53 "href": "https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9LK14475MF9937440-9EG47645TP521822L",
        54 "rel": "self",
        55 "method": "GET"
        56 },
        57 {
        58 "href": "https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9LK14475MF9937440-9EG47645TP521822L/resend",
        59 "rel": "resend",
        60 "method": "POST"
        61 }
        62 ]
        63}

        Sample PAYMENT.CAPTURE.DENIED webhook

          1{
          2 "id": "WH-9LK14475MF9937440-9EG47645TP521822L",
          3 "event_version": "1.0",
          4 "zts": 1481046241,
          5 "create_time": "2022-05-10T06:04:12.533Z",
          6 "resource_type": "capture",
          7 "resource_version": "2.0",
          8 "event_type": "PAYMENT.CAPTURE.DENIED",
          9 "summary": "Payment denied for USD 100.0 USD",
          10 "resource": {
          11 "amount": {
          12 "value": "100.00",
          13 "currency_code": "USD"
          14 },
          15 "supplementary_data": {
          16 "related_ids": {
          17 "order_id": "5V159329PV571861D"
          18 }
          19 },
          20 "update_time": "2022-05-10T06:04:08Z",
          21 "create_time": "2022-05-10T06:04:08Z",
          22 "final_capture": true,
          23 "seller_receivable_breakdown": {
          24 "paypal_fee": {
          25 "value": "3.80",
          26 "currency_code": "USD"
          27 },
          28 "gross_amount": {
          29 "value": "100.00",
          30 "currency_code": "USD"
          31 },
          32 "net_amount": {
          33 "value": "96.20",
          34 "currency_code": "USD"
          35 }
          36 },
          37 "links": [
          38 {
          39 "method": "GET",
          40 "rel": "self",
          41 "href": "https://api-m.sandbox.paypal.com/v2/payments/captures/5R102774VL663561J"
          42 },
          43 {
          44 "method": "POST",
          45 "rel": "refund",
          46 "href": "https://api-m.sandbox.paypal.com/v2/payments/captures/5R102774VL663561J/refund"
          47 },
          48 {
          49 "method": "GET",
          50 "rel": "up",
          51 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/5V159329PV571861D"
          52 }
          53 ],
          54 "id": "5R102774VL663561J",
          55 "status": "DECLINED"
          56 },
          57 "links": [
          58 {
          59 "href": "https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9LK14475MF9937440-9EG47645TP521822L",
          60 "rel": "self",
          61 "method": "GET"
          62 },
          63 {
          64 "href": "https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9LK14475MF9937440-9EG47645TP521822L/resend",
          65 "rel": "resend",
          66 "method": "POST"
          67 }
          68 ]
          69}

          Sample request

            1curl -v -X GET https://api-m.sandbox.paypal.com/v2/checkout/orders/5V159329PV571861D \
            2 -H "Content-Type: application/json" \
            3 -H "Authorization: Bearer ACCESS-TOKEN"

            Sample response

              1{
              2 "id": "5V159329PV571861D",
              3 "intent": "CAPTURE",
              4 "status": "COMPLETED",
              5 "payment_source": {
              6 "wechatpay": {
              7 "name": "John Doe",
              8 "country_code": "CN"
              9 }
              10 },
              11 "processing_instruction": "ORDER_COMPLETE_ON_PAYMENT_APPROVAL",
              12 "purchase_units": [
              13 {
              14 "reference_id": "default",
              15 "amount": {
              16 "currency_code": "USD",
              17 "value": "100.00"
              18 },
              19 "payments": {
              20 "captures": [
              21 {
              22 "id": "5R102774VL663561J",
              23 "status": "COMPLETED",
              24 "amount": {
              25 "currency_code": "USD",
              26 "value": "100.00"
              27 },
              28 "final_capture": true,
              29 "seller_receivable_breakdown": {
              30 "gross_amount": {
              31 "currency_code": "USD",
              32 "value": "100.00"
              33 },
              34 "paypal_fee": {
              35 "currency_code": "USD",
              36 "value": "3.80"
              37 },
              38 "net_amount": {
              39 "currency_code": "USD",
              40 "value": "96.20"
              41 }
              42 },
              43 "links": [
              44 {
              45 "href": "https://api-m.sandbox.paypal.com/v2/payments/captures/5R102774VL663561J",
              46 "rel": "self",
              47 "method": "GET"
              48 },
              49 {
              50 "href": "https://api-m.sandbox.paypal.com/v2/payments/captures/5R102774VL663561J/refund",
              51 "rel": "refund",
              52 "method": "POST"
              53 },
              54 {
              55 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/5V159329PV571861D",
              56 "rel": "up",
              57 "method": "GET"
              58 }
              59 ]
              60 }
              61 ]
              62 }
              63 }
              64 ],
              65 "links": [
              66 {
              67 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/5V159329PV571861D",
              68 "rel": "self",
              69 "method": "GET"
              70 }
              71 ]
              72}

              Step result

              A successful request returns the HTTP 200 OK status code with a JSON response body that returns a COMPLETED status.

              A captured order has the following:

              • The order status as COMPLETED, which means the order was captured successfully.
              • A capture with COMPLETED status is present in the response parameter purchase_units[0].payments.captures[0].
              • The up HATEOAS link indicates the order associated with this capture.

              5. Notify payer of success

              After a successful payment, notify the payer of a successful transaction.

              Next steps

              Test in PayPal sandbox, then go live in PayPal's production environment.

              We use cookies to improve your experience on our site. May we use marketing cookies to show you personalized ads? Manage all cookies