class CurrencylayerExchanger in Commerce Exchanger 8
Provides the Currencylayer.com exchange rates.
Plugin annotation
@CommerceExchangerProvider(
id = "currencylayer",
label = "Currencylayer",
display_label = "currencylayer.com",
historical_rates = TRUE,
enterprise = TRUE,
api_key= TRUE,
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\commerce_exchanger\Plugin\Commerce\ExchangerProvider\ExchangerProviderBase implements ExchangerProviderInterface, ContainerFactoryPluginInterface
- class \Drupal\commerce_exchanger\Plugin\Commerce\ExchangerProvider\ExchangerProviderRemoteBase implements ExchangerProviderRemoteInterface
- class \Drupal\commerce_exchanger\Plugin\Commerce\ExchangerProvider\CurrencylayerExchanger
- class \Drupal\commerce_exchanger\Plugin\Commerce\ExchangerProvider\ExchangerProviderRemoteBase implements ExchangerProviderRemoteInterface
- class \Drupal\commerce_exchanger\Plugin\Commerce\ExchangerProvider\ExchangerProviderBase implements ExchangerProviderInterface, ContainerFactoryPluginInterface
Expanded class hierarchy of CurrencylayerExchanger
File
- src/
Plugin/ Commerce/ ExchangerProvider/ CurrencylayerExchanger.php, line 19
Namespace
Drupal\commerce_exchanger\Plugin\Commerce\ExchangerProviderView source
class CurrencylayerExchanger extends ExchangerProviderRemoteBase {
/**
* {@inheritdoc}
*/
public function apiUrl() {
if ($this
->isEnterprise()) {
return 'https://api.currencylayer.com/live';
}
return 'http://api.currencylayer.com/live';
}
/**
* {@inheritdoc}
*/
public function getRemoteData($base_currency = NULL) {
$data = NULL;
$options = [
'query' => [
'access_key' => $this
->getApiKey(),
],
];
// Add base currency if we use enterprise model.
if ($this
->isEnterprise()) {
$options['query']['base'] = $base_currency;
}
$request = $this
->apiClient($options);
if ($request) {
$json = Json::decode($request);
if (!empty($json['success'])) {
// Leave base currency. In some cases we don't know base currency.
// Currenclayer on free plan uses your address for base currency, and in
// Drupal you could have different default value.
$data['base'] = $json['source'];
foreach ($json['quotes'] as $code => $rate) {
$data['rates'][str_replace($json['source'], '', $code)] = $rate;
}
}
}
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrencylayerExchanger:: |
public | function |
URL from remote provider upon API call should be made. Overrides ExchangerProviderRemoteInterface:: |
|
CurrencylayerExchanger:: |
public | function |
Fetch external data. Overrides ExchangerProviderRemoteInterface:: |
|
ExchangerProviderBase:: |
protected | property | Configuration management. | |
ExchangerProviderBase:: |
protected | property | Return formatted array of currencies ['HRK' => 'Croatian Kuna']. | |
ExchangerProviderBase:: |
protected | property | The currency storage. | |
ExchangerProviderBase:: |
private | property | Parent entity if present. | |
ExchangerProviderBase:: |
protected | property | The HTTP client to fetch the feed data with. | |
ExchangerProviderBase:: |
protected | property | The logger. | |
ExchangerProviderBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
ExchangerProviderBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ExchangerProviderBase:: |
public | function | ||
ExchangerProviderBase:: |
public | function |
Return config object name where exchange rates are saved. Overrides ExchangerProviderInterface:: |
|
ExchangerProviderBase:: |
public | function | ||
ExchangerProviderBase:: |
protected | function | Simple key-value array for enabled currencies. | |
ExchangerProviderBase:: |
public | function | ||
ExchangerProviderBase:: |
public | function | ||
ExchangerProviderBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
ExchangerProviderBase:: |
public | function | ||
ExchangerProviderBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
ExchangerProviderBase:: |
public | function |
Constructs a new ExchangeProvider object. Overrides PluginBase:: |
|
ExchangerProviderRemoteBase:: |
public | function |
Generic wrapper around Drupal http client. Overrides ExchangerProviderRemoteInterface:: |
|
ExchangerProviderRemoteBase:: |
protected | function | Process all currencies for rates for other currencies. | |
ExchangerProviderRemoteBase:: |
protected | function | Rates calculation for currencies when we use cross sync conversion. | |
ExchangerProviderRemoteBase:: |
public | function |
Remote providers api key. Overrides ExchangerProviderRemoteInterface:: |
|
ExchangerProviderRemoteBase:: |
public | function |
Remote authentication credentials. Overrides ExchangerProviderRemoteInterface:: |
|
ExchangerProviderRemoteBase:: |
public | function |
Either remote provider defined base currency, or use entered. Overrides ExchangerProviderRemoteInterface:: |
|
ExchangerProviderRemoteBase:: |
public | function |
Method which supports remote provider. Overrides ExchangerProviderRemoteInterface:: |
|
ExchangerProviderRemoteBase:: |
public | function | ||
ExchangerProviderRemoteBase:: |
protected | function | Preform cross conversion between currencies to build exchange data rates. | |
ExchangerProviderRemoteBase:: |
protected | function | Fetch remote provider by each currency and create dataset. | |
ExchangerProviderRemoteBase:: |
public | function |
Determine if remote provider supports querying by different base currency. Overrides ExchangerProviderRemoteInterface:: |
|
ExchangerProviderRemoteBase:: |
protected | function | Helper function to create array for exchange rates. | |
ExchangerProviderRemoteBase:: |
protected | function | Process data with checking structure and preparing data for importing. | |
ExchangerProviderRemoteBase:: |
protected | function | Recalculate currencies from exchange rate between two other currencies. | |
ExchangerProviderRemoteBase:: |
public | function |
Determine if rates provided by provider needs to be transformed
in a required rate ratio based on base currency. Overrides ExchangerProviderRemoteInterface:: |
|
ExchangerProviderRemoteBase:: |
public | function |
Either remote provider defined or use defined choice. Overrides ExchangerProviderRemoteInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |