WeChat Pay

WeChat Pay is one of the biggest and fastest-growing mobile payment solutions in China.

About WeChat Pay

With over 600 million active monthly users, WeChat Pay provides individuals and businesses with an easy, safe and secure way to make and receive payments over the internet.

Accept a WeChat Pay payment

To accept a WeChat payment, follow the steps below.

When testing, do not use real customer data. Use the test data prepared by unzer.

Step 1: Create a wechatpay resource

To create a wechatpay resource, make a POST call with an empty request body to types/wechatpay:

POST https://api.unzer.com/v1/types/wechatpay

Body: {}
{
    "id": "s-wcp-otvqlpgqsh7u",
    "method": "wechatpay",
    "recurring": false,
    "geoLocation": {
        "clientIp": "115.77.189.143",
        "countryCode": "VN"
    }
}
Property Type Description
id String The returned ID of the wechatpay resource that you just created.
method String The payment method.
recurring Boolean Indicates if this is a recurring payment.
clientIp String The IP address of the device used for the payment.
countryCode String The country associated with clientIp, displayed in the ISO 3166-1 alpha-2 format.

Step 2: Make a charges call

To charge the wechatpay resource, make a payments/charges call with the following parameters in the request body:

Parameter Required Type Default Description Example
amount Yes Number / The amount to be charged. 50
currency Yes String / The transaction currency, in the ISO 4217 alpha-3 format. EUR
returnUrl No String / After the customer confirms the payment on the WeChat Pay payment page, returnUrl is called to redirect customer to the shop’s website. https://www.unzer.com
orderId No String / A unique order ID that identifies the payment on your side. Order-12
typeId Yes String / The newly-created payment type ID that you received in response to creating a wechatpay resource (Step 1). s-wcp-otvqlpgqsh7u
customerId No String / The ID of the customers resource to be used. s-cst-1
metadataId No String / The ID of the metadata resource to be used. s-mtd-1
POST https://api.unzer.com/v1/payments/charges

Body:
{
  "amount" : "50",
  "currency" : "EUR",
  "returnUrl" : "https://www.unzer.com",
  "orderId": "",
  "resources" : {
    "typeId" : "s-wcp-otvqlpgqsh7u",
    "metadataId": "",
    "customerId": ""
  }
}
{
    "id": "s-chg-1",
    "isSuccess": false,
    "isPending": true,
    "isError": false,
    "redirectUrl": "https://dev-payment.unzer.com/v1/redirect/wechatpay/laksjdfloikwjerklj2lk3j",
    ....
}
Property Type Description
id String The ID of the wechatpay resource.
isSuccess Boolean Set to true if the transaction was successful.
isPending Boolean Set to true if the transaction is pending
(e.g. if a redirect to an external system is required).
isError Boolean Set to true if an error occurs.
redirectUrl String The URL to which the customer gets redirected after the payment.

Step 3: Forward the customer to the redirect URL

After you charge the wechatpay resource, implement the following flow:

  1. Redirect the customer to the redirectURL.
  2. The customer is forwarded to the WeChat Pay payment page.
  3. After a successful payment, the customer is redirected to the returnURL that you specified in the charges call (Step 2).

Step 4: Check the payment status

After the customer is redirected to the returnUrl, check the status of the payment.

Make a GET call with the following parameters in the request path:

Parameter Required Type Default Description Example
resource_ID Yes String / The returned ID of the wechatpay resource that you created in Step 1. s-wcp-otvqlpgqsh7u
transaction_ID Yes String / The transaction’s unique ID that you received in Step 2. s-chg-1
GET https://api.unzer.com/v1/payments/{resource_ID}>/charges/{transaction_ID}
{
    "id":   "s-chg-1",
    "isSuccess":   true,
    "isPending":   false,
    "isError":     false,
    "redirectUrl": "",
     ...
}
Property Type Description
id String The ID of the wechatpay resource.
isSuccess Boolean Set to true if the transaction was successful.
isPending Boolean Set to true if the transaction is pending
(e.g. if a redirect to an external system is required).
isError Boolean Set to true if an error occurs.
redirectUrl String The URL to which the customer gets redirected after the payment.