dfdsf
All checks were successful
Deploy / deploy-staging (push) Successful in 5s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-29 01:27:49 +02:00
parent 1da63807eb
commit b76edb49b0

View File

@@ -414,12 +414,25 @@ final class FxRatesService
private function fetchCurrenciesPayload(): array private function fetchCurrenciesPayload(): array
{ {
$request = $this->buildCurrenciesRequest(); $requests = $this->buildCurrenciesRequests();
if ($request === null) { if ($requests === []) {
throw new \RuntimeException('FX-API-Key fehlt.'); throw new \RuntimeException('FX-API-Key fehlt.');
} }
$payload = $this->requestJson($request['url'], $request['headers'] ?? [], 'Waehrungskatalog konnte nicht geladen werden.'); $payload = null;
$lastError = null;
foreach ($requests as $request) {
try {
$payload = $this->requestJson($request['url'], $request['headers'] ?? [], 'Waehrungskatalog konnte nicht geladen werden.');
break;
} catch (\RuntimeException $exception) {
$lastError = $exception;
}
}
if (!is_array($payload)) {
throw $lastError ?? new \RuntimeException('Waehrungskatalog konnte nicht geladen werden.');
}
if ($this->isCurrencyApiCom()) { if ($this->isCurrencyApiCom()) {
return $this->normalizeCurrencyApiComCurrenciesPayload($payload); return $this->normalizeCurrencyApiComCurrenciesPayload($payload);
@@ -482,30 +495,40 @@ final class FxRatesService
]; ];
} }
private function buildCurrenciesRequest(): ?array private function buildCurrenciesRequests(): array
{ {
$apiKey = $this->apiKey(); $apiKey = $this->apiKey();
if ($apiKey === '') { if ($apiKey === '') {
return null; return [];
} }
if ($this->isCurrencyApiCom()) { if ($this->isCurrencyApiCom()) {
return [ return [[
'url' => $this->currenciesApiUrl() . '/v3/currencies', 'url' => $this->currenciesApiUrl() . '/v3/currencies',
'headers' => [ 'headers' => [
'Accept: application/json', 'Accept: application/json',
'apikey: ' . $apiKey, 'apikey: ' . $apiKey,
], ],
]; ]];
} }
return [ return [
'url' => sprintf( [
'%s/api/v2/currencies?output=json&key=%s', 'url' => sprintf(
$this->currenciesApiUrl(), '%s/api/v1/currencies?output=json&key=%s',
rawurlencode($apiKey) $this->currenciesApiUrl(),
), rawurlencode($apiKey)
'headers' => ['Accept: application/json'], ),
'headers' => ['Accept: application/json'],
],
[
'url' => sprintf(
'%s/api/v2/currencies?output=json&key=%s',
$this->currenciesApiUrl(),
rawurlencode($apiKey)
),
'headers' => ['Accept: application/json'],
],
]; ];
} }