Hi please check this code for me and see what's wrong and if someone can fix it. Issue is subscription error.
https://drive.google.com/drive/folders/1Zswnlp4qwMGM31numcbDKoDZRjXm-uSx?usp=sharing
<?php
function curlPost($url, $header, $data, $type){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
if($type){
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}else{
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}
$result=curl_exec ($ch);
$status_code = curl_getinfo($ch);
curl_close ($ch);
$responce = json_decode($result,true);
return($responce);
}
function curlGet($url, $header){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result=curl_exec ($ch);
$status_code = curl_getinfo($ch);
curl_close ($ch);
$responce = json_decode($result,true);
return($responce);
}
function get_Access_token_by_refresh_token($get_refresh_token){
$url = BASE_URL."/restapi/oauth/token";
$headers = array();
$auth = base64_encode(CLIENT_ID .":". APP_SECRET);
$headers[] = "Content-Type: application/x-www-form-urlencoded";
$headers[] = "Authorization: Basic ".$auth;
$data = array(
"grant_type" => "refresh_token",
"refresh_token" => $get_refresh_token
);
$response = curlPost($url, $headers, $data, false);
return $response;
}
/*
Get Token
*/
function subscribe($token){
$url= BASE_URL."/restapi/v1.0/subscription";
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer ".$token;
$headers[] = "Accept: application/json";
$data = array("eventFilters"=>array("/restapi/v1.0/account/~/presence?detailedTelephonyState=true"), "deliveryMode"=>array( "transportType"=> "WebHook","address"=>"https://tbmslive.com/ringcentral/safeforu/webhook.php"));
$response = curlPost($url, $headers, json_encode($data), true);
return $response;
}
function readPresence($token){
$url= BASE_URL."/restapi/v1.0/account/~/extension/~/presence";
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer ".$token;
$headers[] = "Accept: application/json";
$response = curlGet($url, $headers);
return $response;
}
function getSubscription($token){
$url= BASE_URL."/restapi/v1.0/subscription";
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer ".$token;
$headers[] = "Accept: application/json";
$response = curlGet($url, $headers);
return $response;
}
function renewSubscription($token, $id){
$url= BASE_URL."/restapi/v1.0/subscription/".$id."/renew";
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer ".$token;
$headers[] = "Accept: application/json";
$data = array();
$response = curlPost($url, $headers, json_encode($data), true);
return $response;
}