Required changes to use Symfony uid component

This commit is contained in:
Francis Hilaire 2024-02-22 18:31:40 +01:00 committed by Grzegorz Sadowski
parent 30d3af2d13
commit fe5ad08276
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
12 changed files with 30 additions and 22 deletions

View file

@ -24,7 +24,12 @@ final class PaymentRequestHashAwareInputCommandDataTransformer implements Comman
/** @var PaymentRequestInterface $paymentRequest */
$paymentRequest = $context['object_to_populate'];
$object->setHash($paymentRequest->getHash());
$hash = $paymentRequest->getHash();
if (null === $hash) {
return $object;
}
$object->setHash($hash->toBinary());
return $object;
}

View file

@ -35,7 +35,10 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface
public function __invoke(CapturePaymentRequest $capturePaymentRequest): void
{
$paymentRequest = $this->paymentRequestRepository->findOneByHash($capturePaymentRequest->getHash());
$hash = $capturePaymentRequest->getHash();
Assert::notNull($hash, 'The payment request hash cannot be null.');
$paymentRequest = $this->paymentRequestRepository->findOneByHash($hash);
Assert::notNull($paymentRequest);
/** @var PaymentMethodInterface|null $paymentMethod */

View file

@ -26,6 +26,6 @@ final class CapturePaymentRequestCommandProvider implements PaymentRequestComman
public function provide(PaymentRequestInterface $paymentRequest): object
{
return new CapturePaymentRequest($paymentRequest->getHash());
return new CapturePaymentRequest($paymentRequest->getHash()?->toBinary());
}
}

View file

@ -26,6 +26,6 @@ final class StatusPaymentRequestCommandProvider implements PaymentRequestCommand
public function provide(PaymentRequestInterface $paymentRequest): object
{
return new StatusPaymentRequest($paymentRequest->getHash());
return new StatusPaymentRequest($paymentRequest->getHash()?->toBinary());
}
}

View file

@ -23,6 +23,7 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid
{
public function __construct(
private PaymentRequestDuplicationCheckerInterface $paymentRequestDuplicationChecker,
/** @var ServiceProviderInterface<PaymentRequestCommandProviderInterface> */
private ServiceProviderInterface $locator,
) {
}
@ -53,9 +54,6 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid
Assert::notNull($gatewayConfig);
$factoryName = $gatewayConfig->getConfig()['factory'] ?? $gatewayConfig->getFactoryName();
/** @var PaymentRequestCommandProviderInterface $provider */
$provider = $this->locator->get($factoryName);
return $provider;
return $this->locator->get($factoryName);
}
}

View file

@ -19,23 +19,18 @@ use Symfony\Contracts\Service\ServiceProviderInterface;
final class PaymentRequestTypeCommandProvider implements PaymentRequestCommandProviderInterface
{
public function __construct(
/** @var ServiceProviderInterface<PaymentRequestCommandProviderInterface> */
private ServiceProviderInterface $locator,
) {
}
public function supports(PaymentRequestInterface $paymentRequest): bool
{
/** @var PaymentRequestCommandProviderInterface $provider */
$provider = $this->locator->get($paymentRequest->getType());
return $provider->supports($paymentRequest);
return $this->locator->get($paymentRequest->getType())->supports($paymentRequest);
}
public function provide(PaymentRequestInterface $paymentRequest): object
{
/** @var PaymentRequestCommandProviderInterface $provider */
$provider = $this->locator->get($paymentRequest->getType());
return $provider->provide($paymentRequest);
return $this->locator->get($paymentRequest->getType())->provide($paymentRequest);
}
}

View file

@ -32,7 +32,10 @@ final class ModelPaymentRequestHandler implements MessageHandlerInterface
public function __invoke(PaymentRequestHashAwareInterface $command): void
{
$paymentRequest = $this->paymentRequestProvider->provideFromHash($command->getHash());
$hash = $command->getHash();
Assert::notNull($hash, 'The payment request hash cannot be null.');
$paymentRequest = $this->paymentRequestProvider->provideFromHash($hash);
Assert::notNull($paymentRequest);
$payment = $paymentRequest->getPayment();

View file

@ -35,7 +35,10 @@ final class TokenPaymentRequestHandler implements MessageHandlerInterface
public function __invoke(PaymentRequestHashAwareInterface $command): void
{
$paymentRequest = $this->paymentRequestProvider->provideFromHash($command->getHash());
$hash = $command->getHash();
Assert::notNull($hash, 'The payment request hash cannot be null.');
$paymentRequest = $this->paymentRequestProvider->provideFromHash($hash);
Assert::notNull($paymentRequest);
$token = $this->payumTokenFactory->createNew($paymentRequest);

View file

@ -26,6 +26,6 @@ final class AuthorizeCommandProvider implements PaymentRequestCommandProviderInt
public function provide(PaymentRequestInterface $paymentRequest): object
{
return new AuthorizePaymentRequest($paymentRequest->getHash());
return new AuthorizePaymentRequest($paymentRequest->getHash()?->toBinary());
}
}

View file

@ -26,6 +26,6 @@ final class CaptureCommandProvider implements PaymentRequestCommandProviderInter
public function provide(PaymentRequestInterface $paymentRequest): object
{
return new CapturePaymentRequest($paymentRequest->getHash());
return new CapturePaymentRequest($paymentRequest->getHash()?->toBinary());
}
}

View file

@ -26,6 +26,6 @@ final class StatusCommandProvider implements PaymentRequestCommandProviderInterf
public function provide(PaymentRequestInterface $paymentRequest): object
{
return new StatusPaymentRequest($paymentRequest->getHash());
return new StatusPaymentRequest($paymentRequest->getHash()?->toBinary());
}
}

View file

@ -16,6 +16,7 @@ namespace Sylius\Bundle\PaymentBundle\Doctrine\ORM;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Payment\Model\PaymentRequestInterface;
use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface;
use Symfony\Bridge\Doctrine\Types\UuidType;
/**
* @template T of PaymentRequestInterface
@ -33,7 +34,7 @@ class PaymentRequestRepository extends EntityRepository implements PaymentReques
->andWhere('o.type = :type')
->andWhere('o.payment = :payment')
->andWhere('o.method = :method')
->setParameter('paymentRequest', $paymentRequest)
->setParameter('paymentRequest', $paymentRequest->getHash(), UuidType::NAME)
->setParameter('type', $paymentRequest->getType())
->setParameter('method', $paymentRequest->getMethod())
->setParameter('payment', $paymentRequest->getPayment())