Files
crowd-fund-api/src/State/GatewayCheckoutProcessor.php
T

37 lines
949 B
PHP

<?php
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\GatewayCheckout;
use App\Library\Economy\Payment\GatewayLocator;
use Doctrine\ORM\EntityManagerInterface;
class GatewayCheckoutProcessor implements ProcessorInterface
{
public function __construct(
private GatewayLocator $gatewayLocator,
private EntityManagerInterface $entityManager
) {
}
/**
* @param GatewayCheckout $data
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): GatewayCheckout
{
$gateway = $this->gatewayLocator->getGatewayOf($data);
$this->entityManager->persist($data);
$this->entityManager->flush();
$checkout = $gateway->sendData($data);
$this->entityManager->persist($checkout);
$this->entityManager->flush();
return $checkout;
}
}