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
{
$request = $this->buildCurrenciesRequest();
if ($request === null) {
$requests = $this->buildCurrenciesRequests();
if ($requests === []) {
throw new \RuntimeException('FX-API-Key fehlt.');
}
$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()) {
return $this->normalizeCurrencyApiComCurrenciesPayload($payload);
@@ -482,30 +495,40 @@ final class FxRatesService
];
}
private function buildCurrenciesRequest(): ?array
private function buildCurrenciesRequests(): array
{
$apiKey = $this->apiKey();
if ($apiKey === '') {
return null;
return [];
}
if ($this->isCurrencyApiCom()) {
return [
return [[
'url' => $this->currenciesApiUrl() . '/v3/currencies',
'headers' => [
'Accept: application/json',
'apikey: ' . $apiKey,
],
];
]];
}
return [
[
'url' => sprintf(
'%s/api/v1/currencies?output=json&key=%s',
$this->currenciesApiUrl(),
rawurlencode($apiKey)
),
'headers' => ['Accept: application/json'],
],
[
'url' => sprintf(
'%s/api/v2/currencies?output=json&key=%s',
$this->currenciesApiUrl(),
rawurlencode($apiKey)
),
'headers' => ['Accept: application/json'],
],
];
}