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 |
API Request from Merchant Backend
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) | ALIPAY_MOBILE | ALIPAY_MOBILE OR WX_APP OR UPI_APP |
currency | y | String(3) | CAD | only CAD and USD supported |
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) | {"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)
Note
To obtain your WeChat appId
, please register your app at WeChat's Weixin Open Platform. Note that you will have to create an account if it's the first time you are using Weixin Open Platform.
name | required | type | sample | description |
---|---|---|---|---|
extra | y | JSON | {"type":"apppay","appId":"xxxxxxxxx"} |
Alipay App(ALIPAY_MOBILE) or UPI_APP
name | required | type | sample | description |
---|---|---|---|---|
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