mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-03 05:41:07 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Money\ExchangeRates;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class CurrencyLayerDriver extends ExchangeRateDriver
|
|
{
|
|
private string $baseUrl = 'http://api.currencylayer.com';
|
|
|
|
public function getExchangeRate(string $baseCurrency, string $targetCurrency): array
|
|
{
|
|
$url = "{$this->baseUrl}/live?access_key={$this->apiKey}&source={$baseCurrency}¤cies={$targetCurrency}";
|
|
$response = Http::get($url)->json();
|
|
|
|
if (array_key_exists('success', $response) && $response['success'] == false) {
|
|
throw new ExchangeRateException($response['error']['info'], 'provider_error');
|
|
}
|
|
|
|
return array_values($response['quotes']);
|
|
}
|
|
|
|
public function getSupportedCurrencies(): array
|
|
{
|
|
$url = "{$this->baseUrl}/list?access_key={$this->apiKey}";
|
|
$response = Http::get($url)->json();
|
|
|
|
if ($response == null) {
|
|
throw new ExchangeRateException('Server not responding', 'server_error');
|
|
}
|
|
|
|
if (array_key_exists('currencies', $response)) {
|
|
return array_keys($response['currencies']);
|
|
}
|
|
|
|
throw new ExchangeRateException('Please Enter Valid Provider Key.', 'invalid_key');
|
|
}
|
|
|
|
public function validateConnection(): array
|
|
{
|
|
$url = "{$this->baseUrl}/live?access_key={$this->apiKey}&source=INR¤cies=USD";
|
|
$response = Http::get($url)->json();
|
|
|
|
if (array_key_exists('success', $response) && $response['success'] == false) {
|
|
throw new ExchangeRateException($response['error']['info'], 'provider_error');
|
|
}
|
|
|
|
return array_values($response['quotes']);
|
|
}
|
|
}
|