From 01f66652dd6d34f6c32b778c7e7660fe218b550c Mon Sep 17 00:00:00 2001 From: Shek Muktar Date: Sat, 30 Mar 2024 15:08:56 +0530 Subject: [PATCH 1/7] Fix namespace issue and add limit argument to read() Class name and file name is now MagnusBilling instead of magnusBilling This fixes the complains by phpstan (static analyzer) --- src/{magnusBilling.php => MagnusBilling.php} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/{magnusBilling.php => MagnusBilling.php} (96%) diff --git a/src/magnusBilling.php b/src/MagnusBilling.php similarity index 96% rename from src/magnusBilling.php rename to src/MagnusBilling.php index fbe133c..67eaa53 100755 --- a/src/magnusBilling.php +++ b/src/MagnusBilling.php @@ -76,7 +76,7 @@ private function query(array $req = array()) $res = curl_exec($ch); if ($res === false) { - throw new Exception('Curl error: ' . curl_error($ch)); + throw new \Exception('Curl error: ' . curl_error($ch)); } $dec = json_decode($res, true); @@ -116,7 +116,7 @@ public function destroy($module, $id) ) ); } - public function read($module, $page = 1, $action = 'read') + public function read($module, $page = 1, $action = 'read', $limit = 25) { return $this->query( @@ -124,8 +124,8 @@ public function read($module, $page = 1, $action = 'read') 'module' => $module, 'action' => $action, 'page' => $page, - 'start' => $page == 1 ? 0 : ($page - 1) * 25, - 'limit' => 25, + 'start' => $page == 1 ? 0 : ($page - 1) * $limit, + 'limit' => $limit, 'filter' => json_encode($this->filter), ) ); From d214fd8d4fdb96b9c99faf90b35912ca3aaea7a4 Mon Sep 17 00:00:00 2001 From: Shek Muktar Date: Thu, 23 May 2024 17:18:52 +0530 Subject: [PATCH 2/7] Handle downloadable content response api --- src/MagnusBilling.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/MagnusBilling.php b/src/MagnusBilling.php index 67eaa53..a37fdaf 100755 --- a/src/MagnusBilling.php +++ b/src/MagnusBilling.php @@ -79,6 +79,12 @@ private function query(array $req = array()) throw new \Exception('Curl error: ' . curl_error($ch)); } + $res_content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); + if (strtolower($res_content_type) === "application/force-download") { + // It's a audio download request + return $res; + } + $dec = json_decode($res, true); if (!$dec) { print_r($res); From 180f27d3661f465b958e8cfb1f8f89eeb365cb9e Mon Sep 17 00:00:00 2001 From: Shek Muktar Date: Thu, 23 May 2024 18:08:56 +0530 Subject: [PATCH 3/7] Chagne name of the repo to imskm --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cf7cbf0..9926b0c 100755 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "magnussolution/magnusbilling-api", + "name": "imskm/magnusbilling-api-php", "description": "PHP wrapper for the MagnusBilling API.", "type": "library", "license": "MIT", @@ -17,4 +17,4 @@ "magnusbilling\\api\\": "src/" } } -} \ No newline at end of file +} From 8909f99c4caad525632618c7537b893978a99970 Mon Sep 17 00:00:00 2001 From: Shek Muktar Date: Thu, 23 May 2024 20:06:37 +0530 Subject: [PATCH 4/7] Change the return value of binary content type --- src/MagnusBilling.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/MagnusBilling.php b/src/MagnusBilling.php index a37fdaf..405c682 100755 --- a/src/MagnusBilling.php +++ b/src/MagnusBilling.php @@ -82,7 +82,10 @@ private function query(array $req = array()) $res_content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); if (strtolower($res_content_type) === "application/force-download") { // It's a audio download request - return $res; + return [ + 'type' => 'binary', + 'blob' => $res, + ]; } $dec = json_decode($res, true); From 670788c7faa9f486aeb5af25ae32888a6dccce6c Mon Sep 17 00:00:00 2001 From: Shek Muktar Date: Thu, 23 May 2024 21:12:34 +0530 Subject: [PATCH 5/7] Implement call audio download --- src/MagnusBilling.php | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/MagnusBilling.php b/src/MagnusBilling.php index 405c682..176bae1 100755 --- a/src/MagnusBilling.php +++ b/src/MagnusBilling.php @@ -62,7 +62,11 @@ private function query(array $req = array()) static $ch = null; if (is_null($ch)) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if (isset($req['write_cb'])) { + curl_setopt($ch, CURLOPT_WRITEFUNCTION, $req['write_cb']); + } else { + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + } curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MagnusBilling PHP bot; ' . php_uname('a') . '; PHP/' . phpversion() . ')' ); @@ -79,13 +83,8 @@ private function query(array $req = array()) throw new \Exception('Curl error: ' . curl_error($ch)); } - $res_content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); - if (strtolower($res_content_type) === "application/force-download") { - // It's a audio download request - return [ - 'type' => 'binary', - 'blob' => $res, - ]; + if (isset($req['write_cb'])) { + return $res; } $dec = json_decode($res, true); @@ -188,6 +187,24 @@ public function releaseDID($did) ); } + public function getCallAudioRecording($call_id, $stream_cb) + { + $this->clearFilter(); + $this->setFilter('id', $call_id, 'eq', 'numeric'); + + return $this->query( + array( + 'module' => "call", + 'action' => "downloadRecord", + 'page' => $page = 1, + 'start' => $page == 1 ? 0 : ($page - 1) * $limit, + 'limit' => $limit = 25, + 'filter' => json_encode($this->filter), + 'write_cb' => $stream_cb, + ) + ); + } + public function getFields($module) { return $this->query( From f95f50381fbd9efc14701891efebf9779ad0f93b Mon Sep 17 00:00:00 2001 From: Shek Muktar Date: Fri, 24 May 2024 18:21:10 +0530 Subject: [PATCH 6/7] getCallAudioRecording(): query(): second call may not set write_cb --- src/MagnusBilling.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/MagnusBilling.php b/src/MagnusBilling.php index 176bae1..9ee505d 100755 --- a/src/MagnusBilling.php +++ b/src/MagnusBilling.php @@ -70,6 +70,12 @@ private function query(array $req = array()) curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MagnusBilling PHP bot; ' . php_uname('a') . '; PHP/' . phpversion() . ')' ); + } else { + if (isset($req['write_cb'])) { + curl_setopt($ch, CURLOPT_WRITEFUNCTION, $req['write_cb']); + } else { + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + } } curl_setopt($ch, CURLOPT_URL, $trading_url . '/index.php/' . $module . '/' . $action); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); From e8c1a3a25458f56dc2ff5d82a6a7a707a51f8482 Mon Sep 17 00:00:00 2001 From: Shek Muktar Date: Tue, 17 Jun 2025 15:08:46 +0530 Subject: [PATCH 7/7] getCallAudioRecording: MagnusBilling: Call the correct backend API in action --- src/MagnusBilling.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MagnusBilling.php b/src/MagnusBilling.php index 9ee505d..99c373a 100755 --- a/src/MagnusBilling.php +++ b/src/MagnusBilling.php @@ -201,7 +201,7 @@ public function getCallAudioRecording($call_id, $stream_cb) return $this->query( array( 'module' => "call", - 'action' => "downloadRecord", + 'action' => "downloadRecordTwo", 'page' => $page = 1, 'start' => $page == 1 ? 0 : ($page - 1) * $limit, 'limit' => $limit = 25,