Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "magnussolution/magnusbilling-api",
"name": "imskm/magnusbilling-api-php",
"description": "PHP wrapper for the MagnusBilling API.",
"type": "library",
"license": "MIT",
Expand All @@ -17,4 +17,4 @@
"magnusbilling\\api\\": "src/"
}
}
}
}
87 changes: 74 additions & 13 deletions src/magnusBilling.php → src/MagnusBilling.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class MagnusBilling
protected $api_secret;
public $public_url;
public $filter = [];
public $columns = [];

public function __construct($api_key, $api_secret)
{
Expand Down Expand Up @@ -62,10 +63,20 @@ 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() . ')'
);
} 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);
Expand All @@ -76,7 +87,11 @@ 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));
}

if (isset($req['write_cb'])) {
return $res;
}

$dec = json_decode($res, true);
Expand Down Expand Up @@ -116,19 +131,21 @@ public function destroy($module, $id)
)
);
}
public function read($module, $page = 1, $action = 'read')
public function read($module, $page = 1, $action = 'read', $limit = 25)
{
$query = [
'module' => $module,
'action' => $action,
'page' => $page,
'start' => $page == 1 ? 0 : ($page - 1) * $limit,
'limit' => $limit,
'filter' => json_encode($this->filter),
];
if (isset($this->columns[0])) {
$query['columns'] = json_encode($this->columns);
}

return $this->query(
array(
'module' => $module,
'action' => $action,
'page' => $page,
'start' => $page == 1 ? 0 : ($page - 1) * 25,
'limit' => 25,
'filter' => json_encode($this->filter),
)
);
return $this->query($query);
}

public function buyDID($id_did, $id_user)
Expand Down Expand Up @@ -179,6 +196,42 @@ 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' => "downloadRecordTwo",
'page' => $page = 1,
'start' => $page == 1 ? 0 : ($page - 1) * $limit,
'limit' => $limit = 25,
'filter' => json_encode($this->filter),
'write_cb' => $stream_cb,
)
);
}

public function downloadResource($module, $action, $limit, $stream_cb)
{
$query = [
'module' => $module,
'action' => $action,
'page' => $page = 1,
'start' => $page == 1 ? 0 : ($page - 1) * $limit,
'limit' => $limit,
'filter' => json_encode($this->filter),
'write_cb' => $stream_cb,
];
if (isset($this->columns[0])) {
$query['columns'] = json_encode($this->columns);
}

return $this->query($query);
}

public function getFields($module)
{
return $this->query(
Expand Down Expand Up @@ -253,4 +306,12 @@ public function setFilter($field, $value, $comparison = 'st', $type = 'string')
'comparison' => $comparison,
];
}

public function setColumn($header, $field)
{
$this->columns[] = (object) [
'header' => $header,
'dataIndex' => $field,
];
}
}