|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MyFatoorah\Library\API; |
|
4
|
|
|
|
|
5
|
|
|
use MyFatoorah\Library\MyFatoorah; |
|
6
|
|
|
use Exception; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* MyFatoorahList handles the list process of MyFatoorah API endpoints |
|
10
|
|
|
* |
|
11
|
|
|
* @author MyFatoorah <[email protected]> |
|
12
|
|
|
* @copyright 2021 MyFatoorah, All rights reserved |
|
13
|
|
|
* @license GNU General Public License v3.0 |
|
14
|
|
|
*/ |
|
15
|
|
|
class MyFatoorahList extends MyFatoorah |
|
16
|
|
|
{ |
|
17
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Gets the rate of a given currency according to the default currency of the MyFatoorah portal account. |
|
21
|
|
|
* |
|
22
|
|
|
* @param string $currency The currency that will be converted into the currency of MyFatoorah portal account. |
|
23
|
|
|
* |
|
24
|
|
|
* @return number The conversion rate converts a given currency to the MyFatoorah account default currency. |
|
25
|
|
|
* |
|
26
|
|
|
* @throws Exception Throw exception if the input currency is not support by MyFatoorah portal account. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getCurrencyRate($currency) |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
$json = $this->getCurrencyRates(); |
|
32
|
|
|
foreach ($json as $value) { |
|
33
|
|
|
if ($value->Text == $currency) { |
|
34
|
|
|
return $value->Value; |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
throw new Exception('The selected currency is not supported by MyFatoorah'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get list of MyFatoorah currency rates |
|
44
|
|
|
* |
|
45
|
|
|
* @return array |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getCurrencyRates() |
|
48
|
|
|
{ |
|
49
|
|
|
|
|
50
|
|
|
$url = "$this->apiURL/v2/GetCurrenciesExchangeList"; |
|
51
|
|
|
return (array) $this->callAPI($url, null, null, 'Get Currencies Exchange List'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
|
55
|
|
|
} |
|
56
|
|
|
|