ApiLayerService.php
4 weeks ago
CurrencyLayer.php
4 weeks ago
ExchangeRatesApi.php
4 weeks ago
Fixerio.php
4 weeks ago
OpenExchangeRates.php
4 weeks ago
Service.php
4 weeks ago
CurrencyLayer.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\MultiCurrency\ExchangeRateServices; |
| 4 | |
| 5 | class CurrencyLayer extends ApiLayerService { |
| 6 | |
| 7 | public function getId() { |
| 8 | return 'currencylayer'; |
| 9 | } |
| 10 | |
| 11 | public function getName() { |
| 12 | return 'currencylayer'; |
| 13 | } |
| 14 | |
| 15 | public function getUrl() { |
| 16 | return 'https://currencylayer.com/'; |
| 17 | } |
| 18 | |
| 19 | protected function getApiLayerUrl() { |
| 20 | return 'https://api.apilayer.com/currency_data/live?source=%2$s¤cies=%3$s'; |
| 21 | } |
| 22 | |
| 23 | protected function getApiLegacyUrl() { |
| 24 | return 'http://apilayer.net/api/live?access_key=%s&source=%s¤cies=%s&amount=1'; |
| 25 | } |
| 26 | |
| 27 | protected function isInvalidResponse( $decodedData ) { |
| 28 | return empty( $decodedData->quotes ); |
| 29 | } |
| 30 | |
| 31 | protected function extractRates( $validData, $from, $tos ) { |
| 32 | $rates = []; |
| 33 | |
| 34 | foreach ( $tos as $to ) { |
| 35 | if ( isset( $validData->quotes->{$from . $to} ) ) { |
| 36 | $rates[ $to ] = round( $validData->quotes->{$from . $to}, \WCML_Exchange_Rates::DIGITS_AFTER_DECIMAL_POINT ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return $rates; |
| 41 | } |
| 42 | } |
| 43 |