WeChat Mini Program
This endpoint requires the merchant to have a pre-existing WeChat Mini Program that is registered under a non-Chinese company.
API Request
Endpoint
https://api.iotpaycloud.com/v1/create_order
Method
POST
Header
Content-Type: application/x-www-form-urlencoded
Parameters
| Name | Required | Type | Sample | Description |
|---|---|---|---|---|
| mchId | y | String(30) | 10000701 | merchant ID assigned by IOTPay |
| mchOrderNo | y | String(30) | 20160427210604000490 | order number in merchant system, need to be unique |
| channelId | y | String(24) | WX_JSAPI | Fixed to WX_JSAPI |
| currency | y | String(3) | CAD | 3 letters representation for currency |
| amount | y | int | 100 | payment amounts, in cents, e.g. $28.56 is 2856 |
| clientIp | y | String(32) | 210.73.10.148 | Client IP |
| device | n | String(64) | WEB | device identifier |
| notifyUrl | y | String(200) | http://xxx.com/notify.php | IOTPay will notify this URL when payment success |
| subject | y | String(64) | product ID or title | product ID or title |
| body | y | String(255) | product description | the description of the product |
| param1 | n | String(64) | IOTPay will send back the original value | |
| param2 | n | String(64) | IOTPay will send back the original value | |
| extra | y | String(512) | {"openId":"o2R****eaDqo", "type":"minipay","appId":"xxxxxxxxx"} | |
| jobNo | y | String(50) | merchant login name | |
| remarks | n | String(200) | remarks | |
| sign | y | String(32) | C380BEC2BFD727A4B6845133519F3AD6 | signature |
When merchant get the response from IOTPay API, pass the returned parameters to mini program. Mini program will call wx.requestPayment with these parameters.
wx.requestPayment({
appId: res.data.payParams.appId,
timeStamp: res.data.payParams.timeStamp,
nonceStr: res.data.payParams.nonceStr,
package: res.data.payParams.package,
signType: res.data.payParams.signType,
paySign: res.data.payParams.paySign,
success(res) {
console.log(res)
wx.navigateTo({
url: '',
})
},
fail(res) {
console.log(res)
wx.navigateTo({
url: '',
})
},
})After payment, merchant backend server still need notifyUrl to judge whether the transaction is successful
Return Fields
| Name | Required | Type | Sample | Description |
|---|---|---|---|---|
| retCode | y | String(16) | SUCCESS | SUCCESS/FAIL this field indicate communication result, not transaction. Need to check resCode to see whether transaction succeed |
| retMsg | n | String(128) | signature error | error message |
The following fields will return when retCode and resCode are both SUCCESS
| Name | Required | Type | Sample | Description |
|---|---|---|---|---|
| payOrderId | y | String | payment order ID | |
| payParams | y | Array | the parameters for mini program to call wx.requestPayment | |
| sign | y | String | signature |
Error Code
Sample Code
sample code download
