WeChat Pay Online

You are here:
← All Topics

 

MC Payment provides 4 methods of accepting WeChat Pay for online transactions as follows:

  1. EWallet Unified Order Payment
  2. EWallet Payment in WeChat Browser
  3. EWallet In-App Payment for WeChat Official Accounts
  4. EWallet WeChat Mini Program Payment

 

Payment flow for each method

 

EWallet Unified Order Payment

This method requires the WeChat Pay user to access merchant website on a device does not have his wechat app installed, ie User access merchant on his PC or Laptop and later uses his mobile phone to pay by WeChat Pay. The payment process is as follows:

How to send an Ewallet Unified Order request >

EWallet Payment in WeChat Browser

This method requires the WeChat Pay user to access merchant website in his WeChat app. The payment process is as follows:

How to send an Ewallet Payment in WeChat Browser request >

 

EWallet In-App Payment

This method requires the merchant to have a WeChat Official Account. WeChat user to access merchant official account in his WeChat app. The payment process is as follows:

How to send an EWallet In-App Payment request >

 

EWallet Mini Program Payment

This method requires the merchant to have a WeChat Official Account. With this, merchant is able to develop a mini program to issue coupons or sell products and more. For more info on WeChat Mini Programs, please click here >. The payment process is as follows:

How to send an EWallet Mini Program Payment >

 

Integration Doc

API Specification Titles

Name​: This column specifies the name of JSON field in request or response.

Max Length​: This column specifies the content and maximum length of value of JSON field.
a – Alpha
n – Numeric
s – Special printable character

Type​: This column specifies the type of JSON field.

  1. String – the value is in string type;
  2. Nested JSON – the value is a JSON object.

Required​: This column specifies the requirement of JSON field
1. M – Mandatory. MCP system will validate this field in request and response
2. C – Conditional. In some conditions, this field is Mandatory. The condition will be specified in the Description column.
3. O – Optional. This field is optional, which will not affect the result of transaction.

Description​: This column describe the usage, conditions or values contained of this JSON field.
eCom – The web based payment solution, the request is sent from merchant website or web
application.

Security Standards
MCP API provides different types of security standard.
HTTPS​: First layer of security which is compulsory for all connections to MCP API. TLS 1.2.
Whitelist​: IP white list is optional.

EWallet Unified Order request

MCP backend calls this API to create an advance transaction in the EWallet payment service backend, and initiates the payment process via payment by QR Code.

Send the request data as specified in the Request Data table below.

Protocol Format
MediaTypes​: JSON format
Protocol​ : https
Server Port ​: 8443
Method​ : POST
Server URL ​:  https://gw2.sandbox.mcpayment.net
EndPoint: ​api/v5/ewallet/unifiedOrder

Request Data

Important notes:

  1. USER_PAYING (transaction state 71): It may take sometime for WeChat host to update us on the payment result. Merchant may wish to run a transaction query (set at specified intervals) to finalize the payment result, by using transaction Id returned in the unified order request. For more info on Transaction state see here >
  2. Receipt Number: A receipt number will be generated and returned in the response if payment is successful.
  3. Signature: see here >

Request sample:
{
“header”: {
“version”: “5”,
“appType”: “APP”,
“appVersion”: “1.2.3”,
“mcpTerminalId”: “3119110001”,
“signature”:”5Jv2C*x,n[+X]f5!fxt<qy8U;r”|K>”
},
“data”: {
“currency”: “USD”,
“referenceNo”: “52431f516”,
“totalAmount”: “10”,
“description”: “ewallet”,
“eType”: “77771”,
“clientUrl”: “https://mcpayment.com/callback”
}
}

Response sample (sent to statusurl):
{
“header”: {
“version”: “5”,
“appType”: “APP”,
“appVersion”: “1.2.3”,
“status”: {
“responseCode”: “0000”,
“message”: “”
}
},
“data”: {
“transactionId”: “12107”,
“transactionState”: “71”,
“walletType”: “77771”,
“walletPaymentType”: “72001”,
“totalAmount”: “5000”,
“amountSettled”: “39”,
“amountInCNY”: “250”,
“currency”: “USD”,
“currencySettled”: “USD”,
“qrUrl”: “weixin://wxpay/bizpayurl?pr=b5abFwF”,
“errorMessage”: “”
“referenceNo”: “52431f516”
}
}
A QR code will be generated and displayed on the merchant’s website. WeChat user pays by opening his WeChat app to scan and pay.

Response Data
Generating Signature

In the Unified Order API, before sending transaction request merchant needs to generate a Signature once. This can be done by sending a request to the Terminal Authentication API. Every merchant will be issued a “userId”, “password” and “password hash key”. Generate signature using signKey, hash ‘data’ string by Hmac SHA512, and to be used as ‘signature’ in requests’ ‘header’ object (Not HTTP Headers). Convert data object to string and hmac SHA512 with “signKey” returned from auth/terminal API

Sample Code in Java:
Gson gson = ​new ​Gson();
String dataJson = gson.toJson(​dataObject​);
String signature = SymmetricCrypto.​hmacSHA512​(dataJson, signKey);

public static ​String ​hmacSHA512​(String dataJson, String key) { ​try ​{
​byte​[] bytesKey = key.getBytes();
​final ​SecretKeySpec secretKey = ​new ​SecretKeySpec(bytesKey, ​HMAC_SHA512​); Mac mac = Mac.​getInstance​(​HMAC_SHA512​);
mac.init(secretKey);
​final byte​[] macData = mac.doFinal(dataJson.getBytes());
​byte​[] hex = ​new ​Hex().encode(macData);
​return new ​String(hex, ​ISO_8859_1)​ ;
} ​catch ​(NoSuchAlgorithmException e) { e.printStackTrace();
} ​catch ​(InvalidKeyException e) { e.printStackTrace();
} ​catch ​(UnsupportedEncodingException e) {s e.printStackTrace();
}
​return null​; }

Terminal Authentication

Client’s terminal must be registered to the server and the server will then validate the request parameters and returns the terminal identification, which the client will use for future transactions.

Protocol Format
MediaTypes​: JSON
format Protocol​ : https
Server Port ​: 8443
Method​ : POST
Server URL ​: https://gw2.sandbox.mcpayment.net
EndPoint: ​api/v5/auth/terminal

Terminal authentication request data

Sample Request:
{
“header”: {
“version”: “5”,
“appType”: “W”,
“appVersion”: “1.00.00”
},
“data”: {
“userId”: “mcp123”,
“password”: “2B2E4C1B8A889684E40633677214F0A0F55C07CDEE210A01E7DE784A0B5E4D9BC5352C273815D991B46E1F33FE05B6648AE07B76CEC02F3B683D5AE88A128B11”
}
}

You will receive a response in the following example:

{
“header”: {
“version”: “5”,
“appType”: “W”,
“appVersion”: “1.00.00”,

“status”: {
“responseCode”: “0000”,
“message”: “Approved”
}
},
“Data”: {
“mcpTerminalId”: “12345671”,
“signKey”: “ShqHvaW/54Y9c/R5o1vNLP1w/7ksoRm+qjTZ3p2GaQA=”,
“routeList”: [
“USD;amexHost”, “SGD;alipayHost”, “SGD;fdHost”, “SGD;wechatHost”
]
}
}

You can use the same signKey (signature) for all other requests. The signKey (signature) can be generated monthly or any frequency you prefer.

 

EWallet payment in WeChat Browser

Send the request data as specified in the Request Data table below.

Protocol Format
MediaTypes​: JSON format
Protocol​ : https
Server Port ​: 8443
Method​ : POST
Server URL ​:  https://gw2.sandbox.mcpayment.net
EndPoint: ​api/v6/payment
This Request has no header because it is a two steps payment process, 1. Get the url and 2. Payment will be done in WeChat

Request Data

Important notes:

  1. No Header in Payment Page API request
  2. User will automatically check out with his WeChat EWallet.
  3. The notification will be post to StatusUrl right after payment is completed. Refer to StatusUrl Postback
  4. If no callback after 30 mins (or longer), please call ​Query Details API​ with ‘referenceNo’, ‘currency’ and ‘totalAmount’ to confirm the state of transaction. If NO TRANSACTION FOUND, it means user didn’t complete the payment.

Request sample (No header):
{
“mcptid”: “3119110001”,
“currency”: “USD”,
“amount”: “1”,
“referenceNo”: “WeChat payment”,
“statusUrl”: (backend),
“returnUrl”: (frontend),
“itemDetail”: “Item”,
“tokenize”: “N”
}

The WeChat user will be automatically asked to complete the payment via his WeChat EWallet

StatusUrl Postback

 

EWallet In-App Payment (WeChat official Accounts)

Send the request data as specified in the Request Data table below.

Protocol Format
MediaTypes​: JSON format
Protocol​ : https
Server Port ​: 8443
Method​ : POST
Server URL ​:  https://gw2.sandbox.mcpayment.net
URI: ​api/v6/ewallet/in-app-pay

Request Data

Sample request 
{
“header”: {
“version”: “6”,
“appType”: “W”,
“appVersion”: “2”,
“mcpTerminalId”: “123123”
},
“data”: {
“currency”: “SGD”,
“totalAmount”: “0.01”,
“description”: “In-App Payment”,
“eType”: “77771”,
“referenceNo”: “123123”,
“appId”: “wx12345678abcdefg”
}
}

Response Data


*USER_PAYING state: 71 (note : there maybe a delay in transmitting transaction result from wechat host to MCP, hence the transaction result will show “USER_PAYING”. In such cases, the merchant system can send a query request (set at specified intervals) to check for the final status.

Response sample:
{
“header”: {
“version”: “5”,
“appType”: “APP”,
“appVersion”: “1.2.3”,
“status”: {
“responseCode”: “0000”,
“message”: “”
}
},
“data”: {
“transactionId”: “12107”,
“transactionState”: “71”,
“walletType”: “77771”,
“walletPaymentType”: “72001”,
“totalAmount”: “5000”,
“amountSettled”: “5000”,
“amountInCNY”: “250”,
“currency”: “SGD”,
“currencySettled”: “SGD”,
“appId”: “wx8888888888888888”,
“​prepayId​”: “WX1217752501201407033233368018”,
“​package​”:
“Sign=WXPay”,
“​nonceStr​”: “5K8264ILTKCH16CQ2502SI8ZNMTM67VS”,
“​sign​”: “C380BEC2BFD727A4B6845133519F3AD6”,
“​timestamp​”: “1412000000”,
“errorMessage”: “”
“referenceNo”: “52431f516”
}
}

EWallet Mini Program Payment

Send the request data as specified in the Request Data table below.

Protocol Format
MediaTypes​: JSON format
Protocol​ : https
Server Port ​: 8443
Method​ : POST
Server URL ​:  https://gw2.sandbox.mcpayment.net
URI: ​api/v6/ewallet/mini-program-pay

Request Data

Request sample:
{
“header”: {
“version”: “6”,
“appType”: “W”,
“appVersion”: “2”,
“mcpTerminalId”: “123123”
},
“data”: {
“amountSettled”: “39”,
“currency”: “SGD”,
“totalAmount”: “0.01”,
“description”: “In-App Payment”,
“eType”: “77771”,
“referenceNo”: “123123”,
“appId”: “wx12345678abcdefg”,
“openId”: “oUpF8uMuAJO_M2pxb1Q9zNjWeS6o”
}
}

Response Data

Response sample
{
“header”: {
“version”: “5”,
“appType”: “APP”,
“appVersion”: “1.2.3”,
“status”: {
“responseCode”: “0000”,
“message”: “”
}
},
“data”: {
“transactionId”: “12107”,
“transactionState”: “71”,
“walletType”: “77771”,
“walletPaymentType”: “72001”,
“totalAmount”: “1”,
“amountSettled”: “1”,
“currency”: “SGD”,
“currencySettled”: “SGD”,
“appId”: “wx8888888888888888”,
“​package​”: “prepay_id=123456789”,
“​nonceStr​”: “5K8264ILTKCH16CQ2502SI8ZNMTM67VS”,
“​paySign​”: “C380BEC2BFD727A4B6845133519F3AD6”,
“​signType​”: “MD5”,
“​timestamp​”: “1412000000”,
“errorMessage”: “”
“referenceNo”: “52431f516”
}
}

Transaction Type
Transaction State
Response Codes

Ready to start? Sign up to request for sandbox account >

Company
Merchant
Resources
Connect with us
Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from Youtube
Vimeo
Consent to display content from Vimeo
Google Maps
Consent to display content from Google