You are here

class TransferWiseExchanger in Commerce Exchanger 8

Provides the transferwise.com exchange rates.

Plugin annotation


@CommerceExchangerProvider(
  id = "transferwise",
  label = "TransferWise",
  display_label = "TransferWise",
  historical_rates = TRUE,
  enterprise = TRUE,
  api_key = TRUE,
  modes = TRUE,
)

Hierarchy

Expanded class hierarchy of TransferWiseExchanger

File

src/Plugin/Commerce/ExchangerProvider/TransferWiseExchanger.php, line 21

Namespace

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

  /**
   * {@inheritdoc}
   */
  public function apiUrl() {
    return 'https://api.transferwise.com/v1/rates';
  }

  /**
   * {@inheritdoc}
   */
  public function getRemoteData($base_currency = NULL) {
    $data = NULL;
    $source = $this
      ->isEnterprise() ? $base_currency : $this
      ->getBaseCurrency();
    $options = [
      RequestOptions::QUERY => [
        'source' => $source,
      ],
      RequestOptions::HEADERS => [
        'Authorization' => 'Bearer ' . $this
          ->getApiKey(),
      ],
    ];
    $request = $this
      ->apiClient($options);
    if ($request) {
      $rates = Json::decode($request);
      $data['base'] = $source;
      foreach ($rates as $rate) {
        $data['rates'][$rate['target']] = $rate['rate'];
      }
    }
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
TransferWiseExchanger::apiUrl public function URL from remote provider upon API call should be made. Overrides ExchangerProviderRemoteInterface::apiUrl
TransferWiseExchanger::getRemoteData public function Fetch external data. Overrides ExchangerProviderRemoteInterface::getRemoteData