feat: dedicated terms urls per country for accommodation bookings

This commit is contained in:
Björn Fromme
2026-08-05 12:38:34 +02:00
parent e5fa63b7e8
commit 8e4afc0813
6 changed files with 83 additions and 4 deletions
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace App\Service;
use App\Entity\Groups\Accommodation;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Resolves the terms and conditions a booking is concluded under.
*
* Which legal entity operates an accommodation depends on the country it is located in,
* and each entity has its own AGB document. Countries without a dedicated entity — and
* any country whose document is not configured in this environment — fall back to the
* general E&P terms.
*/
class AccommodationTermsUrlProvider
{
/** @var array<string, string> country code → terms document URL */
private array $termsUrls;
/**
* @param array<string, string> $config
*/
public function __construct(
array $config,
private readonly string $termsAndConditionsUrl,
) {
$this->termsUrls = $this->resolveConfig($config);
}
public function forAccommodation(?Accommodation $accommodation): string
{
$country = $accommodation?->getCountry();
$url = null !== $country ? ($this->termsUrls[$country->value] ?? '') : '';
return '' !== $url ? $url : $this->termsAndConditionsUrl;
}
/**
* @param array<string, string> $config
*
* @return array<string, string>
*/
private function resolveConfig(array $config): array
{
$resolver = new OptionsResolver();
$resolver->setRequired(['AT', 'CH', 'IT']);
$resolver->setAllowedTypes('AT', 'string');
$resolver->setAllowedTypes('CH', 'string');
$resolver->setAllowedTypes('IT', 'string');
return $resolver->resolve($config);
}
}