diff --git a/lib/KolmisoftMore/KolmisoftMore.php b/lib/KolmisoftMore/KolmisoftMore.php new file mode 100644 index 000000000..a1c111c23 --- /dev/null +++ b/lib/KolmisoftMore/KolmisoftMore.php @@ -0,0 +1,82 @@ +host = $host; + $this->apiKey = $apiKey; + $this->username = $username; + } + + /** + * Generate hash for the given query parameters + * @param $queryParameters - Array of query parameters to generate hash + * @return string + */ + public function generateHash($queryParameters): string { + // concatenate all query parameters values in order of the array and then add apiKey to the end + + $queryString = implode('', $queryParameters); + $queryString .= $this->apiKey; + + return hash('sha1', $queryString); + } + + /** + * Make a request to the Kolmisoft API + * @param $path - API path + * @param $queryString - Query string + * @return array|bool + */ + public function makeRequest($path, $queryString) { + $url = "https://{$this->host}/billing/api/$path?$queryString"; + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + + $response = curl_exec($curl); + + try { + $response = new SimpleXMLElement($response); + } catch (Exception $e) { + return false; + } + + $response = json_decode(json_encode($response), true); + + if (is_array($response)) { + return $response; + } else { + return false; + } + } + + public function getVoiceCallHistory($startDate, $endDate) { + + $queryParameters = [ + 'period_start' => $startDate, + 'period_end' => $endDate + ]; + + $hash = $this->generateHash($queryParameters); + + $queryParameters['hash'] = $hash; + $queryParameters['u'] = $this->username; + + $queryString = http_build_query($queryParameters); + + $response = $this->makeRequest('user_calls_get', $queryString); + + if ($response) { + return $response['calls_stat']['calls']['call']; + } else { + return false; + } + + } + +} \ No newline at end of file