Add GatewayController to handle redirections

This commit is contained in:
2024-06-25 13:23:30 +02:00
parent a257931e25
commit aa51170d7d
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Controller;
use ApiPlatform\Api\IriConverterInterface;
use App\Library\Economy\Payment\GatewayLocator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/v4/controllers')]
class GatewayController extends AbstractController
{
public function __construct(
private GatewayLocator $gatewayLocator,
private EntityManagerInterface $entityManager,
private IriConverterInterface $iriConverter
) {
}
#[Route('/gateway_redirect', name: 'gateway_redirect')]
public function handleRedirect(Request $request): Response
{
$gateway = $this->gatewayLocator->getGateway($request->query->get('gateway'));
$checkout = $gateway->handleRedirect($request);
$this->entityManager->persist($checkout);
$this->entityManager->flush();
// TO-DO: This should redirect the user to a GUI
return new RedirectResponse($this->iriConverter->getIriFromResource($checkout));
}
}