Pay with QR Code (Desktop Website Browser) - WeChat Pay
Accept WeChat Pay on your website by presenting your QR code to the shopper.
Step 1. Initialize a Payment Intent
Create a Payment Intent with the Create a Payment Intent API API.
POST /api/v1/pa/payment_intents/create
Step 2. Generate and render the QR code
2.1. Obtain the string representation of the QR code
When a shopper selects to pay with WeChat Pay on their desktop browser, call the Confirm a Payment Intent API API to get a string representation of the QR code.
POST /api/v1/pa/payment_intents/{id}/confirm
You will get a response similar to the following.
2.2. Present the QR code to the shopper
You can render the QR code image with the next_action.qrcode
returned in the confirm Payment Intent response and present it to the shopper. Shoppers will complete the payment after scanning the QR code with their WeChat Pay mobile app.
There are publicly available libraries for different programming languages to render a QR code image from its string representation. For example, if you use JavaScript, you may use qrcode to facilitate the conversion. Firstly, get a Base64-encoded image string with the qrcode library:
Then place the image string into the src
field of the img
element.
Once generated, the QR code will expire in 2 hours. Confirming the Payment Intent again (with WeChat Pay or any other payment methods) will void the QR code.
Step 3. Query the payment result status
To get the payment result, we suggest you poll the status of the Payment Intent via the Retrieve a Payment Intent API API.
GET /api/v1/pa/payment_intents/{id}
You should start polling the status immediately after you rendered and presented the QR code to the shopper.
In addition, Airwallex will notify you of the payment result asynchronously via the webhooks. Please refer to the webhook documentation to set up your webhook accordingly. Although subscribing to webhook events is optional, it is recommended to subscribe to the payment_intent.succeeded
webhook which indicates that the shopper has paid the order.