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
+3 -1
View File
@@ -12,6 +12,7 @@ use App\Repository\Groups\AccommodationBookingRepository;
use App\Service\AccommodationBookingBreakdownCalculator;
use App\Service\AccommodationBookingLinkSigner;
use App\Service\AccommodationBookingService;
use App\Service\AccommodationTermsUrlProvider;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -27,6 +28,7 @@ class OfferController extends AbstractController
private readonly AccommodationBookingLinkSigner $linkSigner,
private readonly AccommodationBookingBreakdownCalculator $breakdownCalculator,
private readonly AccommodationBookingService $bookingService,
private readonly AccommodationTermsUrlProvider $termsUrlProvider,
) {
}
@@ -96,7 +98,7 @@ class OfferController extends AbstractController
}
$confirmationForm = $this->createForm(OfferAcceptConfirmationType::class, null, [
'terms_url' => $this->getParameter('terms_and_conditions_url'),
'terms_url' => $this->termsUrlProvider->forAccommodation($booking->getAccommodation()),
]);
$confirmationForm->handleRequest($request);
+3 -1
View File
@@ -15,6 +15,7 @@ use App\Htmx\HxTrait;
use App\Model\AccommodationBookingContext;
use App\Service\AccommodationBookingService;
use App\Service\AccommodationSessionManager;
use App\Service\AccommodationTermsUrlProvider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
@@ -26,6 +27,7 @@ class Step4Controller extends AbstractAccommodationController
public function __construct(
private readonly AccommodationBookingService $bookingService,
private readonly AccommodationSessionManager $sessionManager,
private readonly AccommodationTermsUrlProvider $termsUrlProvider,
) {
}
@@ -94,7 +96,7 @@ class Step4Controller extends AbstractAccommodationController
$accommodation = $this->loadAccommodationOrFail($dto);
$confirmationForm = $this->createForm(AccommodationBookingConfirmationType::class, $dto, [
'terms_url' => $this->getParameter('terms_and_conditions_url'),
'terms_url' => $this->termsUrlProvider->forAccommodation($accommodation),
]);
$confirmationForm->handleRequest($request);
@@ -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);
}
}