From 8e4afc08130738332ca6616fca5e00c53d37d8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 5 Aug 2026 12:38:34 +0200 Subject: [PATCH] feat: dedicated terms urls per country for accommodation bookings --- config/services.yaml | 7 +++ src/Controller/Groups/OfferController.php | 4 +- src/Controller/Groups/Step4Controller.php | 4 +- src/Service/AccommodationTermsUrlProvider.php | 56 +++++++++++++++++++ .../Controller/Groups/OfferControllerTest.php | 9 ++- .../Controller/Groups/Step4ControllerTest.php | 7 ++- 6 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/Service/AccommodationTermsUrlProvider.php diff --git a/config/services.yaml b/config/services.yaml index 2c78cb1..5735cb3 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -267,6 +267,13 @@ services: arguments: $accommodationEmail: '%accommodation_inquiry_email%' + App\Service\AccommodationTermsUrlProvider: + arguments: + $config: + AT: '%env(ACCOMMODATION_TERMS_AT)%' + CH: '%env(ACCOMMODATION_TERMS_CH)%' + IT: '%env(ACCOMMODATION_TERMS_IT)%' + App\Service\GroupsPriceCalculator: arguments: $config: diff --git a/src/Controller/Groups/OfferController.php b/src/Controller/Groups/OfferController.php index 0704f37..b899aa3 100644 --- a/src/Controller/Groups/OfferController.php +++ b/src/Controller/Groups/OfferController.php @@ -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); diff --git a/src/Controller/Groups/Step4Controller.php b/src/Controller/Groups/Step4Controller.php index 258c9d4..4c0164a 100644 --- a/src/Controller/Groups/Step4Controller.php +++ b/src/Controller/Groups/Step4Controller.php @@ -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); diff --git a/src/Service/AccommodationTermsUrlProvider.php b/src/Service/AccommodationTermsUrlProvider.php new file mode 100644 index 0000000..8c3fd73 --- /dev/null +++ b/src/Service/AccommodationTermsUrlProvider.php @@ -0,0 +1,56 @@ + country code → terms document URL */ + private array $termsUrls; + + /** + * @param array $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 $config + * + * @return array + */ + 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); + } +} diff --git a/tests/Controller/Groups/OfferControllerTest.php b/tests/Controller/Groups/OfferControllerTest.php index 7e2a67b..edad980 100644 --- a/tests/Controller/Groups/OfferControllerTest.php +++ b/tests/Controller/Groups/OfferControllerTest.php @@ -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 PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -418,7 +419,13 @@ final class TestableOfferController extends OfferController AccommodationBookingService $bookingService, private readonly ?FormInterface $confirmationForm = null, ) { - parent::__construct($bookingRepository, $linkSigner, $breakdownCalculator, $bookingService); + parent::__construct( + $bookingRepository, + $linkSigner, + $breakdownCalculator, + $bookingService, + new AccommodationTermsUrlProvider(['AT' => '', 'CH' => '', 'IT' => ''], 'https://example.test/agb/'), + ); } protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface diff --git a/tests/Controller/Groups/Step4ControllerTest.php b/tests/Controller/Groups/Step4ControllerTest.php index 45ad226..9baba23 100644 --- a/tests/Controller/Groups/Step4ControllerTest.php +++ b/tests/Controller/Groups/Step4ControllerTest.php @@ -11,6 +11,7 @@ use App\Enum\Groups\AccommodationBookingStatus; use App\Form\Model\AccommodationBookingDto; use App\Service\AccommodationBookingService; use App\Service\AccommodationSessionManager; +use App\Service\AccommodationTermsUrlProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -353,7 +354,11 @@ final class TestableStep4Controller extends Step4Controller AccommodationSessionManager $sessionManager, private readonly FormInterface $form, ) { - parent::__construct($bookingService, $sessionManager); + parent::__construct( + $bookingService, + $sessionManager, + new AccommodationTermsUrlProvider(['AT' => '', 'CH' => '', 'IT' => ''], 'https://example.test/agb/'), + ); } /**