Refund interface
This interface is for WeChatPay, Alipay and UnionPay only.
API Request
Endpoint
https://api.iotpaycloud.com/v1/refund_order
Method
POST
Header
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 Order to test out the workflow for this functionality. Which may help you when going through the documentation.
Parameters
Name | Required | Type | Sample | Description |
---|---|---|---|---|
mchId | y | String(30) | 20001222 | merchant id assigned by IOTPay |
mchRefundNo | y | String(30) | 20160427210604000490 | generated by merchant |
refundAmount | y | int | 100 | refund amount in cents,<= pay amount |
clientIp | y | String(32) | 210.73.10.148 | client ip |
device | n | String(64) | WEB | |
loginName | y | String(32) | xxx | merchant login name |
payOrderId | y | String(64) | U00180918065500913991007022 | order id must be the same with original order id |
sign | y | String(32) | C380BEC2BFD727A4B6845133519F3AD6 | signature |
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
Name | Required | Type | Sample | Description |
---|---|---|---|---|
retCode | y | String(16) | SUCCESS | SUCCESS/FAIL,retCode indicate communication status, still need to check resCode to judge transaction status |
retMsg | n | String(128) | signature error | error 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'];
}