You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.3 KiB
72 lines
1.3 KiB
<?php
|
|
|
|
namespace WCML\MultiCurrency\ExchangeRateServices;
|
|
|
|
/**
|
|
* Class CurrencyLayer
|
|
*/
|
|
class CurrencyLayer extends ApiLayerService {
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getId() {
|
|
return 'currencylayer';
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getName() {
|
|
return 'currencylayer';
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getUrl() {
|
|
return 'https://currencylayer.com/';
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
protected function getApiLayerUrl() {
|
|
return 'https://api.apilayer.com/currency_data/live?source=%2$s¤cies=%3$s';
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
protected function getApiLegacyUrl() {
|
|
return 'http://apilayer.net/api/live?access_key=%s&source=%s¤cies=%s&amount=1';
|
|
}
|
|
|
|
/**
|
|
* @param object $decodedData
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function isInvalidResponse( $decodedData ) {
|
|
return empty( $decodedData->quotes );
|
|
}
|
|
|
|
/**
|
|
* @param object $validData
|
|
* @param string $from
|
|
* @param array $tos
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function extractRates( $validData, $from, $tos ) {
|
|
$rates = [];
|
|
|
|
foreach ( $tos as $to ) {
|
|
if ( isset( $validData->quotes->{$from . $to} ) ) {
|
|
$rates[ $to ] = round( $validData->quotes->{$from . $to}, \WCML_Exchange_Rates::DIGITS_AFTER_DECIMAL_POINT );
|
|
}
|
|
}
|
|
|
|
return $rates;
|
|
}
|
|
}
|
|
|