From 3a840e53cc0d4910cd873658194673bcd177e39c Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Thu, 7 Nov 2024 10:30:49 +0100 Subject: [PATCH] Add Gateway mapping --- src/ApiResource/Gateway/Charge.php | 2 +- src/Mapping/Accounting/AccountingMapper.php | 2 +- src/Mapping/Gateway/GatewayMapper.php | 18 ++++++++++++++++++ src/State/Gateway/GatewayStateProvider.php | 16 ++++------------ 4 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 src/Mapping/Gateway/GatewayMapper.php diff --git a/src/ApiResource/Gateway/Charge.php b/src/ApiResource/Gateway/Charge.php index 13fb4b6..0979fe2 100644 --- a/src/ApiResource/Gateway/Charge.php +++ b/src/ApiResource/Gateway/Charge.php @@ -53,7 +53,7 @@ class Charge /** * The money to-be-paid at the gateway. - * + * * It is money before gateway fees and taxes, not accountable. */ #[Assert\NotBlank()] diff --git a/src/Mapping/Accounting/AccountingMapper.php b/src/Mapping/Accounting/AccountingMapper.php index d6def27..7c3454f 100644 --- a/src/Mapping/Accounting/AccountingMapper.php +++ b/src/Mapping/Accounting/AccountingMapper.php @@ -11,7 +11,7 @@ class AccountingMapper { public function __construct( private EntityManagerInterface $entityManager, - private AccountingRepository $accountingRepository + private AccountingRepository $accountingRepository, ) {} public function toResource(Entity\Accounting $entity): Resource\Accounting diff --git a/src/Mapping/Gateway/GatewayMapper.php b/src/Mapping/Gateway/GatewayMapper.php new file mode 100644 index 0000000..16e06a7 --- /dev/null +++ b/src/Mapping/Gateway/GatewayMapper.php @@ -0,0 +1,18 @@ +name = $gateway::getName(); + $resource->supports = $gateway::getSupportedChargeTypes(); + + return $resource; + } +} diff --git a/src/State/Gateway/GatewayStateProvider.php b/src/State/Gateway/GatewayStateProvider.php index 064c877..803a7e9 100644 --- a/src/State/Gateway/GatewayStateProvider.php +++ b/src/State/Gateway/GatewayStateProvider.php @@ -6,14 +6,15 @@ use ApiPlatform\Metadata as API; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; use App\ApiResource\Gateway\Gateway; -use App\Gateway\GatewayInterface; use App\Gateway\GatewayLocator; +use App\Mapping\Gateway\GatewayMapper; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class GatewayStateProvider implements ProviderInterface { public function __construct( private GatewayLocator $gateways, + private GatewayMapper $gatewayMapper, ) {} public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null @@ -26,20 +27,11 @@ class GatewayStateProvider implements ProviderInterface } } - private function toResource(GatewayInterface $gateway): Gateway - { - $resource = new Gateway(); - $resource->name = $gateway::getName(); - $resource->supports = $gateway::getSupportedChargeTypes(); - - return $resource; - } - private function getGateways(): array { $gateways = []; foreach ($this->gateways->getGateways() as $gateway) { - $gateways[] = $this->toResource($gateway); + $gateways[] = $this->gatewayMapper->toResource($gateway); } return $gateways; @@ -50,7 +42,7 @@ class GatewayStateProvider implements ProviderInterface try { $gateway = $this->gateways->getGateway($name); - return $this->toResource($gateway); + return $this->gatewayMapper->toResource($gateway); } catch (\Exception $e) { throw new NotFoundHttpException('Not Found'); }