Refund interface

This interface is for WeChatPay, Alipay and UnionPay only.

API Request

Endpoint

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

Method

POST

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

! Tip

After you receive access credentials (merchant id, login name, merchant key). You can step through the demo Refund Orderopen in new window to test out the workflow for this functionality. Which may help you when going through the documentation.

Parameters

NameRequiredTypeSampleDescription
mchIdyString(30)20001222merchant id assigned by IOTPay
mchRefundNoyString(30)20160427210604000490generated by merchant
refundAmountyint100refund amount in cents,<= pay amount
clientIpyString(32)210.73.10.148client ip
devicenString(64)WEB
loginNameyString(32)xxxmerchant login name
payOrderIdyString(64)U00180918065500913991007022order id must be the same with original order id
signyString(32)C380BEC2BFD727A4B6845133519F3AD6signature

Note

Due to backwards compatibility requirements, we require the parameters to be wrapped like the following:

params={"channelId":"WX_MICROPAY","clientIp":"24.80.45.254","device":"","loginName":"vincent","mchId":"10000576","mchRefundNo":"1537224899791","payOrderId":"U00180918065500913991007022","refundAmount":"1","sign":"75BB98BD083B7F2F7FDEFF5852F3D526"}

return result

NameRequiredTypeSampleDescription
retCodeyString(16)SUCCESSSUCCESS/FAIL,retCode indicate communication status,
still need to check resCode to judge transaction status
retMsgnString(128)signature errorerror message

Sample Code

require_once('Utility.php');
$merchant_id = $_POST['merchantid'];
$merchant_key = $_POST['merchantKey'];
$url = 'https://api.iotpaycloud.com/v1/refund_order';
$order_amount = $_POST['orderamount'];
$order_sn = $_SERVER['REQUEST_TIME'];
$Utility = new Utility();
$ip = $Utility->real_ip();
$loginname = $_POST['loginname'];
$payorderid = $_POST['payorderid'];
$arr = array(
    'mchId' => $merchant_id,
    'mchRefundNo' => $order_sn,
    'loginName' => $loginname,
    'currency' => 'CAD',
    'refundAmount' => intval($order_amount * 100),
    'clientIp' => $ip,
    'payOrderId' => $payorderid,
);
$sort_array = $Utility->arg_sort($arr);
$arr['sign'] = $Utility->build_mysign($sort_array, $merchant_key, "MD5"); //Generate signature parameter sign
$param = 'params=' . json_encode($arr);
$resBody = $Utility->request($url, $param); //Submit to the gateway
$res = json_decode($resBody, true);
if ($res['retCode'] == 'SUCCESS' AND $res['resCode'] == 'SUCCESS') {
    echo "Refund successfully";
} else {
    echo 'Order payment failed!' . $res['retMsg'] . $res['errCodeDes'];
}

Last Updated: