Add Gateway mapping
This commit is contained in:
@@ -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()]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user