feat: implement payment step

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 3d9fc18a83
commit 3f7db4e772
12 changed files with 1273 additions and 30 deletions
@@ -4,35 +4,37 @@ declare(strict_types=1);
namespace App\Controller\Booking;
use App\BusProNet\Constants;
use App\Controller\Traits\HtmxControllerTrait;
use App\Form\BookingCreateStep3Type;
use App\Service\BookingService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
/**
* Handles the third step of the booking creation process.
*
* This controller manages the booking confirmation and final review
* before completing the booking process.
* Handles the third step of the booking creation process (payment method selection).
*/
class CreateStep3Controller extends AbstractController
{
use BookingCreateTrait;
use BookingExceptionHandlerTrait;
use HtmxControllerTrait;
public function __construct(
private readonly BookingService $bookingCreateService,
private readonly BookingService $bookingService,
) {
}
/**
* Displays the booking confirmation page.
* Displays and processes the payment method form.
*/
#[Route('/bookings/create/confirm', name: 'app_booking_create_step_3')]
public function confirm(Request $request): Response
#[Route('/bookings/create/payment', name: 'app_booking_create_step_3')]
public function step3(Request $request): Response
{
$result = $this->getOrCreateBookingCreateDto($this->bookingCreateService, $request);
$result = $this->getOrCreateBookingCreateDto($this->bookingService, $request);
if ($result instanceof Response) {
return $result;
}
@@ -43,8 +45,48 @@ class CreateStep3Controller extends AbstractController
return $redirect;
}
$form = $this->createForm(BookingCreateStep3Type::class, $bookingCreateDto);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
// TODO: Redirect to confirmation page or direct API submission
$this->addFlash('success', 'Zahlungsart erfolgreich ausgewählt.');
return $this->redirectToRoute('app_booking_create_step_3');
}
return $this->render('booking/create_step_3.html.twig', [
'bookingCreateDto' => $bookingCreateDto,
'form' => $form->createView(),
...$this->getSummaryVariables($bookingCreateDto),
]);
}
/**
* Handles HTMX refresh when payment method changes.
*/
#[Route('/bookings/create/payment/refresh', name: 'app_booking_create_step_3_refresh')]
public function refresh(Request $request): Response
{
$result = $this->getOrCreateBookingCreateDto($this->bookingService, $request);
if ($result instanceof Response) {
return $result;
}
$bookingCreateDto = $result;
$form = $this->createForm(BookingCreateStep3Type::class, $bookingCreateDto, [
'validation_groups' => false,
]);
$form->handleRequest($request);
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
return $this->render('booking/create_step_3.html.twig', [
'bookingCreateDto' => $bookingCreateDto,
'form' => $form->createView(),
...$this->getSummaryVariables($bookingCreateDto),
]);
}
}