feat: update voucher purchase urls to match established patterns
This commit is contained in:
1 parent
e42f836d9b
commit
627b190fcb
7 files changed
+167
-45
No files matched your search
@@ -33,52 +33,49 @@ class IndexController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a loading page that posts to init, as the booking flow does.
|
||||
* Entry point: starts a purchase, or resumes the unfinished one, and sends the visitor to the
|
||||
* login page (sign in or continue as guest).
|
||||
*
|
||||
* A GET with side effects, kept safe for speculative fetches by being idempotent: an existing
|
||||
* draft is never reset, only its return URL is updated when one is given. Starting over goes through cancel, and
|
||||
* a completed purchase clears the draft. /voucher is an English alias for links.
|
||||
*/
|
||||
#[Route('/gutschein', name: 'app_voucher', methods: ['GET'])]
|
||||
public function index(#[MapQueryParameter('r')] ?string $returnUrl = null): Response
|
||||
#[Route('/voucher', name: 'app_voucher_alias', methods: ['GET'])]
|
||||
public function index(Request $request, #[MapQueryParameter('r')] ?string $returnUrl = null): Response
|
||||
{
|
||||
return $this->render('voucher/index.html.twig', [
|
||||
'returnUrl' => $returnUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a fresh purchase and sends the visitor to the login page (sign in or continue as guest).
|
||||
*
|
||||
* POST-only for the same reason as app_booking_create_init: it resets session state and calls
|
||||
* BusPro, so nothing that speculatively fetches URLs may trigger it.
|
||||
*/
|
||||
#[Route('/gutschein/init', name: 'app_voucher_init', methods: ['POST'])]
|
||||
public function init(Request $request, #[MapQueryParameter('r')] ?string $returnUrl = null): Response
|
||||
{
|
||||
$this->sessionManager->clear($request);
|
||||
$this->sessionManager->storeReturnUrl($request, $returnUrl);
|
||||
|
||||
try {
|
||||
$templates = $this->templateProvider->getTemplates();
|
||||
$paymentMethod = $this->templateProvider->getPaymentMethod();
|
||||
} catch (VoucherShopUnavailableException) {
|
||||
$this->addFlash('error', 'Gutscheine können gerade nicht gekauft werden. Bitte versuche es später noch einmal.');
|
||||
|
||||
return $this->htmxRedirect($request, $this->generateUrl('app_voucher_error'));
|
||||
$resumed = null !== $this->sessionManager->find($request);
|
||||
if (!$resumed || null !== $returnUrl) {
|
||||
$this->sessionManager->storeReturnUrl($request, $returnUrl);
|
||||
}
|
||||
|
||||
$dto = new VoucherPurchaseDto();
|
||||
$dto->minAmount = $templates->minAmount;
|
||||
$dto->maxAmount = $templates->maxAmount;
|
||||
$dto->paymentMethod = $paymentMethod;
|
||||
if (1 === \count($templates->templates)) {
|
||||
$dto->template = $templates->templates[0];
|
||||
if (!$resumed) {
|
||||
try {
|
||||
$templates = $this->templateProvider->getTemplates();
|
||||
$paymentMethod = $this->templateProvider->getPaymentMethod();
|
||||
} catch (VoucherShopUnavailableException) {
|
||||
$this->addFlash('error', 'Gutscheine können gerade nicht gekauft werden. Bitte versuche es später noch einmal.');
|
||||
|
||||
return $this->redirectToRoute('app_voucher_error');
|
||||
}
|
||||
|
||||
$dto = new VoucherPurchaseDto();
|
||||
$dto->minAmount = $templates->minAmount;
|
||||
$dto->maxAmount = $templates->maxAmount;
|
||||
$dto->paymentMethod = $paymentMethod;
|
||||
if (1 === \count($templates->templates)) {
|
||||
$dto->template = $templates->templates[0];
|
||||
}
|
||||
|
||||
$this->sessionManager->save($request, $dto);
|
||||
}
|
||||
|
||||
$this->sessionManager->save($request, $dto);
|
||||
$this->purchaseFlowResolver->markStarted($request, PurchaseFlow::Voucher);
|
||||
|
||||
return $this->htmxRedirect($request, $this->generateUrl('app_login'));
|
||||
return $this->redirectToRoute('app_login');
|
||||
}
|
||||
|
||||
#[Route('/gutschein/abbrechen', name: 'app_voucher_cancel', methods: ['GET', 'POST'])]
|
||||
#[Route('/vouchers/cancel', name: 'app_voucher_cancel', methods: ['GET', 'POST'])]
|
||||
public function cancel(Request $request): Response
|
||||
{
|
||||
if (Request::METHOD_POST !== $request->getMethod()) {
|
||||
@@ -100,7 +97,7 @@ class IndexController extends AbstractController
|
||||
return $this->htmxRedirect($request, $returnUrl);
|
||||
}
|
||||
|
||||
#[Route('/gutschein/fehler', name: 'app_voucher_error', methods: ['GET'])]
|
||||
#[Route('/vouchers/create/error', name: 'app_voucher_error', methods: ['GET'])]
|
||||
public function error(Request $request): Response
|
||||
{
|
||||
return $this->render('booking/create/error.html.twig', [
|
||||
|
||||
Reference in new issue
Block a user