Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class FixerConverter implements Converter {
- public function loadConversionRate(string $baseCurrency, string $toCurrency): string
- {
- $conversionRateJson = @file_get_contents('http://api.fixer.io/latest?base=' . $baseCurrency . '&symbols=' . $toCurrency));
- if ($conversionRateJson === false) {
- echo 'Error: unexpected error retrieving currency conversion rate from API service.';
- }
- $conversionRateArr = json_decode($conversionRateJson, TRUE);
- $this->conversionRate = $conversionRateArr['rates'][$currency];
- }
- public function convertCurrency(string $amount): float
- {
- if (isset($this->conversionRate)) {
- return $amount * $this->conversionRate;
- }
- echo 'Error: There is no conversion rate loaded.';
- }
- }
Add Comment
Please, Sign In to add comment