You are here

class EuropeanCentralBankExchanger in Commerce Exchanger 8

Provides EuropeanCentralBank.

Plugin annotation


@CommerceExchangerProvider(
  id = "ecb",
  label = "European Central Bank",
  display_label = "European Central Bank",
  historical_rates = TRUE,
  base_currency = "EUR",
  refresh_once = TRUE,
)

Hierarchy

Expanded class hierarchy of EuropeanCentralBankExchanger

File

src/Plugin/Commerce/ExchangerProvider/EuropeanCentralBankExchanger.php, line 19

Namespace

Drupal\commerce_exchanger\Plugin\Commerce\ExchangerProvider
View source
class EuropeanCentralBankExchanger extends ExchangerProviderRemoteBase {

  /**
   * {@inheritdoc}
   */
  public function apiUrl() {
    return 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml';
  }

  /**
   * {@inheritdoc}
   */
  public function getRemoteData($base_currency = NULL) {
    $data = NULL;
    $request = $this
      ->apiClient([]);
    if ($request) {
      try {
        $xml = new SimpleXMLElement($request);
      } catch (\Exception $e) {
        $this->logger
          ->error($e
          ->getMessage());
      }
      $data = [];

      // Loop and build array.
      foreach ($xml->Cube->Cube->Cube as $rate) {
        $code = (string) $rate['currency'];
        $rate = (string) $rate['rate'];
        $data[$code] = $rate;
      }
    }
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EuropeanCentralBankExchanger::apiUrl public function URL from remote provider upon API call should be made. Overrides ExchangerProviderRemoteInterface::apiUrl
EuropeanCentralBankExchanger::getRemoteData public function Fetch external data. Overrides ExchangerProviderRemoteInterface::getRemoteData
ExchangerProviderBase::$configFactory protected property Configuration management.
ExchangerProviderBase::$currencies protected property Return formatted array of currencies ['HRK' => 'Croatian Kuna'].
ExchangerProviderBase::$currencyStorage protected property The currency storage.
ExchangerProviderBase::$entityId private property Parent entity if present.
ExchangerProviderBase::$httpClientFactory protected property The HTTP client to fetch the feed data with.
ExchangerProviderBase::$logger protected property The logger.
ExchangerProviderBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
ExchangerProviderBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
ExchangerProviderBase::defaultConfiguration public function
ExchangerProviderBase::getConfigName public function Return config object name where exchange rates are saved. Overrides ExchangerProviderInterface::getConfigName
ExchangerProviderBase::getConfiguration public function
ExchangerProviderBase::getCurrencies protected function Simple key-value array for enabled currencies.
ExchangerProviderBase::getMode public function
ExchangerProviderBase::setConfiguration public function
ExchangerProviderBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
ExchangerProviderBase::supportingModes public function
ExchangerProviderBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
ExchangerProviderBase::__construct public function Constructs a new ExchangeProvider object. Overrides PluginBase::__construct
ExchangerProviderRemoteBase::apiClient public function Generic wrapper around Drupal http client. Overrides ExchangerProviderRemoteInterface::apiClient
ExchangerProviderRemoteBase::buildExchangeRates protected function Process all currencies for rates for other currencies.
ExchangerProviderRemoteBase::crossSyncCalculate protected function Rates calculation for currencies when we use cross sync conversion.
ExchangerProviderRemoteBase::getApiKey public function Remote providers api key. Overrides ExchangerProviderRemoteInterface::getApiKey
ExchangerProviderRemoteBase::getAuthData public function Remote authentication credentials. Overrides ExchangerProviderRemoteInterface::getAuthData
ExchangerProviderRemoteBase::getBaseCurrency public function Either remote provider defined base currency, or use entered. Overrides ExchangerProviderRemoteInterface::getBaseCurrency
ExchangerProviderRemoteBase::getMethod public function Method which supports remote provider. Overrides ExchangerProviderRemoteInterface::getMethod
ExchangerProviderRemoteBase::import public function
ExchangerProviderRemoteBase::importCrossSync protected function Preform cross conversion between currencies to build exchange data rates.
ExchangerProviderRemoteBase::importEnterprise protected function Fetch remote provider by each currency and create dataset.
ExchangerProviderRemoteBase::isEnterprise public function Determine if remote provider supports querying by different base currency. Overrides ExchangerProviderRemoteInterface::isEnterprise
ExchangerProviderRemoteBase::mapExchangeRates protected function Helper function to create array for exchange rates.
ExchangerProviderRemoteBase::processRemoteData protected function Process data with checking structure and preparing data for importing.
ExchangerProviderRemoteBase::recalculateRates protected function Recalculate currencies from exchange rate between two other currencies.
ExchangerProviderRemoteBase::transformRates public function Determine if rates provided by provider needs to be transformed in a required rate ratio based on base currency. Overrides ExchangerProviderRemoteInterface::transformRates
ExchangerProviderRemoteBase::useCrossSync public function Either remote provider defined or use defined choice. Overrides ExchangerProviderRemoteInterface::useCrossSync
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.