diff --git a/app/Console/Commands/SendReminders.php b/app/Console/Commands/SendReminders.php index dd34bdd862..2e0ddc1f7f 100644 --- a/app/Console/Commands/SendReminders.php +++ b/app/Console/Commands/SendReminders.php @@ -200,15 +200,24 @@ class SendReminders extends Command return; } - $this->info(date('r') . ' Loading latest exchange rates...'); + if (config('ninja.exchange_rates_enabled')) { + $this->info(date('r') . ' Loading latest exchange rates...'); - $data = CurlUtils::get(config('ninja.exchange_rates_url')); - $data = json_decode($data); + $response = CurlUtils::get(config('ninja.exchange_rates_url')); + $data = json_decode($response); - Currency::whereCode(config('ninja.exchange_rates_base'))->update(['exchange_rate' => 1]); + if ($data && property_exists($data, 'rates')) { + Currency::whereCode(config('ninja.exchange_rates_base'))->update(['exchange_rate' => 1]); - foreach ($data->rates as $code => $rate) { - Currency::whereCode($code)->update(['exchange_rate' => $rate]); + foreach ($data->rates as $code => $rate) { + Currency::whereCode($code)->update(['exchange_rate' => $rate]); + } + } else { + $this->info(date('r') . ' Error: failed to load exchange rates - ' . $response); + \DB::table('currencies')->update(['exchange_rate' => 1]); + } + } else { + \DB::table('currencies')->update(['exchange_rate' => 1]); } CurlUtils::get(SITE_URL . '?clear_cache=true'); diff --git a/config/ninja.php b/config/ninja.php index 630fe11b63..07a3213bb3 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -19,7 +19,8 @@ return [ 'coupon_75_off' => env('COUPON_75_OFF', false), 'coupon_free_year' => env('COUPON_FREE_YEAR', false), - // data services + // Currency exchange rates + 'exchange_rates_enabled' => env('EXCHANGE_RATES_ENABLED', false), 'exchange_rates_url' => env('EXCHANGE_RATES_URL', 'https://api.fixer.io/latest'), 'exchange_rates_base' => env('EXCHANGE_RATES_BASE', 'EUR'),