mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-17 14:25:21 +00:00
refactor(services): Documents→Document + ExchangeRate→Integrations/ExchangeRate
Two follow-ups to the Services reorg that landed in 6d1816bd.
**Documents → Document** (singular). Documents/ was the only plural subdir in app/Services/ — every other bucket (Company, Mail, Module, Pdf, Storage, Update, ExchangeRate) was singular. Renaming to Document/ normalizes the whole tree.
**ExchangeRate → Integrations/ExchangeRate**. Introduces Integrations/ as an umbrella for external-service adapter subsystems. Exchange rate providers move in first; AI providers, payment gateways, and any other driver-pattern integrations land as sibling subdirs (Integrations/Ai/, Integrations/Payment/) without another reorg. Integrations/ was chosen over Providers/ to avoid conceptual collision with Laravel's app/Providers/ — 'check the providers' shouldn't be ambiguous.
17 files moved, 21 consumer files rewritten to point at the new namespaces via literal-string replacement (same approach as the previous reorg). 350 tests pass, Pint clean.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Integrations\ExchangeRate;
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user