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.

An image

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 IDChannel Name
WX_APPWeChat Pay
ALIPAY_MOBILEAlipay
UPI_APPUnionPay's SecurePay in app

API Request from Merchant Backend

Endpoint

https://api.iotpaycloud.com/v1/create_order

Method

POST

Content-Type: application/x-www-form-urlencoded

Parameters

namerequiredtypesampledescription
mchIdyString(30)10000701merchant ID assigned by IOTPay
mchOrderNoyString(30)20160427210604000490order number in merchant system, need to be unique
channelIdyString(24)ALIPAY_MOBILEALIPAY_MOBILE OR WX_APP OR UPI_APP
currencyyString(3)CADonly CAD and USD supported
amountyint100payment amounts, in cents, e.g. $28.56 is 2856
clientIpyString(32)210.73.10.148Client IP
devicenString(64)WEBdevice identifier
notifyUrlyString(200)http://xxx.com/notify.phpIOTPay will notify this URL when payment success
subjectyString(64)product ID or titleproduct ID or title
bodyyString(255)product descriptionthe description of the product
param1nString(64)IOTPay will send back the original value
param2nString(64)IOTPay will send back the original value
extrayString(512){"type":"apppay","appId":"xxxxxxxxx"}WeChat mini program, WX_APP, WX_APP need this
jobNoyString(50)merchant login name
remarksnString(200)remarks
signyString(32)C380BEC2BFD727A4B6845133519F3AD6signature

WeChat App(WX_APP)

Note

To obtain your WeChat appId, please register your app at WeChat's Weixin Open Platformopen in new window. Note that you will have to create an account if it's the first time you are using Weixin Open Platformopen in new window.

namerequiredtypesampledescription
extrayJSON{"type":"apppay","appId":"xxxxxxxxx"}

Alipay App(ALIPAY_MOBILE) or UPI_APP

namerequiredtypesampledescription
extranJSONignore 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:

Demo source code

downloadopen in new window

Last Updated: