1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Handle currency API changes

This commit is contained in:
Hillel Coren 2018-06-10 10:59:26 +03:00
parent 180dce1772
commit 784183313a
2 changed files with 17 additions and 7 deletions

View File

@ -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');

View File

@ -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'),