From e99aea6f8cd90ebcf2c5c91f19dad9bb95cd7069 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Wed, 17 Jul 2024 13:52:50 +0200 Subject: [PATCH] Use new GatewayInterface methods on controller and processor --- src/Controller/GatewayController.php | 16 +++------------- src/State/GatewayCheckoutProcessor.php | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Controller/GatewayController.php b/src/Controller/GatewayController.php index f044e6c..199afb1 100644 --- a/src/Controller/GatewayController.php +++ b/src/Controller/GatewayController.php @@ -2,11 +2,8 @@ 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; @@ -22,8 +19,6 @@ class GatewayController extends AbstractController public function __construct( private GatewayLocator $gatewayLocator, - private EntityManagerInterface $entityManager, - private IriConverterInterface $iriConverter ) { } @@ -31,18 +26,13 @@ class GatewayController extends AbstractController 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)); + return $gateway->handleRedirect($request); } #[Route('/gateway_webhooks', name: self::WEBHOOKS)] public function handleWebhook(Request $request): Response { - return new Response(500); + $gateway = $this->gatewayLocator->getGateway($request->query->get('gateway')); + return $gateway->handleWebhook($request); } } diff --git a/src/State/GatewayCheckoutProcessor.php b/src/State/GatewayCheckoutProcessor.php index a69f192..c5e64ea 100644 --- a/src/State/GatewayCheckoutProcessor.php +++ b/src/State/GatewayCheckoutProcessor.php @@ -26,7 +26,7 @@ class GatewayCheckoutProcessor implements ProcessorInterface $this->entityManager->persist($data); $this->entityManager->flush(); - $checkout = $gateway->create($data); + $checkout = $gateway->sendData($data); $this->entityManager->persist($checkout); $this->entityManager->flush();