Exchange Rate Key Added

This commit is contained in:
devansh bawari 2021-05-18 17:58:24 +05:30
parent 90c52be42f
commit b5a9ae05c8
3 changed files with 28 additions and 15 deletions

View File

@ -40,6 +40,7 @@ ADMIN_MAIL_TO=
MAIL_FROM_NAME=
FIXER_API_KEY=
EXCHANGE_RATES_API_KEY=
PUSHER_APP_ID=
PUSHER_APP_KEY=

View File

@ -38,6 +38,7 @@ return [
],
'exchange_rates' => [
'key' => env('EXCHANGE_RATES_API_KEY'),
'class' => 'Webkul\Core\Helpers\Exchange\ExchangeRates'
],
],

View File

@ -9,21 +9,28 @@ use Webkul\Core\Repositories\ExchangeRateRepository;
class ExchangeRates extends ExchangeRate
{
/**
* API endpoint
* API key.
*
* @var string
*/
protected $apiKey;
/**
* API endpoint.
*
* @var string
*/
protected $apiEndPoint;
/**
* Holds CurrencyRepository instance
* CurrencyRepository $currencyRepository
*
* @var \Webkul\Core\Repositories\CurrencyRepository
*/
protected $currencyRepository;
/**
* Holds ExchangeRateRepository instance
* ExchangeRateRepository $exchangeRateRepository
*
* @var \Webkul\Core\Repositories\ExchangeRateRepository
*/
@ -46,10 +53,12 @@ class ExchangeRates extends ExchangeRate
$this->exchangeRateRepository = $exchangeRateRepository;
$this->apiEndPoint = 'https://api.exchangeratesapi.io/latest';
$this->apiKey = config('services.exchange-api.exchange_rates.key');
}
/**
* Fetch rates and updates in currency_exchange_rates table
* Fetch rates and updates in `currency_exchange_rates` table.
*
* @return \Exception|void
*/
@ -62,7 +71,7 @@ class ExchangeRates extends ExchangeRate
continue;
}
$result = $client->request('GET', $this->apiEndPoint . '?base=' . config('app.currency') . '&symbols=' . $currency->code);
$result = $client->request('GET', $this->apiEndPoint . '?access_key='. $this->apiKey . '&base=' . config('app.currency') . '&symbols=' . $currency->code);
$result = json_decode($result->getBody()->getContents(), true);
@ -70,7 +79,9 @@ class ExchangeRates extends ExchangeRate
throw new \Exception(
isset($result['error']['info'])
? $result['error']['info']
: $result['error']['type'], 1);
: $result['error']['type'],
1
);
}
if ($exchangeRate = $currency->exchange_rate) {