public function getRate($source, $target)
    {

        $provider = env('FOREX_PROVIDER');
        $url = env('FOREX_PROVIDER_URL');
        $key = env('FOREX_PROVIDER_KEY', '');
        $cache_minutes = intval(env('FOREX_CACHE_MINUTES', 720));

        if ((! $provider) || (! $url))
            throw new ForexException('Invalid exchange rate provider configuration.');

        if(! in_array($source, $this->currency_codes))
            throw new ForexException('Invalid source currency code.');

        if(! in_array($target, $this->currency_codes))
            throw new ForexException('Invalid target currency code.');

        $conversion = $source.$target;
        
        if (($cache_minutes > 0) && (Cache::has($conversion)))
            $rate = Cache::get($conversion);
        else {

            $provider_class = 'Viewflex\Forex\Providers\\' . $provider;

            if (! class_exists($provider_class))
                throw new ForexException("\"" . $provider . "\" is not a supported provider.");

            $this->service = new $provider_class($url, $key, $cache_minutes);
            $rate = $this->service->getRate($source, $target);
            
            if($rate <= 0)
                throw new ForexException('Error retrieving exchange rate.');

            if ($cache_minutes > 0) {
                if(! Cache::add($conversion, $rate, Carbon::now()->addMinutes($cache_minutes)))
                    throw new ForexException('Unable to add exchange rate to cache.');
            }
            
        }

        return $rate;
    }