mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-16 22:05:20 +00:00
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.
58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Integrations\ExchangeRate;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class CurrencyConverterDriver extends ExchangeRateDriver
|
|
{
|
|
public function getExchangeRate(string $baseCurrency, string $targetCurrency): array
|
|
{
|
|
$baseUrl = $this->getBaseUrl();
|
|
$query = "{$baseCurrency}_{$targetCurrency}";
|
|
$url = "{$baseUrl}/api/v7/convert?apiKey={$this->apiKey}&q={$query}&compact=y";
|
|
$response = Http::get($url)->json();
|
|
|
|
return array_values($response[$query]);
|
|
}
|
|
|
|
public function getSupportedCurrencies(): array
|
|
{
|
|
$baseUrl = $this->getBaseUrl();
|
|
$url = "{$baseUrl}/api/v7/currencies?apiKey={$this->apiKey}";
|
|
$response = Http::get($url)->json();
|
|
|
|
if ($response == null) {
|
|
throw new ExchangeRateException('Server not responding', 'server_error');
|
|
}
|
|
|
|
if (array_key_exists('results', $response)) {
|
|
return array_keys($response['results']);
|
|
}
|
|
|
|
throw new ExchangeRateException('Please Enter Valid Provider Key.', 'invalid_key');
|
|
}
|
|
|
|
public function validateConnection(): array
|
|
{
|
|
$baseUrl = $this->getBaseUrl();
|
|
$query = 'INR_USD';
|
|
$url = "{$baseUrl}/api/v7/convert?apiKey={$this->apiKey}&q={$query}&compact=y";
|
|
$response = Http::get($url)->json();
|
|
|
|
return array_values($response[$query]);
|
|
}
|
|
|
|
private function getBaseUrl(): string
|
|
{
|
|
$type = $this->config['type'] ?? 'FREE';
|
|
|
|
return match ($type) {
|
|
'PREMIUM' => 'https://api.currconv.com',
|
|
'PREPAID' => 'https://prepaid.currconv.com',
|
|
'FREE' => 'https://free.currconv.com',
|
|
'DEDICATED' => $this->config['url'] ?? 'https://free.currconv.com',
|
|
};
|
|
}
|
|
}
|