Add Gateway mapping

This commit is contained in:
2024-11-07 10:30:49 +01:00
parent a980129bae
commit 3a840e53cc
4 changed files with 24 additions and 14 deletions
+1 -1
View File
@@ -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()]
+1 -1
View File
@@ -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
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace App\Mapping\Gateway;
use App\ApiResource\Gateway\Gateway;
use App\Gateway\GatewayInterface;
class GatewayMapper
{
public function toResource(GatewayInterface $gateway): Gateway
{
$resource = new Gateway();
$resource->name = $gateway::getName();
$resource->supports = $gateway::getSupportedChargeTypes();
return $resource;
}
}
+4 -12
View File
@@ -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');
}