Premium payments!
POST https://paycode.unicorn.se/api/v1/setPaycode/bnr
| HEADER ELEMENTS | ||
| Name | Type | Description |
|---|---|---|
| username | string | Generated by Paycode IT Dep. |
| password | string | Generated by Paycode IT Dep. |
| username and password used with basic Auth in HTTP Request - base64_encoded | ||
| partnerid | int | Generated by Paycode IT Dep. |
| apikey | int | Generated by Paycode IT Dep. |
| callback | string |
Optional customer callback url. Executed on succesful paycode entry in IVR Must be base64_encoded |
| cusref | string |
Optional customer json reference object. {account:'113445','email':'olle.olsson@xx.se'} Must be base64_encoded |
| URL ELEMENTS | ||
| url_arg_1 | string | Required premium phonenr (bnr) |
/**
* UNICORN PAYCODE
* EXAMPLE - BACKEND - BASIC AUTH HTTP REQUEST TO API USING 4 CUSTOM HEADERS
*/
/** Handle post api data from client side */
$apicmd=$url_arg_1=$url_arg_2 = '';
$apidata = json_decode($_REQUEST['apidata'],true);
if (isset($apidata)) {
if (isset($apidata['apicmd'])) { $apicmd = $apidata['apicmd'];} // setPaycode
if (isset($apidata['url_arg_1'])) { $url_arg_1 = $apidata['url_arg_1'];} // bnr
if (isset($apidata['url_arg_2'])) { $url_arg_2 = $apidata['url_arg_2'];} // (not used)
}
/** Check data types and if ok, Run HTTP Request */
if (!is_string($url_arg_1) || !is_string($url_arg_2) || !is_string($apicmd)) {
echo json_encode(array("Data type error!", $apidata));
exit();
} else {
apiRequest($apicmd,$url_arg_1,$url_arg_2);
exit();
}
/** HTTPS REQUEST WITH stream_context_create() and file_get_contents */
function apiRequest($apicmd,$url_arg_1,$url_arg_2)
{
/** Partner Auth data */
$username = "apiFlash"; //string
$password = "hjd*Rhdasj67J"; //string
$partnerid = "898989"; //int
$apikey = "896235"; //int
$callback = 'https://www.digitalcare.se/2.0/site/paycode/paycode_callback.php';
$callback = '';
$cusref = array(
'account' => '113445',
'email' => 'olle.olsson@xx.se'
);
/** Encode auth data (username & password) with base64 */
$auth = base64_encode("$username:$password");
$callback = base64_encode("$callback");
$cusref = base64_encode(json_encode($cusref));
/** Set test or production api url's */
$apiurl = "https://193.15.20.88/api/v1"; // TEST/STAGE
//$apiurl = "https://paycode.unicorn.se/api/v1"; //PROD
/** Create the final request url from collected data */
$url = $apiurl.'/'.$apicmd."/".$url_arg_1."/".$url_arg_2;
/** Execute the request */
try {
$opts = [
'http'=> [
'method' => "POST",
'header' => "Authorization: Basic $auth\r\n".
"X-pid: $partnerid\r\n".
"X-key: $apikey\r\n".
"X-callback: $callback\r\n".
"X-cusref: $cusref\r\n"
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
];
$context = stream_context_create($opts);
$http_result = file_get_contents($url, false, $context);
echo json_encode(array('Http request return',$http_result));
exit();
} catch (\Exception $e) {
echo json_encode(array("Http request error!", $e));
}
}
{
bnr: "0850209992",
callback: "https://www.digitalcare.se/2.0/site/paycode/paycode_callback.php",
cusref: "{"account":"113445","email":"olle.olsson@xx.se"}",
paid: "",
paycode: "580887",
price: "50.00",
request: "setPaycode",
timeout: "240"
}
POST https://paycode.unicorn.se/api/v1/checkPaid/bnr/paycode
| HEADER ELEMENTS | ||
| Name | Type | Description |
|---|---|---|
| username | string | Generated by Paycode IT Dep. |
| password | string | Generated by Paycode IT Dep. |
| username and password used with basic Auth in HTTP Request - base64_encoded | ||
| partnerid | int | Generated by Paycode IT Dep. |
| apikey | int | Generated by Paycode IT Dep. |
| callback | string |
Optional customer callback url. Executed on succesful paycode entry in IVR Must be base64_encoded |
| cusref | string |
Optional customer json reference object. {account:'113445','email':'olle.olsson@xx.se'} Must be base64_encoded |
| URL ELEMENTS | ||
| url_arg_1 | string | Required premium phonenr (bnr) |
| url_arg_2 | string | Required paycode (paycode) |
/**
* UNICORN PAYCODE
* EXAMPLE - BACKEND - BASIC AUTH HTTP REQUEST TO API USING 4 CUSTOM HEADERS
*/
/** Handle post api data from client side */
$apicmd=$url_arg_1=$url_arg_2 = '';
$apidata = json_decode($_REQUEST['apidata'],true);
if (isset($apidata)) {
if (isset($apidata['apicmd'])) { $apicmd = $apidata['apicmd'];} // checkPaid
if (isset($apidata['url_arg_1'])) { $url_arg_1 = $apidata['url_arg_1'];} // bnr
if (isset($apidata['url_arg_2'])) { $url_arg_2 = $apidata['url_arg_2'];} // paycode
}
/** Check data types and if ok, Run HTTP Request */
if (!is_string($url_arg_1) || !is_string($url_arg_2) || !is_string($apicmd)) {
echo json_encode(array("Data type error!", $apidata));
exit();
} else {
apiRequest($apicmd,$url_arg_1,$url_arg_2);
exit();
}
/** HTTPS REQUEST WITH stream_context_create() and file_get_contents */
function apiRequest($apicmd,$url_arg_1,$url_arg_2)
{
/** Partner Auth data */
$username = "apiFlash"; //string
$password = "hjd*Rhdasj67J"; //string
$partnerid = "898989"; //int
$apikey = "896235"; //int
$callback = 'https://www.digitalcare.se/2.0/site/paycode/paycode_callback.php';
$callback = '';
$cusref = array(
'account' => '113445',
'email' => 'olle.olsson@xx.se'
);
/** Encode auth data (username & password) with base64 */
$auth = base64_encode("$username:$password");
$callback = base64_encode("$callback");
$cusref = base64_encode(json_encode($cusref));
/** Set test or production api url's */
$apiurl = "https://193.15.20.88/api/v1"; // TEST/STAGE
//$apiurl = "https://paycode.unicorn.se/api/v1"; //PROD
/** Create the final request url from collected data */
$url = $apiurl.'/'.$apicmd."/".$url_arg_1."/".$url_arg_2;
/** Execute the request */
try {
$opts = [
'http'=> [
'method' => "POST",
'header' => "Authorization: Basic $auth\r\n".
"X-pid: $partnerid\r\n".
"X-key: $apikey\r\n".
"X-callback: $callback\r\n".
"X-cusref: $cusref\r\n"
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
];
$context = stream_context_create($opts);
$http_result = file_get_contents($url, false, $context);
echo json_encode(array('Http request return',$http_result));
exit();
} catch (\Exception $e) {
echo json_encode(array("Http request error!", $e));
}
}
{
bnr: "0850209992",
callback: "https://www.digitalcare.se/2.0/site/paycode/paycode_callback.php",
cusref: "{"account":"113445","email":"olle.olsson@xx.se"}",
paid: "1",
paycode: "580887",
price: "50.00",
request: "checkPaid",
timeout: "240"
}
POST https://paycode.unicorn.se/api/v1/getReport/from/to
| HEADER ELEMENTS | ||
| Name | Type | Description |
|---|---|---|
| username | string | Generated by Paycode IT Dep. |
| password | string | Generated by Paycode IT Dep. |
| username and password used with basic Auth in HTTP Request - base64_encoded | ||
| partnerid | int | Generated by Paycode IT Dep. |
| apikey | int | Generated by Paycode IT Dep. |
| callback | string |
Optional customer callback url. Executed on succesful paycode entry in IVR Must be base64_encoded |
| cusref | string |
Optional customer json reference object. {account:'113445','email':'olle.olsson@xx.se'} Must be base64_encoded |
| URL ELEMENTS | ||
| url_arg_1 | string | Required from date (Format 2019-06-01 - Y-m-d) |
| url_arg_2 | string | Required to date (Format 2019-06-11 - Y-m-d) |
/**
* UNICORN PAYCODE
* EXAMPLE - BACKEND - BASIC AUTH HTTP REQUEST TO API USING 4 CUSTOM HEADERS
*/
/** Handle post api data from client side */
$apicmd=$url_arg_1=$url_arg_2 = '';
$apidata = json_decode($_REQUEST['apidata'],true);
if (isset($apidata)) {
if (isset($apidata['apicmd'])) { $apicmd = $apidata['apicmd'];} // getReport
if (isset($apidata['url_arg_1'])) { $url_arg_1 = $apidata['url_arg_1'];} // from
if (isset($apidata['url_arg_2'])) { $url_arg_2 = $apidata['url_arg_2'];} // to
}
/** Check data types and if ok, Run HTTP Request */
if (!is_string($url_arg_1) || !is_string($url_arg_2) || !is_string($apicmd)) {
echo json_encode(array("Data type error!", $apidata));
exit();
} else {
apiRequest($apicmd,$url_arg_1,$url_arg_2);
exit();
}
/** HTTPS REQUEST WITH stream_context_create() and file_get_contents */
function apiRequest($apicmd,$url_arg_1,$url_arg_2)
{
/** Partner Auth data */
$username = "apiFlash"; //string
$password = "hjd*Rhdasj67J"; //string
$partnerid = "898989"; //int
$apikey = "896235"; //int
$callback = 'https://www.digitalcare.se/2.0/site/paycode/paycode_callback.php';
$callback = '';
$cusref = array(
'account' => '113445',
'email' => 'olle.olsson@xx.se'
);
/** Encode auth data (username & password) with base64 */
$auth = base64_encode("$username:$password");
$callback = base64_encode("$callback");
$cusref = base64_encode(json_encode($cusref));
/** Set test or production api url's */
$apiurl = "https://193.15.20.88/api/v1"; // TEST/STAGE
//$apiurl = "https://paycode.unicorn.se/api/v1"; //PROD
/** Create the final request url from collected data */
$url = $apiurl.'/'.$apicmd."/".$url_arg_1."/".$url_arg_2;
/** Execute the request */
try {
$opts = [
'http'=> [
'method' => "POST",
'header' => "Authorization: Basic $auth\r\n".
"X-pid: $partnerid\r\n".
"X-key: $apikey\r\n".
"X-callback: $callback\r\n".
"X-cusref: $cusref\r\n"
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
];
$context = stream_context_create($opts);
$http_result = file_get_contents($url, false, $context);
echo json_encode(array('Http request return',$http_result));
exit();
} catch (\Exception $e) {
echo json_encode(array("Http request error!", $e));
}
}
{
from: "2019-05-01"
report: [{
ani: "",
apikey: "896235",
bnr: "0850209991",
callback: "https://www.digitalcare.se/2.0/site/paycode/paycode_callback.php",
callbrsp: "0",
created: "2019-06-25 11:52:21",
cusref: "{"account":"113445","email":"olle.olsson@xx.se"}",
dtmf: "",
gwid: "",
id: "1561456331.0206",
ip: "193.202.110.26",
paid: "0",
partner: "898989",
paycode: "859008",
price: "10.00",
request: "setPaycode",
type: "json",
updated: "2019-06-25 11:52:21",
}, {…}, {…}, {…}, {…}, {…}],
request: "getReport",
to: "2019-06-25",
}
$payment = json_decode(base64_decode($_SERVER['HTTP_X_PAYMENT']));
if ($payment->id) {
echo json_encode(array(
'status' => 'OK',
'description' => $payment->id,
'json' => $payment
));
} else {
echo json_encode(array(
'status' => 'ERROR',
'description' => 'Wrong payment data',
'json' => $payment
));
}