# App integrate IOTPay
# Basic process
There are four roles in the whole integration:
1, Merchant App
2, Merchant backend server
3, IOTPay API server
4, Third party(Alipay, WechatPay, UnionPay) server
Merchant App send payment request to IOTPay API server, IOTPay API return the encrypted data to the merchant app, then merchant app send the encrypted data to the third party pay server via SDK. IOTPay API server will notify merchant backend server when the transaction is successful.
# Merchant App call merchant backend server api
The API is defined by merchant,can use the following as reference:
Server address: https://merchant_server/pay?channelid=XXX&amount=xxx
- Request method: GET
Merchant backend server call create order api of IOTPay, after get the request from merchant app.
# for app integration, channel should be :
Channel ID | Channel Name |
---|---|
WX_APP | Wechat Pay |
ALIPAY_MOBILE | Alipay |
UPI_APP | UnionPay's SecurePay in app |
# merchant backend call create order api
# request URL
Endpoint: https://api.iotpaycloud.com/v1/create_order
Request method:
- POST
- 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) | ALIPAY_MOBILE | ALIPAY_MOBILE OR WX_APP OR UPI_APP |
currency | y | String(3) | CAD | 3 letters representation for currency |
amount | y | int | 100 | payment amount,in cents,eg. $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 | product description |
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) | {"type":"apppay","appId":"xxxxxxxxx"} | wechat mini program,WX_APP,WX_APP need this |
jobNo | y | String(50) | merchant login name | |
remarks | n | String(200) | remarks | |
sign | y | String(32) | C380BEC2BFD727A4B6845133519F3AD6 | signature |
# Wechat App(WX_APP)
| extra | y | JSON | {"type":"apppay","appId":"xxxxxxxxx"} | |
# Alipay App(ALIPAY_MOBILE) or UPI_APP
| extra | n | JSON | ignore this parameter | |
# php sample code
require_once('Utility.php');
$url = 'http://api.iotpaycloud.com/v1/create_order';
$merchantId = '1000####';
$merchantKey = '#############################';
$channelId = $_REQUEST['channelid'];
$orderAmount = $_REQUEST['amount'];
$orderNo = $_SERVER['REQUEST_TIME'];
$Utility = new Utility();
$ip = $Utility->real_ip();
$notifyUrl = 'https://develop.iotpay.ca/demo/order/notify.php';
$subject = 'test';
$body = 'paytest';
$extra = '';
if($channelId =='WX_APP')
{
$appId = 'wxxxxxxxxxxxxxx';
$type = 'apppay';
$extra = json_encode(array(
'type' => $type,
'appId' => $appId,
));
}
$arr = array(
'mchId' => $merchantId,
'mchOrderNo' => $orderNo,
'extra' => $extra,
'channelId' => $channelId,
'currency' => 'CAD',
'amount' => intval($orderAmount * 100),
'clientIp' => $ip,
'device' => 'WEB',
'notifyUrl' => $notifyUrl,
'subject' => $subject,
'body' => $body,
);
$sortArray = $Utility->arg_sort($arr);
$arr['sign'] = $Utility->build_mysign($sortArray, $merchantKey, "MD5");//Generate signature parameter sign
$param = 'params=' . json_encode($arr);
$resBody = $Utility->request($url, $param);//Submit to the gateway
$res = json_decode($resBody, true);
echo json_encode($res['payParams']); //client app use payParams to call sdk
# Wechat/Alipay/UnionPay SDK and Documents:
- Alipay SDK
- Alipay source code
- Wechat pay SDK
- Wechat pay source code
- Union Pay SDK for IOS
- Union Pay SDK for Android