WeChat Pay
Learn how to accept WeChat Pay payments.
As China’s largest internet company, Tencent offers a number of web and mobile products across social networking, communications, media, games, finance, and more. WeChat, owned by Tencent, is China’s leading mobile app with over 1 billion monthly active users.
WeChat is a leading lifestyle ‘super app’ used for messaging between people, as well as connecting people, services, and businesses in China and around the world through a number of e-commerce and social features inside the app. WeChat Pay, the payment wallet inside the WeChat app, has over 800 million users.
Payment type | Wallet |
Markets | China |
Processing currencies | EUR, USD, GBP |
Refunds | Yes |
General flow
POST Request -> to /payment_preauthorize
<- Response (direct, synchronous) with status=0&errormessage=pending and redirect_url
Customer is redirected to redirect_url to complete payment
<- HTML response with status=0 (or decline) to return_url
<- Callback (asynchronous) with errorcode=0 to notification_url
Desktop based solution
Step 1. Make a transaction request
From your server, make a POST /payment_preauthorize request.
POST https://sandbox.payabl.com/pay/backoffice/payment_preauthorize
Include in request:
Parameter | Format | Description |
---|---|---|
merchantid | 40 characters | Merchant identification number assigned during account creation |
orderid | max. 40 characters | The field orderid is optional and exclusively for the merchants' convenience |
amount | digits only, either no decimals or two decimal places (e.g. 8 or 8.50) | Transaction’s total amount that will be deducted from the customer |
currency | 3 characters. ISO 4217 | The currency field contains the alpha-3 currency code for the transaction. Links to ISO |
payment_method | 5 | payabl. Payment methods IDs |
signature | 40 characters | Signature Calculation |
custom2 | wechatpay | The name of payment method |
accountname | 3-100 characters | Customer account name |
email | max. 50 characters | Customer email. An RFC 822 compliant email address |
firstname | max. 50 characters | First name of the customer |
lastname | max. 50 characters | Last name of the customer |
bankcountry | 2 characters | country of the customer's bank account. For Wechattpay it is CN |
url_success | max. 255 characters starting with http or https | URL for customer redirection in Success status |
url_failed | max. 255 characters starting with http or https | URL for customer redirection in Failed status |
You can see a full list of parameters in Pre-Authorization .
Request example:
merchantid=gateway_test&orderid=Payabl-Test&amount=19.99¤cy=EUR&payment_method=5&language=en&customerip=2.22.75.244&
[email protected]&firstname=John&lastname=Doe&zip=853012&street=Baoshan Road&house=227&city=Shanghai&accountname=John Doe&
bankcountry=CN&custom2=wechatpay&url_return=https://yourshop.example/thank_you¬ification_url=https://yourshop.example/notification&
signature=21ae5108aa11a34d749de22dacfcc1a85334da1e
Public Sandbox information
Do not use your personal email address, Order ID with sensitive information, real customer details and credit card data in the public Sandbox. For email field you may use [email protected].
Redirection to
url_return
does not confirm that the transaction is successful. Always check the transaction vianotification_url
or use the diagnose interface to get the final status of the transaction.
Step 2. Handle the redirect
To complete the payment, you need to redirect the customer to the correct URL in the response.
Response example:
transactionid=105175176&transid=105175176&status=0&errormessage=pending&errmsg=pending&amount=19.99&price=19.99¤cy=EUR&
orderid=Payabl-Test&payment_guarantee=&redirect_url=https%3A%2F%2Fr2.girogate.de%2Fwechatpay%2FS1067%2FI%3Ftx%3D2075066542%26rs
%3D51gwMhNScinltTnRDPjSCEBbDc1WKW99%26cs%3D42d847979945c2e2d61c953eebc724bc57c18ef215dd3d746632dc4d1df2075d&fail_reason=&
ppro_id=2075066542&redirect_secret=sLxXi3B718nT8WRa13B9MCZ3Miti2XL0&user_id=704535
Response fields reference:
Parameter | Description |
---|---|
transactionid | payabl. internal transaction id. Please use this transaction id when referring to the transaction in communications with the payabl. team |
transid | The same as transactionid |
status | Transaction error code |
errormessage | Brief explanation of transaction decline reason (empty on success) |
errmsg | The same as errormessage |
amount | Transaction amount |
price | The same as amount |
currency | Transaction currency |
orderid | Optional transaction identifier given by the merchant |
ppro_id | Payment system's transaction id |
fail_reason | Payment system's explanation of fail reason |
redirect_secret | Signature for redirection to the payment system's iframe (no actions needed) |
redirect_url | URL for customer redirection to finalize the payment (URL encoded) |
payment_guarantee | Payment system technical field |
user_id | Payment system user identifier |
Step 3. Receive the final status
Once the customer completes the payment, we will send a notification with the transaction's final status to the notification_url
specified by you.
Payment methods that are accessible under ID
5
have a callback structure different from other payment methods. Please note that payabl. transaction ID is not passed in them, so you will need to identify the transaction in question by the Order ID (which is passed in the TXID field).Also, the notification signature for these payment methods is calculated differently from other payment methods. Please see the calculation steps below:
- Sort all notification parameters values by parameter name in alphabetical order.
- Append your secret to the end of the concatenated string.
- Calculate a SHA-1 hex value of the string.
Notification example:
PAYMENTGUARANTEE=NONE&TXID=Payabl-Test&HASH=138217dc940e0698eb9a9803afb31025ff3d3b87&REQUESTSTATUS=SUCCEEDED&
TAG=wechatpay&ERRMSG=&STATUS=SUCCEEDED
Notification fields reference:
Parameter | Description |
---|---|
TAG | Payment method identifier |
PAYMENTGUARANTEE | Payment system technical field |
REQUESTSTATUS | Request status (technical field) |
STATUS | Transaction status (SUCCEEDED for success) |
ERRMSG | Brief explanation of transaction decline reason (empty on success) |
TXID | payabl. order ID - optional transaction identifier given by the merchant |
HASH | Signature to verify the authenticity of the notification. You can find more information here |
url_return
andnotification_url
should be passed by you in the Pre-authorization request.Alternatively, you can communicate a
notifciation_url
to be used by default to payabl. technical team. By doing so, you won't need to send it in every request.
Mobile based solution
Step 1. Make a transaction request
From your server, make a POST /payment_preauthorize request.
POST https://sandbox.payabl.com/pay/backoffice/payment_preauthorize
Include in request:
Parameter | Format | Description |
---|---|---|
merchantid | 40 characters | Merchant identification number assigned during account creation |
orderid | max. 40 characters | The field orderid is optional and exclusively for the merchants' convenience |
currency | 3 characters. ISO 4217 | The currency field contains the alpha-3 currency code for the transaction. Links to ISO |
payment_method | 5 | payabl. Payment methods IDs |
amount | digits only, either no decimals or two decimal places (e.g. 8 or 8.50) | Transaction’s total amount that will be deducted from the customer |
signature | 40 characters | Signature Calculation2 |
custom2 | wechatpayh5 | The name of payment method |
accountname | 3-100 characters | Customer account name |
email | max. 50 characters | Customer email. An RFC 822 compliant email address |
firstname | max. 50 characters | First name of the customer |
lastname | max. 50 characters | Last name of the customer |
url_return | max. 255 characters starting with http or http | URL for customer redirection after payment complete |
url_success | max. 255 characters starting with http or https | URL for customer redirection for Successful status |
url_fail | max. 255 characters starting with http or https | URL for customer redirection for Failed status |
customerip | max. 39 characters. Customer IP | IP address of customer |
bankcountry | 2 characters | country of the customer's bank account. For Wechatpay it is usually CN |
You can see a full list of parameters in Pre-Authorization .
Request example:
../payment_preauthorize&merchantid=gateway_test&amount=1.23¤cy=USD&orderid=Payabl-Test&language=en
&gender=&lastname=&street=&zip=&city=&country=&customerid=&salutation=&title=&firstname=&company=&
birthday=&house=&postbox=&state=&email=&phone=&fax=&mobile=&customerip=127.0.0.1&custom1=&
custom2=wechatpayh5&custom3=&url_return=http://dev-sim-ng.inatec.local/~simdad/InatecResponse/redirec
t_response.php&url_success=http://dev-sim-ng.inatec.local/~simdad/InatecResponse/success.php&url_faile
d=http://dev-sim-ng.inatec.local/~simdad/InatecResponse/failed.php¬ification_url=https://api.powerc
ash.de/simulation/billing_response.php&payment_method=5&accountname=Gateway+Test&bankcountry=CN&signature=93efc9ae00366cfefdcc927375b4d5abb87c77d0
Public Sandbox information
Do not use your personal email address, Order ID with sensitive information, real customer details and credit card data in the public Sandbox. For email field you may use [email protected].
Redirection to
url_return
does not confirm that the transaction is successful. Always check the transaction vianotification_url
or use the diagnose interface to get the final status of the transaction.
Step 2. Handle the redirect
To complete the payment, you need to redirect the customer to the correct URL in the response.
Response example:
transactionid=215479405&transid=215479405&status=0&errormessage=pending&errmsg=pending&amount=1.23&
price=1.23¤cy=USD&orderid=Payabl-Test&payment_method=5&redirect_url=https://r2.girogate.de/
wechatpay/S1461/I?tx=2138384845&rs=rJG9Lc5BeHe26NYnXf4B0nxsTjXWwzYF&cs=ca2bc13b8779493dfa18ef861b2e
5ac0acc14fd47a5c45d13b788726da217a97&payment_guarantee=&fail_reason=&redirect_secret=Sdaf0Tn8j7LYK3
Oagsl2eJ01YQLaUAjM&ppro_id=2138384845&user_id=254214&custom2=wechatpayh5
Response fields reference:
Parameter | Description |
---|---|
transactionid | payabl. internal transaction id. Please use this transaction id when referring to the transaction in communications with the payabl. team |
transid | The same as transactionid |
status | Transaction error code |
errormessage | Brief explanation of transaction decline reason (empty on success) |
errmsg | The same as errormessage |
amount | Transaction amount |
price | The same as amount |
currency | Transaction currency |
orderid | Optional transaction identifier given by the merchant |
ppro_id | Payment system's transaction id |
fail_reason | Payment system's explanation of fail reason |
redirect_secret | Signature for redirection to the payment system's iframe (no actions needed) |
redirect_url | URL for customer redirection to finalize the payment (URL encoded) |
payment_guarantee | Payment system technical field |
user_id | Payment system user identifier |
Step 3. Receive the final status
Once the customer completes the payment, we will send a notification with the transaction's final status to the notification_url
specified by you.
Payment methods that are accessible under ID
5
have a callback structure different from other payment methods. Please note that payabl. transaction ID is not passed in them, so you will need to identify the transaction in question by the Order ID (which is passed in the TXID field).Also, the notification signature for these payment methods is calculated differently from other payment methods. Please see the calculation steps below:
- Sort all notification parameters values by parameter name in alphabetical order.
- Append your secret to the end of the concatenated string.
- Calculate a SHA-1 hex value of the string.
Notification example:
REQUESTSTATUS=SUCCEEDED&STATUS=SUCCEEDED&TXID=2138384845&ERRMSG=&CHANNEL=testchannel&TAG=wechatpayh5&
PAYMENTGUARANTEE=NONE&REDIRECTSECRET=Sdaf0Tn8j7LYK3Oagsl2eJ01YQLaUAjM&SPECOUT.CNYAMOUNT=9.64&
SPECOUT.FXRATE=7.843417&SPECOUT.SETTLEMENTAMOUNT=123&SPECOUT.SETTLEMENTCURRENCY=USD&SPECOUT.SRCAMOUNT=964&SPECOUT.SRCCURRENCY=CNY
Notification fields reference:
Parameter | Description |
---|---|
TAG | Payment method identifier |
PAYMENTGUARANTEE | Payment system technical field |
REQUESTSTATUS | Request status (technical field) |
STATUS | Transaction status (SUCCEEDED for success) |
ERRMSG | Brief explanation of transaction decline reason (empty on success) |
TXID | payabl. order ID - optional transaction identifier given by the merchant |
HASH | Signature to verify the authenticity of the notification. You can find more information here |
url_return
andnotification_url
should be passed by you in the Pre-authorization request.Alternatively, you can communicate a
notifciation_url
to be used by default to payabl. technical team. By doing so, you won't need to send it in every request.
Code for Device Type Recognition
To enable a seamless payment experience across multiple customer devices, merchants interested in utilizing both the web and mobile solutions from WeChat Pay should implement the provided script. This script is designed to automatically identify the customer's device—be it mobile or desktop —and redirect the user to the appropriate WeChat Pay solution, thereby enhancing the user experience. The requisite script is outlined below for your reference.
<script>
document.addEventListener("DOMContentLoaded", (event) => {
if (isMobile()) {
// show wechatpayh5 option for mobile;
}
else
{
// show wechatpay option for web;
}
});
/**
* check platform web or mobile
*/
function isMobile() {
const regex = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
return regex.test(navigator.userAgent);
}
</script>
Refunds
WeChat Pay supports refunds which can be initiated only on a successful captured transaction.
The request will send a credit note to the authorization system after the customer has already been charged. The refund amount will be credited to the customer and the merchant’s account will be charged.
The refund can be done in two ways:
- Through API integration
- Through payabl. dashboard
If you have API integration, you can check more in our documentation Refund.
Our Technical Support team is there to help you:
Email: [email protected]
Available Monday – Friday between 09:00 and 17:00 CET/CEST
Updated about 2 months ago