GatewayCheckouts should only be updated by the Gateways
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Dto;
|
||||
|
||||
use App\Entity\GatewayCheckoutStatus;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class GatewayCheckoutUpdateDto
|
||||
{
|
||||
/**
|
||||
* The status of the checkout with the Gateway.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
public GatewayCheckoutStatus $status;
|
||||
|
||||
/**
|
||||
* An external identifier provided by the Gateway for the payment.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
public string $gatewayReference;
|
||||
|
||||
public function __construct(
|
||||
GatewayCheckoutStatus $status,
|
||||
string $gatewayReference
|
||||
) {
|
||||
$this->status = $status;
|
||||
$this->gatewayReference = $gatewayReference;
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,8 @@ namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\Dto\GatewayCheckoutUpdateDto;
|
||||
use App\Repository\GatewayCheckoutRepository;
|
||||
use App\State\GatewayCheckoutProcessor;
|
||||
use App\State\GatewayCheckoutUpdateProcessor;
|
||||
use App\Validator\GatewayName;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
@@ -20,13 +18,13 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
/**
|
||||
* A GatewayCheckout bundles the data to perform a payment operation with a Gateway.\
|
||||
* \
|
||||
* Once the Gateway validates the checkout as successful it will generated the appropiate AccountingTransactions for each GatewayCharge.
|
||||
* Once the Gateway validates the payment as successful the GatewayCheckout will be updated
|
||||
* and respective AccountingTransactions will be generated for each GatewayCharge.
|
||||
*/
|
||||
#[Gedmo\Loggable()]
|
||||
#[API\GetCollection()]
|
||||
#[API\Post(processor: GatewayCheckoutProcessor::class)]
|
||||
#[API\Get()]
|
||||
#[API\Patch(input: GatewayCheckoutUpdateDto::class, processor: GatewayCheckoutUpdateProcessor::class)]
|
||||
#[API\ApiFilter(filterClass: SearchFilter::class, properties: ['origin' => 'exact', 'charges.target' => 'exact'])]
|
||||
#[ORM\Entity(repositoryClass: GatewayCheckoutRepository::class)]
|
||||
class GatewayCheckout
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Dto\GatewayCheckoutUpdateDto;
|
||||
use App\Entity\GatewayCheckout;
|
||||
use App\Repository\GatewayCheckoutRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class GatewayCheckoutUpdateProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private GatewayCheckoutRepository $checkoutRepository,
|
||||
private EntityManagerInterface $entityManager,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GatewayCheckoutUpdateDto $data
|
||||
*/
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): GatewayCheckout
|
||||
{
|
||||
$checkout = $this->checkoutRepository->find($uriVariables['id']);
|
||||
|
||||
if (!$checkout) {
|
||||
throw new HttpException(Response::HTTP_NOT_FOUND, sprintf("The checkout '%s' does not exist.", $uriVariables['id']));
|
||||
}
|
||||
|
||||
$checkout->setGatewayReference($data->gatewayReference);
|
||||
|
||||
$this->entityManager->persist($checkout);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $checkout;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user