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 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
|
|
|
* @param array $allRates An array of MyFatoorah currencies and rates |
24
|
|
|
* |
25
|
|
|
* @return double |
26
|
|
|
* |
27
|
|
|
* @throws Exception Throw exception if the input currency is not support by MyFatoorah portal account. |
28
|
|
|
*/ |
29
|
|
|
public static function getOneCurrencyRate($currency, $allRates) |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
foreach ($allRates as $value) { |
33
|
|
|
if ($value->Text == $currency) { |
34
|
|
|
return (double) $value->Value; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
throw new Exception('The selected currency is not supported by MyFatoorah'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Gets the rate of a given currency according to the default currency of the MyFatoorah portal account. |
44
|
|
|
* |
45
|
|
|
* @param string $currency The currency that will be converted into the currency of MyFatoorah portal account. |
46
|
|
|
* |
47
|
|
|
* @return double |
48
|
|
|
*/ |
49
|
|
|
public function getCurrencyRate($currency) |
50
|
|
|
{ |
51
|
|
|
|
52
|
|
|
$allRates = $this->getCurrencyRates(); |
53
|
|
|
return self::getOneCurrencyRate($currency, $allRates); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get list of MyFatoorah currency rates |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function getCurrencyRates() |
64
|
|
|
{ |
65
|
|
|
|
66
|
|
|
$url = "$this->apiURL/v2/GetCurrenciesExchangeList"; |
67
|
|
|
return (array) $this->callAPI($url, null, null, 'Get Currencies Exchange List'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
71
|
|
|
} |
72
|
|
|
|