/**
  * Calculates the exchange rate between ISOs.
  *
  * @param string $currencyFromIso The currency ISO we are converting from.
  * @param string $currencyToIso   The currency ISO we are converting to.
  *
  * @return float
  *
  * @throws CurrencyNotConvertibleException
  */
 protected function calculateExchangeRateBetweenIsos($currencyFromIso, $currencyToIso)
 {
     $currencyExchangeRates = $this->currencyManager->getExchangeRateList();
     /**
      * We are calculating the exchange from the default currency.
      */
     if ($this->defaultExchangeCurrencyIso == $currencyFromIso && isset($currencyExchangeRates[$currencyToIso])) {
         $exchangeRate = $currencyExchangeRates[$currencyToIso]['rate'];
     } elseif ($this->defaultExchangeCurrencyIso == $currencyToIso && isset($currencyExchangeRates[$currencyFromIso])) {
         $exchangeRate = 1 / $currencyExchangeRates[$currencyFromIso]['rate'];
     } elseif (isset($currencyExchangeRates[$currencyFromIso]) && isset($currencyExchangeRates[$currencyToIso])) {
         $exchangeRate = 1 / $currencyExchangeRates[$currencyFromIso]['rate'] * $currencyExchangeRates[$currencyToIso]['rate'];
     } else {
         throw new CurrencyNotConvertibleException();
     }
     return $exchangeRate;
 }
Esempio n. 2
0
 /**
  * Convert Amount given base currency iso
  *
  * @param string  $currencyToIso Currency iso where to convert to
  * @param integer $amount        Amount to convert
  * @param boolean $type          Type of conversion
  *
  * @return float conversion
  *
  * @throws CurrencyNotConvertibleException Currencies cannot be converted
  */
 private function convertToIso($currencyToIso, $amount, $type)
 {
     if (isset($this->currencyManager->getExchangeRateList()[$currencyToIso])) {
         $currencyRate = $this->currencyManager->getExchangeRateList()[$currencyToIso];
     } else {
         /**
          * No CurrencyRate can be found
          */
         throw new CurrencyNotConvertibleException();
     }
     return $type ? $amount * $currencyRate['rate'] : $amount / $currencyRate['rate'];
 }