WeChat Pay Element
WeChat Pay Element has been deprecated in the latest @airwallex/components-sdk
v1.14.2. Please migrate to the Drop-in Element to access this functionality.
The WeChat Pay Element allows you to embed a WeChat Pay QR code checkout option on your payment page. It contains a QR code that matches the specified PaymentIntent and a Refresh button to regenerate the QR code. The shopper can scan the QR code using their WeChat app to make a payment.
This page describes how to embed a WeChat Pay Element on your payment page to accept payments.
How it works
The diagram below depicts the information flow in a WeChat Pay QR Code Element integration.
Before you begin
Before you implement the integration, consider the following:
Ensure your Airwallex account is activated for online payments.
Obtain your access token API by authenticating to Airwallex using your unique Client ID and API key. You will need the access token to make API calls.
Explore the
airwallex-payment-elements
JavaScript client library reference to familiarize yourself with the Embedded Elements methods, parameters, and properties.Install the package
- Using Yarn or NPM
yarn add airwallex-payment-elements
npm install airwallex-payment-elements
- Using CDN
<script src="https://checkout.airwallex.com/assets/elements.bundle.min.js"></script>
- Using Yarn or NPM
Step 1: Set up the server to create a PaymentIntent
When the shopper begins the checkout process, you will need to create a PaymentIntent object to indicate your intent to collect payment from the shopper.
When the checkout page loads, on your server, call Create a PaymentIntent API with an amount and currency. Always decide how much to charge on the server side, a trusted environment, as opposed to the client. This prevents malicious shoppers from being able to alter the payment amount.
Provide return_url
in Create a PaymentIntent API to indicate where Airwallex should redirect the shopper after completing the payment, whether successful or otherwise.
The PaymentIntent’s id
and client_secret
are returned in the response — these parameters let you confirm the payment and update card details on the client, without allowing manipulation of sensitive information, like payment amount.
Step 2: Initialize legacy Airwallex element on your checkout page
First, you will need to import the legacy airwallex-payment-elements SDK and then initialize the package. For details, see Initialize Airwallex .
Step 3: Add the WeChat QR Code Element to your checkout page
To embed the WeChat QR Code Element into your checkout page, you will need to create an empty container, create the Element and then mount the Element to the container.
Define the payment form
First, create an empty container div
with a unique id in your payment form. Ensure that the payment form only contains one Element with this unique id. Airwallex inserts an iframe into this div
on mounting the Element.
Create the WeChat QR Code Element
When the payment form has loaded, call createElement(type, options)
by specifying the Element type as wechat
to create the Element. Ensure that the payment form only contains one Element with wechat
id. Passing PaymentIntent id
and client_secret
as options
is mandatory.
Mount the WeChat QR Code Element
Call mount()
with the id of the div
to mount the Element to the DOM. The Element should only be mounted once in a single payment flow.
Add onReady
event listener to ensure the Element is mounted. Use this event to prepare and load the checkout page.
Step 4: Handle the response
Add success
and error
event listeners to handle error and success events received from Airwallex.
If no error occurred, display a message that the payment was successful. If payment fails with an error, display the appropriate message to your shopper so they can take action and try again.
Retrieve the payment result
For any actions subsequent to the payment such as shipping goods or sending email receipts, you can retrieve the payment result using the following options:
Set up webhooks to receive notifications on whether the payment has succeeded. Airwallex sends
payment_intent.succeeded
event when a payment succeeds. Listen to these events rather than waiting on a callback from the client. On the client, the shopper could close the browser window or quit the app before the callback executes. For information on how to set up webhooks and listen to events, see Getting started with webhooksOn your server, call Retrieve a PaymentIntent API to check the PaymentIntent status.
Check Payment Activity screen on your Airwallex web app.
Test your integration
Perform transaction tests in the production environment as described in the go-live checklist to ensure your integration is working correctly.
Example integrations
Explore a full, working code sample of an integration built using various web frameworks .
Additional features
You can use the following features in your Drop-in Element integration.
Localization
You can configure the Element to display localized text of the payment fields based on the locale
set in init()
. See supported locales JS.
Device fingerprinting
Device fingerprinting uniquely tracks and identifies devices used for transacting on your shopping site, increasing your protection from fraud. Airwallex.js automatically handles device fingerprinting, so no additional integration is needed.
FAQ
What are the common error scenarios with Embedded Elements integration?
Some common error scenarios include :
Error | Next steps |
---|---|
Airwallex is not defined | Check if you have initialized Airwallex (Step 2) before using Airwallex functions. If you are using CDN, check if you have changed the bundle version from x.x.x to the latest version in the package.json file. For example, https://checkout.airwallex.com/assets/elements.bundle.min.js is invalid |
Access denied, authentication failed | Check if you have replaced your intent id and client_secret in createElement() and optionally confirm() . |
The PaymentIntent with ID int_xxxxxxxxx cannot be found | Check if the environment you initialized Airwallex in, for example, demo or prod, matches the environment you retrieved your intent id and client_secret from. In other words, if you ran init in the demo environment, you must also create your PaymentIntent in the demo environment. |
Development resources
airwallex-payment-elements
NPM packageairwallex-payment-elements
library referenceSample SDKs in various frontend and backend languages
Test cards and sandbox to test your integration