EuropeanCentralBankExchanger.php in Commerce Exchanger 8
File
src/Plugin/Commerce/ExchangerProvider/EuropeanCentralBankExchanger.php
View source
<?php
namespace Drupal\commerce_exchanger\Plugin\Commerce\ExchangerProvider;
use SimpleXMLElement;
class EuropeanCentralBankExchanger extends ExchangerProviderRemoteBase {
public function apiUrl() {
return 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml';
}
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 = [];
foreach ($xml->Cube->Cube->Cube as $rate) {
$code = (string) $rate['currency'];
$rate = (string) $rate['rate'];
$data[$code] = $rate;
}
}
return $data;
}
}