feat: optional return url
This commit is contained in:
@@ -18,6 +18,8 @@ class BookingService
|
||||
public const BOOKING_CREATE_KEY = 'booking_create';
|
||||
public const BOOKING_CREATE_BASELINE_KEY = 'booking_create_baseline_snapshot';
|
||||
public const BOOKING_EDIT_KEY = 'booking_edit';
|
||||
public const RETURN_URL_KEY = 'booking_return_url';
|
||||
public const DEFAULT_RETURN_URL = 'https://www.ep-reisen.de';
|
||||
|
||||
public function __construct(
|
||||
private readonly TravelDataService $travelDataService,
|
||||
@@ -146,6 +148,8 @@ class BookingService
|
||||
*
|
||||
* This method removes all booking session data including the main DTO
|
||||
* and any cached snapshots to ensure a completely fresh start.
|
||||
* Note: RETURN_URL_KEY is intentionally preserved so it remains available
|
||||
* for redirects after cancel or error flows.
|
||||
*/
|
||||
public function clearBookingSession(Request $request): void
|
||||
{
|
||||
@@ -154,6 +158,36 @@ class BookingService
|
||||
$session->remove(self::BOOKING_CREATE_BASELINE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the return URL in the session.
|
||||
*
|
||||
* Validates that the URL is a valid absolute URL with http/https scheme.
|
||||
* Falls back to the default return URL if null or invalid.
|
||||
*/
|
||||
public function storeReturnUrl(Request $request, ?string $returnUrl): void
|
||||
{
|
||||
$url = self::DEFAULT_RETURN_URL;
|
||||
|
||||
if (null !== $returnUrl && '' !== trim($returnUrl)) {
|
||||
if (false !== filter_var($returnUrl, \FILTER_VALIDATE_URL)
|
||||
&& 1 === preg_match('#^https?://#i', $returnUrl)) {
|
||||
$url = $returnUrl;
|
||||
}
|
||||
}
|
||||
|
||||
$request->getSession()->set(self::RETURN_URL_KEY, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the return URL from the session.
|
||||
*
|
||||
* Returns the default URL if not set in session.
|
||||
*/
|
||||
public function getReturnUrl(Request $request): string
|
||||
{
|
||||
return $request->getSession()->get(self::RETURN_URL_KEY, self::DEFAULT_RETURN_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fresh booking session with the provided travel parameters.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user