From 9acd3b741581c36fb39e2fe276b30fd6c1480281 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 6 Nov 2023 20:15:41 +0100 Subject: [PATCH 001/200] Add Payment request model --- composer.json | 1 + .../Migrations/Version20231106190918.php | 39 ++++++ .../DependencyInjection/Configuration.php | 19 +++ .../Resources/config/app/config.yml | 8 ++ .../doctrine/model/PaymentRequest.orm.xml | 44 ++++++ src/Sylius/Bundle/PaymentBundle/composer.json | 3 +- .../Payment/Model/PaymentRequest.php | 106 +++++++++++++++ .../Payment/Model/PaymentRequestInterface.php | 70 ++++++++++ .../Payment/spec/Model/PaymentRequestSpec.php | 126 ++++++++++++++++++ symfony.lock | 9 ++ 10 files changed, 424 insertions(+), 1 deletion(-) create mode 100644 src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php create mode 100644 src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml create mode 100644 src/Sylius/Component/Payment/Model/PaymentRequest.php create mode 100644 src/Sylius/Component/Payment/Model/PaymentRequestInterface.php create mode 100644 src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php diff --git a/composer.json b/composer.json index 7811e75f59..473e9dff0c 100644 --- a/composer.json +++ b/composer.json @@ -71,6 +71,7 @@ "psr/http-message": "^1.0", "psr/log": "^2.0", "ramsey/uuid": "^4.0", + "ramsey/uuid-doctrine": "^2.0", "sonata-project/block-bundle": "^4.2 || ^5.0", "stof/doctrine-extensions-bundle": "^1.4", "sylius-labs/association-hydrator": "^1.1 || ^1.2", diff --git a/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php b/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php new file mode 100644 index 0000000000..a38141a0cc --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php @@ -0,0 +1,39 @@ +addSql('CREATE TABLE sylius_payment_request (hash CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, data LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\', details JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_86D904B19883967 (method_id), INDEX IDX_86D904B4C3A3BB (payment_id), PRIMARY KEY(hash)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B19883967 FOREIGN KEY (method_id) REFERENCES sylius_payment_method (id)'); + $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B4C3A3BB FOREIGN KEY (payment_id) REFERENCES sylius_payment (id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE sylius_payment_request DROP FOREIGN KEY FK_86D904B19883967'); + $this->addSql('ALTER TABLE sylius_payment_request DROP FOREIGN KEY FK_86D904B4C3A3BB'); + $this->addSql('DROP TABLE sylius_payment_request'); + } +} diff --git a/src/Sylius/Bundle/PaymentBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/PaymentBundle/DependencyInjection/Configuration.php index 6c26b7a571..f525bae9cb 100644 --- a/src/Sylius/Bundle/PaymentBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/PaymentBundle/DependencyInjection/Configuration.php @@ -24,6 +24,8 @@ use Sylius\Component\Payment\Model\PaymentMethod; use Sylius\Component\Payment\Model\PaymentMethodInterface; use Sylius\Component\Payment\Model\PaymentMethodTranslation; use Sylius\Component\Payment\Model\PaymentMethodTranslationInterface; +use Sylius\Component\Payment\Model\PaymentRequest; +use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Resource\Factory\Factory; use Sylius\Component\Resource\Factory\TranslatableFactory; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; @@ -118,6 +120,23 @@ final class Configuration implements ConfigurationInterface ->end() ->end() ->end() + ->arrayNode('payment_request') + ->addDefaultsIfNotSet() + ->children() + ->variableNode('options')->end() + ->arrayNode('classes') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('model')->defaultValue(PaymentRequest::class)->cannotBeEmpty()->end() + ->scalarNode('interface')->defaultValue(PaymentRequestInterface::class)->cannotBeEmpty()->end() + ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() + ->scalarNode('repository')->cannotBeEmpty()->end() + ->scalarNode('factory')->defaultValue(Factory::class)->end() + ->scalarNode('form')->defaultValue(null)->end() + ->end() + ->end() + ->end() + ->end() ->end() ->end() ->end() diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml index e5bfe497fe..7748456355 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml @@ -1,6 +1,14 @@ # This file is part of the Sylius package. # (c) Sylius Sp. z o.o. +parameters: + sylius.uuid_type: Ramsey\Uuid\Doctrine\UuidType + +doctrine: + dbal: + types: + sylius_uuid: "%sylius.uuid_type%" + jms_serializer: metadata: directories: diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml new file mode 100644 index 0000000000..992e2712ba --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PaymentBundle/composer.json b/src/Sylius/Bundle/PaymentBundle/composer.json index dce6337dad..3ebb64ae54 100644 --- a/src/Sylius/Bundle/PaymentBundle/composer.json +++ b/src/Sylius/Bundle/PaymentBundle/composer.json @@ -29,7 +29,8 @@ "php": "^8.2", "sylius/payment": "^2.0", "sylius/resource-bundle": "^1.10", - "symfony/framework-bundle": "^6.4.1" + "symfony/framework-bundle": "^6.4.1", + "ramsey/uuid-doctrine": "^2.0" }, "conflict": { "doctrine/orm": "2.15.2" diff --git a/src/Sylius/Component/Payment/Model/PaymentRequest.php b/src/Sylius/Component/Payment/Model/PaymentRequest.php new file mode 100644 index 0000000000..396fa877e8 --- /dev/null +++ b/src/Sylius/Component/Payment/Model/PaymentRequest.php @@ -0,0 +1,106 @@ +createdAt = new \DateTime(); + } + + public function getId(): ?string + { + return $this->hash; + } + + public function getMethod(): ?PaymentMethodInterface + { + return $this->method; + } + + public function setMethod(?PaymentMethodInterface $method): void + { + $this->method = $method; + } + + public function getPayment(): ?PaymentInterface + { + return $this->payment; + } + + public function setPayment(?PaymentInterface $payment): void + { + $this->payment = $payment; + } + + public function getState(): string + { + return $this->state; + } + + public function setState(string $state): void + { + $this->state = $state; + } + + public function getType(): string + { + return $this->type; + } + + public function setType(string $type): void + { + $this->type = $type; + } + + public function getData(): mixed + { + return $this->data; + } + + public function setData(mixed $data): void + { + $this->data = $data; + } + + public function getDetails(): array + { + return $this->details; + } + + public function setDetails(array $details): void + { + $this->details = $details; + } +} diff --git a/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php new file mode 100644 index 0000000000..398af790fc --- /dev/null +++ b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php @@ -0,0 +1,70 @@ +shouldImplement(PaymentRequestInterface::class); + } + + function it_has_no_hash_by_default(): void + { + $this->getId()->shouldReturn(null); + } + + function it_has_no_payment_method_by_default(): void + { + $this->getMethod()->shouldReturn(null); + } + + function its_payment_method_is_mutable(PaymentMethodInterface $method): void + { + $this->setMethod($method); + $this->getMethod()->shouldReturn($method); + } + + function it_has_no_payment_by_default(): void + { + $this->getPayment()->shouldReturn(null); + } + + function its_payment_is_mutable(PaymentInterface $payment): void + { + $this->setPayment($payment); + $this->getPayment()->shouldReturn($payment); + } + + function it_has_new_state_by_default(): void + { + $this->getState()->shouldReturn(PaymentRequestInterface::STATE_NEW); + } + + function its_state_is_mutable(): void + { + $this->setState('test_state'); + $this->getState()->shouldReturn('test_state'); + } + + function it_has_capture_type_by_default(): void + { + $this->getType()->shouldReturn(PaymentRequestInterface::DATA_TYPE_CAPTURE); + } + + function its_type_is_mutable(): void + { + $this->setType('test_type'); + $this->getType()->shouldReturn('test_type'); + } + + function it_has_null_data_by_default(): void + { + $this->getData()->shouldReturn(null); + } + + function its_data_is_mutable(): void + { + $stdClass = new stdClass(); + $this->setData($stdClass); + $this->getData()->shouldReturn($stdClass); + } + + function it_has_empty_array_details_by_default(): void + { + $this->getDetails()->shouldReturn([]); + } + + function its_details_are_mutable(): void + { + $this->setDetails(['foo', 'bar']); + $this->getDetails()->shouldReturn(['foo', 'bar']); + } + + function it_initializes_creation_date_by_default(): void + { + $this->getCreatedAt()->shouldHaveType('DateTime'); + } + + function its_creation_date_is_mutable(): void + { + $date = new \DateTime('last year'); + + $this->setCreatedAt($date); + $this->getCreatedAt()->shouldReturn($date); + } + + function it_has_no_last_update_date_by_default(): void + { + $this->getUpdatedAt()->shouldReturn(null); + } + + function its_last_update_date_is_mutable(): void + { + $date = new \DateTime('last year'); + + $this->setUpdatedAt($date); + $this->getUpdatedAt()->shouldReturn($date); + } +} diff --git a/symfony.lock b/symfony.lock index 36d0121891..2755d00962 100644 --- a/symfony.lock +++ b/symfony.lock @@ -469,6 +469,15 @@ "ramsey/uuid": { "version": "3.8.0" }, + "ramsey/uuid-doctrine": { + "version": "2.0", + "recipe": { + "repo": "github.com/symfony/recipes-contrib", + "branch": "main", + "version": "1.3", + "ref": "471aed0fbf5620b8d7f92b7a5ebbbf6c0945c27a" + } + }, "rector/rector": { "version": "0.11.52" }, From e9e251f2d5e7f38036093b04ba5dd9b52259a0eb Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 17 Nov 2023 13:03:04 +0100 Subject: [PATCH 002/200] Add API resource --- .../Command/Payment/AddPaymentRequest.php | 30 ++++++++ .../Payment/AddPaymentRequestHandler.php | 28 ++++++++ .../config/api_resources/PaymentRequest.xml | 68 +++++++++++++++++++ .../config/serialization/PaymentMethod.xml | 4 ++ .../config/serialization/PaymentRequest.xml | 56 +++++++++++++++ .../Resources/config/services/filters.xml | 9 +++ 6 files changed, 195 insertions(+) create mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php create mode 100644 src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php new file mode 100644 index 0000000000..82e56b72d4 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php @@ -0,0 +1,30 @@ + + + + + + + sylius + + + DESC + + + + + GET + /admin/payment-requests + + sylius.api.search_payment_request_filter + + + admin:payment_request:read + + + + + POST + /shop/payment-requests + input + Sylius\Bundle\ApiBundle\Command\Payment\AddPaymentRequest + + shop:product_review:create + + + shop:product_review:read + + + + + + + GET + /shop/payment-requests/{hash} + + shop:payment_request:read + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentMethod.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentMethod.xml index 0781097cdf..10e86f6afb 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentMethod.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentMethod.xml @@ -40,6 +40,8 @@ sylius:admin:payment_method:show admin:payment_method:update sylius:admin:payment_method:update + sylius:admin:payment_request:index + sylius:admin:payment_request:show @@ -49,6 +51,8 @@ sylius:shop:payment_method:index shop:payment_method:show sylius:shop:payment_method:show + sylius:shop:payment_request:index + sylius:shop:payment_request:show diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml new file mode 100644 index 0000000000..acd2b6aa94 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml @@ -0,0 +1,56 @@ + + + + + + + + admin:payment_request:read + shop:payment_request:read + + + admin:payment_request:read + shop:payment_request:read + + + admin:payment_request:read + shop:payment_request:read + + + admin:payment_request:read + shop:payment_request:read + + + admin:payment_request:read + shop:payment_request:read + + + admin:payment_request:read + shop:payment_request:read + + + admin:payment_request:read + shop:payment_request:read + + + admin:payment_request:read + shop:payment_request:read + + + admin:payment_request:read + shop:payment_request:read + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml index 5edc5c55d3..20a5546da0 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml @@ -17,6 +17,15 @@ + + + exact + exact + exact + + + + exact From 50c169d076b3ddfbcdfe281b8cf014ffef132153 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 23 Nov 2023 20:00:25 +0100 Subject: [PATCH 003/200] Add first step of a PAYUM Capture request --- .../Command/Payment/Payum/PayumCapture.php | 13 ++++ .../Payment/AddPaymentRequestHandler.php | 50 ++++++++++++- .../Payment/Payum/PayumCaptureHandler.php | 74 +++++++++++++++++++ .../PaymentRequestCommandProviderPass.php | 42 +++++++++++ .../PaymentRequestNotSupportedException.php | 26 +++++++ .../PaymentRequestDuplicationChecker.php | 35 +++++++++ ...mentRequestDuplicationCheckerInterface.php | 12 +++ .../Payment/PaymentRequestCommandProvider.php | 64 ++++++++++++++++ ...PaymentRequestCommandProviderInterface.php | 14 ++++ .../Payment/Payum/PayumApiContext.php | 34 +++++++++ .../Payum/PayumApiContextInterface.php | 22 ++++++ .../Payment/Payum/PayumRequestProcessor.php | 50 +++++++++++++ .../Payum/PayumRequestProcessorInterface.php | 23 ++++++ ...umCapturePaymentRequestCommandProvider.php | 21 ++++++ .../config/services/command_handlers.xml | 11 +++ .../Resources/config/services/payments.xml | 14 ++++ .../config/services/payum/offline.xml | 26 +++++++ .../config/services/payum/paypal.xml | 26 +++++++ .../Resources/config/services/payum/payum.xml | 37 ++++++++++ .../config/services/payum/stripe.xml | 26 +++++++ .../Bundle/ApiBundle/SyliusApiBundle.php | 2 + .../config/app/sylius/sylius_payment.yml | 4 + .../Doctrine/ORM/PaymentRequestRepository.php | 38 ++++++++++ .../Payment/Model/PaymentRequest.php | 5 ++ .../Payment/Model/PaymentRequestInterface.php | 2 + .../PaymentRequestRepositoryInterface.php | 25 +++++++ 26 files changed, 695 insertions(+), 1 deletion(-) create mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapture.php create mode 100644 src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumCaptureHandler.php create mode 100644 src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php create mode 100644 src/Sylius/Bundle/ApiBundle/Exception/PaymentRequestNotSupportedException.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationChecker.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationCheckerInterface.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProvider.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProviderInterface.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContext.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/PayumCapturePaymentRequestCommandProvider.php create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/payum.xml create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml create mode 100644 src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php create mode 100644 src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapture.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapture.php new file mode 100644 index 0000000000..38e653c8b6 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapture.php @@ -0,0 +1,13 @@ +createPaymentRequest($addPaymentRequest); + if (!$this->paymentRequestCommandProvider->supports($paymentRequest)) { + throw new PaymentRequestNotSupportedException(); + } + $command = $this->paymentRequestCommandProvider->handle($paymentRequest); + + $this->commandBus->dispatch($command); + + return $paymentRequest; + } + + private function createPaymentRequest(AddPaymentRequest $addPaymentRequest): PaymentRequestInterface + { + /** @var PaymentMethodInterface|null $paymentMethod */ + $paymentMethod = $this->paymentMethodRepository->findOneBy(['code' => $addPaymentRequest->paymentMethodCode]); + Assert::notNull($paymentMethod); + /** @var PaymentInterface|null $payment */ + $payment = $this->paymentRepository->find($addPaymentRequest->paymentId); + Assert::notNull($payment); + + /** @var PaymentRequestInterface $paymentRequest */ + $paymentRequest = $this->paymentRequestFactory->createNew(); + $paymentRequest->setPayment($payment); + $paymentRequest->setMethod($paymentMethod); + $paymentRequest->setType($addPaymentRequest->type); + $paymentRequest->setData($addPaymentRequest->data); + + $this->paymentRequestManager->persist($paymentRequest); + return $paymentRequest; } } diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumCaptureHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumCaptureHandler.php new file mode 100644 index 0000000000..43c6966c36 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumCaptureHandler.php @@ -0,0 +1,74 @@ +paymentRequestRepository->find($payumCapture->hash); + Assert::notNull($paymentRequest); + + /** @var PaymentMethodInterface|null $paymentMethod */ + $paymentMethod = $paymentRequest->getMethod(); + Assert::notNull($paymentMethod); + + $gatewayConfig = $paymentMethod->getGatewayConfig(); + Assert::notNull($gatewayConfig); + + $gatewayName = $gatewayConfig->getGatewayName(); + + $payment = $paymentRequest->getPayment(); + Assert::notNull($payment); + + /** @var array|null $data */ + $data = $paymentRequest->getData(); + Assert::notNull($data); + + $afterPath = $data['after_path'] ?? null; + Assert::notNull($afterPath); + + $afterPathParameters = $data['after_path_parameters'] ?? []; + + $token = $this->payum->getTokenFactory()->createCaptureToken( + $gatewayName, + $payment, + $afterPath, + $afterPathParameters + ); + + $captureRequest = new Capture($token); + $this->payumReplyProcessor->process($paymentRequest, $captureRequest); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php b/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php new file mode 100644 index 0000000000..908cd8c454 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php @@ -0,0 +1,42 @@ +findTaggedServiceIds('sylius.api.payment_request.command_provider', true) as $serviceId => $tags) { + foreach ($tags as $tag) { + if (!isset($tag['id'])) { + $tag['id'] = $serviceId; + } + + $factoryName = $tag['factory'] ?? null; + Assert::notNull( + $factoryName, + sprintf('The tag "%s" must have a "factory" attribut.', 'sylius.api.payment_request.command_provider') + ); + + $type = $tag['type'] ?? null; + Assert::notNull( + $type, + sprintf('The tag "%s" must have a "type" attribut.', 'sylius.api.payment_request.command_provider') + ); + + $commandProviders[sprintf('%s::%s', $factoryName, $type)] = new Reference($serviceId); + } + } + + $container->getDefinition('sylius.api.payment_request.command_provider.locator')->addArgument($commandProviders); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Exception/PaymentRequestNotSupportedException.php b/src/Sylius/Bundle/ApiBundle/Exception/PaymentRequestNotSupportedException.php new file mode 100644 index 0000000000..bf31ca989b --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Exception/PaymentRequestNotSupportedException.php @@ -0,0 +1,26 @@ +getPayment(); + Assert::notNull($payment); + + $paymentMethod = $paymentRequest->getMethod(); + Assert::notNull($paymentMethod); + + $paymentRequests = $this->paymentRequestRepository->findExisting( + $payment, + $paymentMethod, + $paymentRequest->getType() + ); + + return count($paymentRequests) > 0; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationCheckerInterface.php b/src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationCheckerInterface.php new file mode 100644 index 0000000000..78526585bb --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationCheckerInterface.php @@ -0,0 +1,12 @@ +paymentRequestDuplicationChecker->hasDuplicates($paymentRequest); + + if ($hasDuplicates) { + return false; + } + + return $this->getCommandProvider($paymentRequest)->supports($paymentRequest); + } + + public function handle(PaymentRequestInterface $paymentRequest): object + { + return $this->getCommandProvider($paymentRequest)->handle($paymentRequest); + } + + protected function getCommandProvider(PaymentRequestInterface $paymentRequest): PaymentRequestCommandProviderInterface + { + /** @var PaymentMethodInterface|null $paymentMethod */ + $paymentMethod = $paymentRequest->getMethod(); + Assert::notNull($paymentMethod); + + $gatewayConfig = $paymentMethod->getGatewayConfig(); + Assert::notNull($gatewayConfig); + /** @var PaymentRequestCommandProviderInterface $service */ + $factoryName = $gatewayConfig->getConfig()['factory'] ?? $gatewayConfig->getFactoryName(); + + $id = sprintf('%s::%s', $factoryName, $paymentRequest->getType()); + + /** @var PaymentRequestCommandProviderInterface $provider */ + $provider = $this->paymentRequestCommandProviderLocator->get($id); + + return $provider; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProviderInterface.php b/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProviderInterface.php new file mode 100644 index 0000000000..a6927abd74 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProviderInterface.php @@ -0,0 +1,14 @@ +enabled; + } + + public function enable(): void + { + $this->enabled = true; + } + + public function disable(): void + { + $this->enabled = false; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php new file mode 100644 index 0000000000..5ea74e5bde --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php @@ -0,0 +1,22 @@ +getToken(); + Assert::notNull($token); + + $gateway = $this->payum->getGateway($token->getGatewayName()); + + $this->payumApiContext->enable(); + $reply = $gateway->execute($request, true); + $this->payumApiContext->disable(); + + $payment = $paymentRequest->getPayment(); + Assert::notNull($payment); + + $details = $paymentRequest->getDetails(); + if (null === $reply) { + $details['after_url'] = $token->getAfterUrl(); + } + + $payment->setDetails($details); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php new file mode 100644 index 0000000000..e339e5e9e1 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php @@ -0,0 +1,23 @@ +getType() === PaymentRequestInterface::DATA_TYPE_CAPTURE; + } + + public function handle(PaymentRequestInterface $paymentRequest): object + { + return new PayumCapture($paymentRequest->getHash()); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml index af075d3b35..50c031418d 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml @@ -238,5 +238,16 @@ + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml index 95b4fb5172..989e9a1052 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml @@ -22,5 +22,19 @@ + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml new file mode 100644 index 0000000000..6c12bb4eee --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml new file mode 100644 index 0000000000..5293dc25e6 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/payum.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/payum.xml new file mode 100644 index 0000000000..044b3cc0dd --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/payum.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml new file mode 100644 index 0000000000..8608439fb9 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/SyliusApiBundle.php b/src/Sylius/Bundle/ApiBundle/SyliusApiBundle.php index f74852f938..50bb0ca71a 100644 --- a/src/Sylius/Bundle/ApiBundle/SyliusApiBundle.php +++ b/src/Sylius/Bundle/ApiBundle/SyliusApiBundle.php @@ -17,6 +17,7 @@ use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\CommandDataTransformerP use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\ExtractorMergingCompilerPass; use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\FlattenExceptionNormalizerDecoratorCompilerPass; use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\LegacyErrorHandlingCompilerPass; +use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\PaymentRequestCommandProviderPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -27,6 +28,7 @@ final class SyliusApiBundle extends Bundle $container->addCompilerPass(new CommandDataTransformerPass()); $container->addCompilerPass(new FlattenExceptionNormalizerDecoratorCompilerPass()); $container->addCompilerPass(new LegacyErrorHandlingCompilerPass()); + $container->addCompilerPass(new PaymentRequestCommandProviderPass()); $container->addCompilerPass(new ExtractorMergingCompilerPass()); } } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius/sylius_payment.yml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius/sylius_payment.yml index 2f3f553141..06bd27ea5f 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius/sylius_payment.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius/sylius_payment.yml @@ -12,3 +12,7 @@ sylius_payment: model: Sylius\Component\Core\Model\PaymentMethod repository: Sylius\Bundle\CoreBundle\Doctrine\ORM\PaymentMethodRepository controller: Sylius\Bundle\CoreBundle\Controller\PaymentMethodController + payment_request: + classes: + model: Sylius\Component\Payment\Model\PaymentRequest + repository: Sylius\Bundle\PaymentBundle\Doctrine\ORM\PaymentRequestRepository diff --git a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php new file mode 100644 index 0000000000..cde996394a --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php @@ -0,0 +1,38 @@ +createQueryBuilder('o') + ->innerJoin('o.payment', 'payment') + ->innerJoin('o.method', 'method') + ->andWhere('o.type = :type') + ->andWhere('o.payment = :payment') + ->andWhere('o.method = :method') + ->setParameter('type', $type) + ->setParameter('method', $paymentMethod) + ->setParameter('payment', $payment) + ->getQuery() + ->getResult() + ; + } +} diff --git a/src/Sylius/Component/Payment/Model/PaymentRequest.php b/src/Sylius/Component/Payment/Model/PaymentRequest.php index 396fa877e8..bf3650c854 100644 --- a/src/Sylius/Component/Payment/Model/PaymentRequest.php +++ b/src/Sylius/Component/Payment/Model/PaymentRequest.php @@ -40,6 +40,11 @@ class PaymentRequest implements PaymentRequestInterface } public function getId(): ?string + { + return $this->getHash(); + } + + public function getHash(): ?string { return $this->hash; } diff --git a/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php index 398af790fc..a844a531af 100644 --- a/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php +++ b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php @@ -38,6 +38,8 @@ interface PaymentRequestInterface extends TimestampableInterface, ResourceInterf public const DATA_TYPE_PAYOUT = 'payout'; + public function getHash(): ?string; + public function getMethod(): ?PaymentMethodInterface; public function setMethod(?PaymentMethodInterface $method): void; diff --git a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php new file mode 100644 index 0000000000..98797e75c1 --- /dev/null +++ b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php @@ -0,0 +1,25 @@ + Date: Wed, 20 Dec 2023 17:28:37 +0100 Subject: [PATCH 004/200] Finalise Payum POC and 1st try with no Payum using Offline payment method --- ...aymentStateMachineTransitionApplicator.php | 7 ++ ...teMachineTransitionApplicatorInterface.php | 2 + .../Payment/Offline/CapturePaymentRequest.php | 34 +++++++++ .../Payment/Offline/StatusPaymentRequest.php | 34 +++++++++ .../Command/Payment/Payum/PayumCapture.php | 13 ---- .../Payum/PayumCapturePaymentRequest.php | 20 +++++ .../Payum/PayumStatusPaymentRequest.php | 20 +++++ .../PaymentRequestHashAwareInterface.php | 22 ++++++ .../Offline/CapturePaymentRequestHandler.php | 66 +++++++++++++++++ .../Payment/Payum/PayumCaptureHandler.php | 74 ------------------- .../Payum/PayumPaymentRequestHandler.php | 48 ++++++++++++ .../CapturePaymentRequestCommandProvider.php | 31 ++++++++ .../PaymentRequestToDetailsConverter.php | 35 +++++++++ ...mentRequestToDetailsConverterInterface.php | 21 ++++++ .../StatusPaymentRequestCommandProvider.php | 31 ++++++++ .../Payment/PaymentRequestCommandProvider.php | 3 +- .../Action/SyliusApiGetHttpRequestAction.php | 61 +++++++++++++++ .../Action/SyliusApiRenderTemplateAction.php | 46 ++++++++++++ .../Payment/Payum/PayumApiContext.php | 17 +++-- .../Payum/PayumApiContextInterface.php | 7 +- ...umCapturePaymentRequestCommandProvider.php | 7 +- .../Payment/Payum/PayumRequestProcessor.php | 2 +- .../Payum/PayumRequestProcessorInterface.php | 1 - ...yumStatusPaymentRequestCommandProvider.php | 22 ++++++ .../Payment/Payum/PayumTokenFactory.php | 66 +++++++++++++++++ .../Payum/PayumTokenFactoryInterface.php | 22 ++++++ .../config/services/command_handlers.xml | 2 +- .../payum.xml => payment_request/offline.xml} | 17 ++--- .../Resources/config/services/payments.xml | 6 +- .../Resources/config/services/payum/all.xml | 67 +++++++++++++++++ .../config/services/payum/offline.xml | 8 +- .../config/services/payum/paypal.xml | 6 +- .../config/services/payum/stripe.xml | 6 +- ...ntStateMachineTransitionApplicatorSpec.php | 11 +++ 34 files changed, 719 insertions(+), 116 deletions(-) create mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/CapturePaymentRequest.php create mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/StatusPaymentRequest.php delete mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapture.php create mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapturePaymentRequest.php create mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumStatusPaymentRequest.php create mode 100644 src/Sylius/Bundle/ApiBundle/Command/PaymentRequestHashAwareInterface.php create mode 100644 src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php delete mode 100644 src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumCaptureHandler.php create mode 100644 src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumPaymentRequestHandler.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestCommandProvider.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverter.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverterInterface.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Offline/StatusPaymentRequestCommandProvider.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php rename src/Sylius/Bundle/ApiBundle/Payment/{ => Payum}/PayumCapturePaymentRequestCommandProvider.php (62%) create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumStatusPaymentRequestCommandProvider.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php create mode 100644 src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactoryInterface.php rename src/Sylius/Bundle/ApiBundle/Resources/config/services/{payum/payum.xml => payment_request/offline.xml} (52%) create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/all.xml diff --git a/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicator.php b/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicator.php index ccbe66f3f9..b40c357097 100644 --- a/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicator.php +++ b/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicator.php @@ -44,6 +44,13 @@ final class PaymentStateMachineTransitionApplicator implements PaymentStateMachi return $data; } + public function process(PaymentInterface $data): PaymentInterface + { + $this->applyTransition($data, PaymentTransitions::TRANSITION_PROCESS); + + return $data; + } + private function applyTransition(PaymentInterface $payment, string $transition): void { $stateMachine = $this->getStateMachine(); diff --git a/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicatorInterface.php b/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicatorInterface.php index 4193a7f7f4..aa794e7fc7 100644 --- a/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicatorInterface.php +++ b/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicatorInterface.php @@ -18,4 +18,6 @@ use Sylius\Component\Payment\Model\PaymentInterface; interface PaymentStateMachineTransitionApplicatorInterface { public function complete(PaymentInterface $data): PaymentInterface; + + public function process(PaymentInterface $data): PaymentInterface; } diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/CapturePaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/CapturePaymentRequest.php new file mode 100644 index 0000000000..5b1b3c3ee6 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/CapturePaymentRequest.php @@ -0,0 +1,34 @@ +hash; + } + + public function setHash(string $hash): void + { + $this->hash = $hash; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/StatusPaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/StatusPaymentRequest.php new file mode 100644 index 0000000000..f014a9fed4 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/StatusPaymentRequest.php @@ -0,0 +1,34 @@ +hash; + } + + public function setHash(string $hash): void + { + $this->hash = $hash; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapture.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapture.php deleted file mode 100644 index 38e653c8b6..0000000000 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapture.php +++ /dev/null @@ -1,13 +0,0 @@ -paymentRequestRepository->find($capturePaymentRequest->getHash()); + Assert::notNull($paymentRequest); + + /** @var PaymentMethodInterface|null $paymentMethod */ + $paymentMethod = $paymentRequest->getMethod(); + Assert::notNull($paymentMethod); + + $gatewayConfig = $paymentMethod->getGatewayConfig(); + Assert::notNull($gatewayConfig); + $factoryName = $gatewayConfig->getConfig()['factory'] ?? $gatewayConfig->getFactoryName(); + Assert::eq($factoryName, self::FACTORY_NAME, 'Expected a factory name equal to %2$s. Got: %s'); + + $payment = $paymentRequest->getPayment(); + Assert::notNull($payment); + + $details = $this->paymentRequestToDetailsConverter->convert($paymentRequest); + $paymentRequest->setDetails($details); + + if ($paymentRequest->getDetails()['paid']) { + $this->paymentStateMachineTransitionApplicator->complete($payment); + } else { + $this->paymentStateMachineTransitionApplicator->process($payment); + } + + $payment->setDetails($paymentRequest->getDetails()); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumCaptureHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumCaptureHandler.php deleted file mode 100644 index 43c6966c36..0000000000 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumCaptureHandler.php +++ /dev/null @@ -1,74 +0,0 @@ -paymentRequestRepository->find($payumCapture->hash); - Assert::notNull($paymentRequest); - - /** @var PaymentMethodInterface|null $paymentMethod */ - $paymentMethod = $paymentRequest->getMethod(); - Assert::notNull($paymentMethod); - - $gatewayConfig = $paymentMethod->getGatewayConfig(); - Assert::notNull($gatewayConfig); - - $gatewayName = $gatewayConfig->getGatewayName(); - - $payment = $paymentRequest->getPayment(); - Assert::notNull($payment); - - /** @var array|null $data */ - $data = $paymentRequest->getData(); - Assert::notNull($data); - - $afterPath = $data['after_path'] ?? null; - Assert::notNull($afterPath); - - $afterPathParameters = $data['after_path_parameters'] ?? []; - - $token = $this->payum->getTokenFactory()->createCaptureToken( - $gatewayName, - $payment, - $afterPath, - $afterPathParameters - ); - - $captureRequest = new Capture($token); - $this->payumReplyProcessor->process($paymentRequest, $captureRequest); - } -} diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumPaymentRequestHandler.php new file mode 100644 index 0000000000..90a94cdc94 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumPaymentRequestHandler.php @@ -0,0 +1,48 @@ + */ + private string $payumRequestClass, + ) { + } + + public function __invoke(PaymentRequestHashAwareInterface $payumRequest): void + { + /** @var PaymentRequestInterface|null $paymentRequest */ + $paymentRequest = $this->paymentRequestRepository->find($payumRequest->getHash()); + Assert::notNull($paymentRequest); + + $token = $this->payumTokenFactory->createNew($paymentRequest); + + $captureRequest = new $this->payumRequestClass($token); + $this->payumReplyProcessor->process($paymentRequest, $captureRequest); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestCommandProvider.php b/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestCommandProvider.php new file mode 100644 index 0000000000..28cd3d83fe --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestCommandProvider.php @@ -0,0 +1,31 @@ +getType() === PaymentRequestInterface::DATA_TYPE_CAPTURE; + } + + public function handle(PaymentRequestInterface $paymentRequest): object + { + return new CapturePaymentRequest($paymentRequest->getHash()); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverter.php b/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverter.php new file mode 100644 index 0000000000..a3f6dbb404 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverter.php @@ -0,0 +1,35 @@ +getPayment(); + Assert::notNull($payment); + + if (PaymentInterface::STATE_NEW === $payment->getState()) { + return [ + 'paid' => false, + ]; + } + + return $payment->getDetails(); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverterInterface.php b/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverterInterface.php new file mode 100644 index 0000000000..05c79d89ad --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverterInterface.php @@ -0,0 +1,21 @@ +getType() === PaymentRequestInterface::DATA_TYPE_CAPTURE; + } + + public function handle(PaymentRequestInterface $paymentRequest): object + { + return new StatusPaymentRequest($paymentRequest->getHash()); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProvider.php b/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProvider.php index cc3ff4c4d8..1a08a39887 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProvider.php @@ -43,7 +43,7 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid return $this->getCommandProvider($paymentRequest)->handle($paymentRequest); } - protected function getCommandProvider(PaymentRequestInterface $paymentRequest): PaymentRequestCommandProviderInterface + private function getCommandProvider(PaymentRequestInterface $paymentRequest): PaymentRequestCommandProviderInterface { /** @var PaymentMethodInterface|null $paymentMethod */ $paymentMethod = $paymentRequest->getMethod(); @@ -54,6 +54,7 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid /** @var PaymentRequestCommandProviderInterface $service */ $factoryName = $gatewayConfig->getConfig()['factory'] ?? $gatewayConfig->getFactoryName(); + /** @todo consider founding better nested service provider */ $id = sprintf('%s::%s', $factoryName, $paymentRequest->getType()); /** @var PaymentRequestCommandProviderInterface $provider */ diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php new file mode 100644 index 0000000000..95dd3c5686 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php @@ -0,0 +1,61 @@ +updateRequest($request); + } + + private function updateRequest(GetHttpRequest $request): void + { + $paymentRequest = $this->payumApiContext->getPaymentRequest(); + Assert::notNull($paymentRequest); + + /** @var array $details */ + $details = $paymentRequest->getData(); + $httpRequest = $details['http_request'] ?? []; + + $request->query = $httpRequest['query']; + $request->request = $httpRequest['request']; + // Not existing property + //$request->headers = $httpRequest['headers']; + $request->method = $httpRequest['method'] ?? 'POST'; + $request->uri = $httpRequest['uri'] ?? ''; + $request->clientIp = $httpRequest['client_ip'] ?? ''; + $request->userAgent = $httpRequest['user_agent']; + $request->content = $httpRequest['content']; + } + + public function supports($request): bool + { + return $this->payumApiContext->isEnabled() && $request instanceof GetHttpRequest; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php new file mode 100644 index 0000000000..e020cb6c6a --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php @@ -0,0 +1,46 @@ +payumApiContext->getPaymentRequest(); + Assert::notNull($paymentRequest); + + $details = $paymentRequest->getDetails(); + $paymentRequest->setDetails(array_merge($details, $request->getParameters())); + + $request->setResult(''); + } + + public function supports($request): bool + { + return $this->payumApiContext->isEnabled() && $request instanceof RenderTemplate; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContext.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContext.php index 7f8c0597ed..78b64453a3 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContext.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContext.php @@ -13,22 +13,29 @@ declare(strict_types=1); namespace Sylius\Bundle\ApiBundle\Payment\Payum; +use Sylius\Component\Payment\Model\PaymentRequestInterface; + final class PayumApiContext implements PayumApiContextInterface { - private bool $enabled = false; + private ?PaymentRequestInterface $paymentRequest = null; public function isEnabled(): bool { - return $this->enabled; + return null !== $this->paymentRequest; } - public function enable(): void + public function enable(PaymentRequestInterface $paymentRequest): void { - $this->enabled = true; + $this->paymentRequest = $paymentRequest; + } + + public function getPaymentRequest(): ?PaymentRequestInterface + { + return $this->paymentRequest; } public function disable(): void { - $this->enabled = false; + $this->paymentRequest = null; } } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php index 5ea74e5bde..4278d8d186 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php @@ -13,10 +13,15 @@ declare(strict_types=1); namespace Sylius\Bundle\ApiBundle\Payment\Payum; +use Sylius\Component\Payment\Model\PaymentRequestInterface; + interface PayumApiContextInterface { public function isEnabled(): bool; - public function enable(): void; + public function enable(PaymentRequestInterface $paymentRequest): void; + public function disable(): void; + + public function getPaymentRequest(): ?PaymentRequestInterface; } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/PayumCapturePaymentRequestCommandProvider.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumCapturePaymentRequestCommandProvider.php similarity index 62% rename from src/Sylius/Bundle/ApiBundle/Payment/PayumCapturePaymentRequestCommandProvider.php rename to src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumCapturePaymentRequestCommandProvider.php index 71e5e24b9a..0fc941be20 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/PayumCapturePaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumCapturePaymentRequestCommandProvider.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment; +namespace Sylius\Bundle\ApiBundle\Payment\Payum; -use Sylius\Bundle\ApiBundle\Command\Payment\Payum\PayumCapture; +use Sylius\Bundle\ApiBundle\Command\Payment\Payum\PayumCapturePaymentRequest; +use Sylius\Bundle\ApiBundle\Payment\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class PayumCapturePaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface @@ -16,6 +17,6 @@ final class PayumCapturePaymentRequestCommandProvider implements PaymentRequestC public function handle(PaymentRequestInterface $paymentRequest): object { - return new PayumCapture($paymentRequest->getHash()); + return new PayumCapturePaymentRequest($paymentRequest->getHash()); } } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php index 302320be83..38d587719a 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php @@ -33,7 +33,7 @@ final class PayumRequestProcessor implements PayumRequestProcessorInterface $gateway = $this->payum->getGateway($token->getGatewayName()); - $this->payumApiContext->enable(); + $this->payumApiContext->enable($paymentRequest); $reply = $gateway->execute($request, true); $this->payumApiContext->disable(); diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php index e339e5e9e1..81a9c0cbed 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php @@ -18,6 +18,5 @@ use Sylius\Component\Payment\Model\PaymentRequestInterface; interface PayumRequestProcessorInterface { - public function process( PaymentRequestInterface $paymentRequest, TokenAggregateInterface $request): void; } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumStatusPaymentRequestCommandProvider.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumStatusPaymentRequestCommandProvider.php new file mode 100644 index 0000000000..34234e5fd1 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumStatusPaymentRequestCommandProvider.php @@ -0,0 +1,22 @@ +getType() === PaymentRequestInterface::DATA_TYPE_STATUS; + } + + public function handle(PaymentRequestInterface $paymentRequest): object + { + return new PayumStatusPaymentRequest($paymentRequest->getHash()); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php new file mode 100644 index 0000000000..db99538daa --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php @@ -0,0 +1,66 @@ +getPayment(); + Assert::notNull($payment); + + /** @var PaymentMethodInterface|null $paymentMethod */ + $paymentMethod = $paymentRequest->getMethod(); + Assert::notNull($paymentMethod); + + $gatewayConfig = $paymentMethod->getGatewayConfig(); + Assert::notNull($gatewayConfig); + + $gatewayName = $gatewayConfig->getGatewayName(); + + /** @var array|null $data */ + $data = $paymentRequest->getData(); + Assert::notNull($data); + + $targetPath = $data['target_path'] ?? null; + Assert::notNull($targetPath); + + $targetPathParameters = $data['target_path_parameters'] ?? []; + + $afterPath = $data['after_path'] ?? null; + Assert::notNull($afterPath); + + $afterPathParameters = $data['after_path_parameters'] ?? []; + + return $this->payum->getTokenFactory()->createToken( + $gatewayName, + $payment, + $targetPath, + $targetPathParameters, + $afterPath, + $afterPathParameters, + ); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactoryInterface.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactoryInterface.php new file mode 100644 index 0000000000..ea6462dcb1 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactoryInterface.php @@ -0,0 +1,22 @@ + - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/payum.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request/offline.xml similarity index 52% rename from src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/payum.xml rename to src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request/offline.xml index 044b3cc0dd..7c530d81ef 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/payum.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request/offline.xml @@ -18,20 +18,19 @@ - + + + + + - - + + - - - - - - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml index 989e9a1052..377da87e5f 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml @@ -27,12 +27,12 @@ - + - - + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/all.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/all.xml new file mode 100644 index 0000000000..42c657ac64 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/all.xml @@ -0,0 +1,67 @@ + + + + + + + Payum\Core\Request\Capture + Sylius\Bundle\PayumBundle\Request\GetStatus + + + + + + + + + + + + + + + + + + %sylius_api.payment_request.payum.capture.class% + + + + + + + + + %sylius_api.payment_request.payum.status.class% + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml index 6c12bb4eee..4f5b8fc87a 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml @@ -18,8 +18,12 @@ - - + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml index 5293dc25e6..4b8a93dd56 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml @@ -18,9 +18,13 @@ - + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml index 8608439fb9..6fae63e2e2 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml @@ -18,9 +18,13 @@ - + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/spec/Applicator/PaymentStateMachineTransitionApplicatorSpec.php b/src/Sylius/Bundle/ApiBundle/spec/Applicator/PaymentStateMachineTransitionApplicatorSpec.php index 3b568d505b..17697f8551 100644 --- a/src/Sylius/Bundle/ApiBundle/spec/Applicator/PaymentStateMachineTransitionApplicatorSpec.php +++ b/src/Sylius/Bundle/ApiBundle/spec/Applicator/PaymentStateMachineTransitionApplicatorSpec.php @@ -40,6 +40,17 @@ final class PaymentStateMachineTransitionApplicatorSpec extends ObjectBehavior $this->complete($payment); } + function it_process_payment( + StateMachineFactoryInterface $stateMachineFactory, + PaymentInterface $payment, + WinzouStateMachine $stateMachine, + ): void { + $stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->willReturn($stateMachine); + $stateMachine->apply(PaymentTransitions::TRANSITION_PROCESS)->shouldBeCalled(); + + $this->process($payment); + } + function it_throws_exception_if_cannot_complete_payment( StateMachineFactoryInterface $stateMachineFactory, PaymentInterface $payment, From 73cd74d55b219a840efa0e98d02950d5e9709c9a Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 21 Dec 2023 11:16:03 +0100 Subject: [PATCH 005/200] Rename data to payload --- .../Payment/AddPaymentRequestHandler.php | 2 +- .../Payment/Offline/CapturePaymentRequestHandler.php | 3 +-- .../Payum/Action/SyliusApiGetHttpRequestAction.php | 2 +- .../ApiBundle/Payment/Payum/PayumTokenFactory.php | 2 +- .../Resources/config/api_resources/PaymentRequest.xml | 2 +- .../Resources/config/serialization/PaymentRequest.xml | 2 +- .../config/doctrine/model/PaymentRequest.orm.xml | 2 +- src/Sylius/Component/Payment/Model/PaymentRequest.php | 11 +++++------ .../Payment/Model/PaymentRequestInterface.php | 10 ++-------- .../Payment/spec/Model/PaymentRequestSpec.php | 6 +++--- 10 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index d3448fe23f..3ec500243c 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -68,7 +68,7 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface $paymentRequest->setPayment($payment); $paymentRequest->setMethod($paymentMethod); $paymentRequest->setType($addPaymentRequest->type); - $paymentRequest->setData($addPaymentRequest->data); + $paymentRequest->setPayload($addPaymentRequest->data); $this->paymentRequestManager->persist($paymentRequest); return $paymentRequest; diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php index 5360bc8258..771c08ae4d 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php @@ -54,13 +54,12 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface $details = $this->paymentRequestToDetailsConverter->convert($paymentRequest); $paymentRequest->setDetails($details); + $payment->setDetails($details); if ($paymentRequest->getDetails()['paid']) { $this->paymentStateMachineTransitionApplicator->complete($payment); } else { $this->paymentStateMachineTransitionApplicator->process($payment); } - - $payment->setDetails($paymentRequest->getDetails()); } } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php index 95dd3c5686..0e7c456278 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php @@ -40,7 +40,7 @@ final class SyliusApiGetHttpRequestAction implements ActionInterface Assert::notNull($paymentRequest); /** @var array $details */ - $details = $paymentRequest->getData(); + $details = $paymentRequest->getPayload(); $httpRequest = $details['http_request'] ?? []; $request->query = $httpRequest['query']; diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php index db99538daa..24c920cc4b 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php @@ -41,7 +41,7 @@ final class PayumTokenFactory implements PayumTokenFactoryInterface $gatewayName = $gatewayConfig->getGatewayName(); /** @var array|null $data */ - $data = $paymentRequest->getData(); + $data = $paymentRequest->getPayload(); Assert::notNull($data); $targetPath = $data['target_path'] ?? null; diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml index d70cdbb062..c809834789 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml @@ -62,7 +62,7 @@ - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml index acd2b6aa94..8c64fcea8b 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml @@ -36,7 +36,7 @@ admin:payment_request:read shop:payment_request:read - + admin:payment_request:read shop:payment_request:read diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml index 992e2712ba..bfbbc5334f 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml @@ -30,7 +30,7 @@ - + diff --git a/src/Sylius/Component/Payment/Model/PaymentRequest.php b/src/Sylius/Component/Payment/Model/PaymentRequest.php index bf3650c854..a2ab136053 100644 --- a/src/Sylius/Component/Payment/Model/PaymentRequest.php +++ b/src/Sylius/Component/Payment/Model/PaymentRequest.php @@ -29,9 +29,8 @@ class PaymentRequest implements PaymentRequestInterface protected string $type = PaymentRequestInterface::DATA_TYPE_CAPTURE; - protected mixed $data = null; + protected mixed $payload = null; - /** @var mixed[] */ protected array $details = []; public function __construct() @@ -89,14 +88,14 @@ class PaymentRequest implements PaymentRequestInterface $this->type = $type; } - public function getData(): mixed + public function getPayload(): mixed { - return $this->data; + return $this->payload; } - public function setData(mixed $data): void + public function setPayload(mixed $payload): void { - $this->data = $data; + $this->payload = $payload; } public function getDetails(): array diff --git a/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php index a844a531af..7029b44765 100644 --- a/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php +++ b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php @@ -56,17 +56,11 @@ interface PaymentRequestInterface extends TimestampableInterface, ResourceInterf public function setType(string $type): void; - public function getData(): mixed; + public function getPayload(): mixed; - public function setData(mixed $data): void; + public function setPayload(mixed $payload): void; - /** - * @return mixed[] - */ public function getDetails(): array; - /** - * @param mixed[] $details - */ public function setDetails(array $details): void; } diff --git a/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php b/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php index ad15f1bd31..edefb33ae5 100644 --- a/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php +++ b/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php @@ -77,14 +77,14 @@ final class PaymentRequestSpec extends ObjectBehavior function it_has_null_data_by_default(): void { - $this->getData()->shouldReturn(null); + $this->getPayload()->shouldReturn(null); } function its_data_is_mutable(): void { $stdClass = new stdClass(); - $this->setData($stdClass); - $this->getData()->shouldReturn($stdClass); + $this->setPayload($stdClass); + $this->getPayload()->shouldReturn($stdClass); } function it_has_empty_array_details_by_default(): void From ff3e8e0ce197d5ce7d24f2d4a9ce80f7e26f4e1f Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 21 Dec 2023 15:07:28 +0100 Subject: [PATCH 006/200] Rename input/output data to requestPayload/responseData --- .../Payment/AddPaymentRequestHandler.php | 2 +- .../Offline/CapturePaymentRequestHandler.php | 6 +++--- .../PaymentRequestCommandProviderPass.php | 5 ++++- .../Action/SyliusApiGetHttpRequestAction.php | 4 ++-- .../Action/SyliusApiRenderTemplateAction.php | 4 ++-- .../Payment/Payum/PayumRequestProcessor.php | 3 --- .../Payment/Payum/PayumTokenFactory.php | 2 +- .../config/api_resources/PaymentRequest.xml | 4 ++-- .../config/serialization/PaymentRequest.xml | 4 ++-- .../doctrine/model/PaymentRequest.orm.xml | 4 ++-- .../Payment/Model/PaymentRequest.php | 20 +++++++++---------- .../Payment/Model/PaymentRequestInterface.php | 10 ++++++---- .../Payment/spec/Model/PaymentRequestSpec.php | 12 +++++------ 13 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index 3ec500243c..9602e61073 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -68,7 +68,7 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface $paymentRequest->setPayment($payment); $paymentRequest->setMethod($paymentMethod); $paymentRequest->setType($addPaymentRequest->type); - $paymentRequest->setPayload($addPaymentRequest->data); + $paymentRequest->setRequestPayload($addPaymentRequest->data); $this->paymentRequestManager->persist($paymentRequest); return $paymentRequest; diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php index 771c08ae4d..889cced3b9 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php @@ -53,10 +53,10 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface Assert::notNull($payment); $details = $this->paymentRequestToDetailsConverter->convert($paymentRequest); - $paymentRequest->setDetails($details); - $payment->setDetails($details); + $paymentRequest->setResponseData($details); + // @todo modify Payment->getDetails() to retrieve last payment request `responseData` - if ($paymentRequest->getDetails()['paid']) { + if ($details['paid']) { $this->paymentStateMachineTransitionApplicator->complete($payment); } else { $this->paymentStateMachineTransitionApplicator->process($payment); diff --git a/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php b/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php index 908cd8c454..2f1a078b45 100644 --- a/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php +++ b/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php @@ -34,7 +34,10 @@ final class PaymentRequestCommandProviderPass implements CompilerPassInterface ); $commandProviders[sprintf('%s::%s', $factoryName, $type)] = new Reference($serviceId); - } + }// offline::capture, + // stripe::capture + // stripe::status + // stripe::refund } $container->getDefinition('sylius.api.payment_request.command_provider.locator')->addArgument($commandProviders); diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php index 0e7c456278..09ffe68d69 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php @@ -40,13 +40,13 @@ final class SyliusApiGetHttpRequestAction implements ActionInterface Assert::notNull($paymentRequest); /** @var array $details */ - $details = $paymentRequest->getPayload(); + $details = $paymentRequest->getRequestPayload(); $httpRequest = $details['http_request'] ?? []; $request->query = $httpRequest['query']; $request->request = $httpRequest['request']; // Not existing property - //$request->headers = $httpRequest['headers']; + $request->headers = $httpRequest['headers']; $request->method = $httpRequest['method'] ?? 'POST'; $request->uri = $httpRequest['uri'] ?? ''; $request->clientIp = $httpRequest['client_ip'] ?? ''; diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php index e020cb6c6a..0c7641d74e 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php @@ -33,8 +33,8 @@ final class SyliusApiRenderTemplateAction implements ActionInterface $paymentRequest = $this->payumApiContext->getPaymentRequest(); Assert::notNull($paymentRequest); - $details = $paymentRequest->getDetails(); - $paymentRequest->setDetails(array_merge($details, $request->getParameters())); + $details = $paymentRequest->getResponseData(); + $paymentRequest->setResponseData(array_merge($details, $request->getParameters())); $request->setResult(''); } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php index 38d587719a..1abc713afb 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php @@ -40,11 +40,8 @@ final class PayumRequestProcessor implements PayumRequestProcessorInterface $payment = $paymentRequest->getPayment(); Assert::notNull($payment); - $details = $paymentRequest->getDetails(); if (null === $reply) { $details['after_url'] = $token->getAfterUrl(); } - - $payment->setDetails($details); } } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php index 24c920cc4b..833d254770 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php @@ -41,7 +41,7 @@ final class PayumTokenFactory implements PayumTokenFactoryInterface $gatewayName = $gatewayConfig->getGatewayName(); /** @var array|null $data */ - $data = $paymentRequest->getPayload(); + $data = $paymentRequest->getRequestPayload(); Assert::notNull($data); $targetPath = $data['target_path'] ?? null; diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml index c809834789..9b05ee9b12 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml @@ -62,7 +62,7 @@ - - + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml index 8c64fcea8b..dd280a5e69 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml @@ -36,11 +36,11 @@ admin:payment_request:read shop:payment_request:read - + admin:payment_request:read shop:payment_request:read - + admin:payment_request:read shop:payment_request:read diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml index bfbbc5334f..34ea8cbf19 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml @@ -30,8 +30,8 @@ - - + + diff --git a/src/Sylius/Component/Payment/Model/PaymentRequest.php b/src/Sylius/Component/Payment/Model/PaymentRequest.php index a2ab136053..2880153b3f 100644 --- a/src/Sylius/Component/Payment/Model/PaymentRequest.php +++ b/src/Sylius/Component/Payment/Model/PaymentRequest.php @@ -29,9 +29,9 @@ class PaymentRequest implements PaymentRequestInterface protected string $type = PaymentRequestInterface::DATA_TYPE_CAPTURE; - protected mixed $payload = null; + protected mixed $requestPayload = null; - protected array $details = []; + protected array $responseData = []; public function __construct() { @@ -88,23 +88,23 @@ class PaymentRequest implements PaymentRequestInterface $this->type = $type; } - public function getPayload(): mixed + public function getRequestPayload(): mixed { - return $this->payload; + return $this->requestPayload; } - public function setPayload(mixed $payload): void + public function setRequestPayload(mixed $requestPayload): void { - $this->payload = $payload; + $this->requestPayload = $requestPayload; } - public function getDetails(): array + public function getResponseData(): array { - return $this->details; + return $this->responseData; } - public function setDetails(array $details): void + public function setResponseData(array $responseData): void { - $this->details = $details; + $this->responseData = $responseData; } } diff --git a/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php index 7029b44765..554d488f94 100644 --- a/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php +++ b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php @@ -32,6 +32,8 @@ interface PaymentRequestInterface extends TimestampableInterface, ResourceInterf public const DATA_TYPE_AUTHORIZE = 'authorize'; + public const DATA_TYPE_REFUND = 'refund'; + public const DATA_TYPE_STATUS = 'status'; public const DATA_TYPE_SYNC = 'sync'; @@ -56,11 +58,11 @@ interface PaymentRequestInterface extends TimestampableInterface, ResourceInterf public function setType(string $type): void; - public function getPayload(): mixed; + public function getRequestPayload(): mixed; - public function setPayload(mixed $payload): void; + public function setRequestPayload(mixed $requestPayload): void; - public function getDetails(): array; + public function getResponseData(): array; - public function setDetails(array $details): void; + public function setResponseData(array $responseData): void; } diff --git a/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php b/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php index edefb33ae5..dad5d6a8aa 100644 --- a/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php +++ b/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php @@ -77,25 +77,25 @@ final class PaymentRequestSpec extends ObjectBehavior function it_has_null_data_by_default(): void { - $this->getPayload()->shouldReturn(null); + $this->getRequestPayload()->shouldReturn(null); } function its_data_is_mutable(): void { $stdClass = new stdClass(); - $this->setPayload($stdClass); - $this->getPayload()->shouldReturn($stdClass); + $this->setRequestPayload($stdClass); + $this->getRequestPayload()->shouldReturn($stdClass); } function it_has_empty_array_details_by_default(): void { - $this->getDetails()->shouldReturn([]); + $this->getResponseData()->shouldReturn([]); } function its_details_are_mutable(): void { - $this->setDetails(['foo', 'bar']); - $this->getDetails()->shouldReturn(['foo', 'bar']); + $this->setResponseData(['foo', 'bar']); + $this->getResponseData()->shouldReturn(['foo', 'bar']); } function it_initializes_creation_date_by_default(): void From f6fb4d8538a1a42ba5b485d08dd41d97b3a37846 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 21 Dec 2023 21:13:11 +0100 Subject: [PATCH 007/200] Move Payum stuff to PayumBundle --- .../Command/Payment/AddPaymentRequest.php | 2 +- .../Payum/PayumCapturePaymentRequest.php | 20 ------ .../Payum/PayumStatusPaymentRequest.php | 20 ------ .../Payment/AddPaymentRequestHandler.php | 2 +- .../Offline/CapturePaymentRequestHandler.php | 10 +-- ...php => CapturePaymentRequestProcessor.php} | 10 +-- ...pturePaymentRequestProcessorInterface.php} | 4 +- .../Commands/Payment/AddPaymentRequest.xml | 35 +++++++++++ ...ffline.xml => payment_request_offline.xml} | 4 +- .../Action/SyliusApiGetHttpRequestAction.php | 10 +-- .../Action/SyliusApiRenderTemplateAction.php | 4 +- .../Api}/PayumApiContext.php | 2 +- .../Api}/PayumApiContextInterface.php | 2 +- ...umCapturePaymentRequestCommandProvider.php | 6 +- .../Api}/PayumRequestProcessor.php | 2 +- .../Api}/PayumRequestProcessorInterface.php | 2 +- ...yumStatusPaymentRequestCommandProvider.php | 6 +- .../Api}/PayumTokenFactory.php | 16 ++--- .../Api}/PayumTokenFactoryInterface.php | 2 +- .../Command/CapturePaymentRequest.php | 34 ++++++++++ .../Command/StatusPaymentRequest.php | 34 ++++++++++ .../CommandHandler/PaymentRequestHandler.php} | 8 +-- .../UnregisterPaypalGatewayTypePass.php | 35 ----------- .../UnregisterStripeGatewayTypePass.php | 32 ---------- .../SyliusPayumExtension.php | 62 +++++++++++++++---- .../config/integrations}/offline.xml | 0 .../Resources/config/integrations}/paypal.xml | 0 .../Resources/config/integrations}/stripe.xml | 0 .../config/integrations/sylius_api.xml} | 22 +++---- .../PayumBundle/Resources/config/paypal.xml | 36 +++++++++++ .../Resources/config/services/action.xml | 6 -- .../Resources/config/services/form.xml | 10 --- .../PayumBundle/Resources/config/stripe.xml | 31 ++++++++++ .../Bundle/PayumBundle/SyliusPayumBundle.php | 4 -- src/Sylius/Bundle/PayumBundle/composer.json | 5 +- 35 files changed, 282 insertions(+), 196 deletions(-) delete mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapturePaymentRequest.php delete mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumStatusPaymentRequest.php rename src/Sylius/Bundle/ApiBundle/Payment/Offline/{PaymentRequestToDetailsConverter.php => CapturePaymentRequestProcessor.php} (63%) rename src/Sylius/Bundle/ApiBundle/Payment/Offline/{PaymentRequestToDetailsConverterInterface.php => CapturePaymentRequestProcessorInterface.php} (73%) create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml rename src/Sylius/Bundle/ApiBundle/Resources/config/services/{payment_request/offline.xml => payment_request_offline.xml} (85%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle}/Action/SyliusApiGetHttpRequestAction.php (85%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle}/Action/SyliusApiRenderTemplateAction.php (90%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle/Api}/PayumApiContext.php (94%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle/Api}/PayumApiContextInterface.php (92%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle/Api}/PayumCapturePaymentRequestCommandProvider.php (72%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle/Api}/PayumRequestProcessor.php (96%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle/Api}/PayumRequestProcessorInterface.php (91%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle/Api}/PayumStatusPaymentRequestCommandProvider.php (73%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle/Api}/PayumTokenFactory.php (76%) rename src/Sylius/Bundle/{ApiBundle/Payment/Payum => PayumBundle/Api}/PayumTokenFactoryInterface.php (90%) create mode 100644 src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php create mode 100644 src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php rename src/Sylius/Bundle/{ApiBundle/CommandHandler/Payment/Payum/PayumPaymentRequestHandler.php => PayumBundle/CommandHandler/PaymentRequestHandler.php} (83%) delete mode 100644 src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/UnregisterPaypalGatewayTypePass.php delete mode 100644 src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/UnregisterStripeGatewayTypePass.php rename src/Sylius/Bundle/{ApiBundle/Resources/config/services/payum => PayumBundle/Resources/config/integrations}/offline.xml (100%) rename src/Sylius/Bundle/{ApiBundle/Resources/config/services/payum => PayumBundle/Resources/config/integrations}/paypal.xml (100%) rename src/Sylius/Bundle/{ApiBundle/Resources/config/services/payum => PayumBundle/Resources/config/integrations}/stripe.xml (100%) rename src/Sylius/Bundle/{ApiBundle/Resources/config/services/payum/all.xml => PayumBundle/Resources/config/integrations/sylius_api.xml} (67%) create mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/paypal.xml create mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/stripe.xml diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php index 82e56b72d4..6bc6d8243b 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php @@ -22,7 +22,7 @@ class AddPaymentRequest implements IriToIdentifierConversionAwareInterface { public function __construct( public string $type, - public mixed $data, + public mixed $requestPayload, public ?string $paymentId, public ?string $paymentMethodCode, ) { diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapturePaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapturePaymentRequest.php deleted file mode 100644 index 9fc44d4dc6..0000000000 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/Payum/PayumCapturePaymentRequest.php +++ /dev/null @@ -1,20 +0,0 @@ -setPayment($payment); $paymentRequest->setMethod($paymentMethod); $paymentRequest->setType($addPaymentRequest->type); - $paymentRequest->setRequestPayload($addPaymentRequest->data); + $paymentRequest->setRequestPayload($addPaymentRequest->requestPayload); $this->paymentRequestManager->persist($paymentRequest); return $paymentRequest; diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php index 889cced3b9..cf62579c1c 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Offline/CapturePaymentRequestHandler.php @@ -15,7 +15,7 @@ namespace Sylius\Bundle\ApiBundle\CommandHandler\Payment\Offline; use Sylius\Bundle\ApiBundle\Applicator\PaymentStateMachineTransitionApplicatorInterface; use Sylius\Bundle\ApiBundle\Command\Payment\Offline\CapturePaymentRequest; -use Sylius\Bundle\ApiBundle\Payment\Offline\PaymentRequestToDetailsConverterInterface; +use Sylius\Bundle\ApiBundle\Payment\Offline\CapturePaymentRequestProcessorInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; @@ -29,7 +29,7 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface public function __construct( private RepositoryInterface $paymentRequestRepository, - private PaymentRequestToDetailsConverterInterface $paymentRequestToDetailsConverter, + private CapturePaymentRequestProcessorInterface $capturePaymentRequestProcessor, private PaymentStateMachineTransitionApplicatorInterface $paymentStateMachineTransitionApplicator, ) { } @@ -52,11 +52,11 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface $payment = $paymentRequest->getPayment(); Assert::notNull($payment); - $details = $this->paymentRequestToDetailsConverter->convert($paymentRequest); - $paymentRequest->setResponseData($details); + $this->capturePaymentRequestProcessor->process($paymentRequest); + // @todo modify Payment->getDetails() to retrieve last payment request `responseData` - if ($details['paid']) { + if ($paymentRequest->getResponseData()['paid']) { $this->paymentStateMachineTransitionApplicator->complete($payment); } else { $this->paymentStateMachineTransitionApplicator->process($payment); diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverter.php b/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessor.php similarity index 63% rename from src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverter.php rename to src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessor.php index a3f6dbb404..eabf53ec1e 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverter.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessor.php @@ -17,19 +17,21 @@ use Sylius\Component\Payment\Model\PaymentInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Webmozart\Assert\Assert; -final class PaymentRequestToDetailsConverter implements PaymentRequestToDetailsConverterInterface +final class CapturePaymentRequestProcessor implements CapturePaymentRequestProcessorInterface { - public function convert(PaymentRequestInterface $paymentRequest): array + public function process(PaymentRequestInterface $paymentRequest): void { $payment = $paymentRequest->getPayment(); Assert::notNull($payment); + $responseData = $payment->getDetails(); if (PaymentInterface::STATE_NEW === $payment->getState()) { - return [ + $responseData = [ 'paid' => false, ]; } - return $payment->getDetails(); + $paymentRequest->setResponseData($responseData); + $paymentRequest->setState(PaymentRequestInterface::STATE_COMPLETED); } } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverterInterface.php b/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessorInterface.php similarity index 73% rename from src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverterInterface.php rename to src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessorInterface.php index 05c79d89ad..5d66d98c18 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Offline/PaymentRequestToDetailsConverterInterface.php +++ b/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessorInterface.php @@ -15,7 +15,7 @@ namespace Sylius\Bundle\ApiBundle\Payment\Offline; use Sylius\Component\Payment\Model\PaymentRequestInterface; -interface PaymentRequestToDetailsConverterInterface +interface CapturePaymentRequestProcessorInterface { - public function convert(PaymentRequestInterface $paymentRequest): array; + public function process(PaymentRequestInterface $paymentRequest): void; } diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml new file mode 100644 index 0000000000..ce75fb1877 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml @@ -0,0 +1,35 @@ + + + + + + + + shop:payment_request:create + + + shop:payment_request:create + + + shop:payment_request:create + + + shop:payment_request:create + + + shop:payment_request:create + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request/offline.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request_offline.xml similarity index 85% rename from src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request/offline.xml rename to src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request_offline.xml index 7c530d81ef..b55f84c9f2 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request/offline.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request_offline.xml @@ -24,13 +24,13 @@ - + - + diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php b/src/Sylius/Bundle/PayumBundle/Action/SyliusApiGetHttpRequestAction.php similarity index 85% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php rename to src/Sylius/Bundle/PayumBundle/Action/SyliusApiGetHttpRequestAction.php index 09ffe68d69..882486714f 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiGetHttpRequestAction.php +++ b/src/Sylius/Bundle/PayumBundle/Action/SyliusApiGetHttpRequestAction.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum\Action; +namespace Sylius\Bundle\PayumBundle\Action; use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Core\Request\GetHttpRequest; -use Sylius\Bundle\ApiBundle\Payment\Payum\PayumApiContextInterface; +use Sylius\Bundle\PayumBundle\Api\PayumApiContextInterface; use Webmozart\Assert\Assert; final class SyliusApiGetHttpRequestAction implements ActionInterface @@ -39,9 +39,9 @@ final class SyliusApiGetHttpRequestAction implements ActionInterface $paymentRequest = $this->payumApiContext->getPaymentRequest(); Assert::notNull($paymentRequest); - /** @var array $details */ - $details = $paymentRequest->getRequestPayload(); - $httpRequest = $details['http_request'] ?? []; + /** @var array $payload */ + $payload = $paymentRequest->getRequestPayload(); + $httpRequest = $payload['http_request'] ?? []; $request->query = $httpRequest['query']; $request->request = $httpRequest['request']; diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php b/src/Sylius/Bundle/PayumBundle/Action/SyliusApiRenderTemplateAction.php similarity index 90% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php rename to src/Sylius/Bundle/PayumBundle/Action/SyliusApiRenderTemplateAction.php index 0c7641d74e..4e4d58a849 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/Action/SyliusApiRenderTemplateAction.php +++ b/src/Sylius/Bundle/PayumBundle/Action/SyliusApiRenderTemplateAction.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum\Action; +namespace Sylius\Bundle\PayumBundle\Action; use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Core\Request\RenderTemplate; -use Sylius\Bundle\ApiBundle\Payment\Payum\PayumApiContextInterface; +use Sylius\Bundle\PayumBundle\Api\PayumApiContextInterface; use Webmozart\Assert\Assert; final class SyliusApiRenderTemplateAction implements ActionInterface diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContext.php b/src/Sylius/Bundle/PayumBundle/Api/PayumApiContext.php similarity index 94% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContext.php rename to src/Sylius/Bundle/PayumBundle/Api/PayumApiContext.php index 78b64453a3..f34058ef22 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContext.php +++ b/src/Sylius/Bundle/PayumBundle/Api/PayumApiContext.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum; +namespace Sylius\Bundle\PayumBundle\Api; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php b/src/Sylius/Bundle/PayumBundle/Api/PayumApiContextInterface.php similarity index 92% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php rename to src/Sylius/Bundle/PayumBundle/Api/PayumApiContextInterface.php index 4278d8d186..bedf49622e 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumApiContextInterface.php +++ b/src/Sylius/Bundle/PayumBundle/Api/PayumApiContextInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum; +namespace Sylius\Bundle\PayumBundle\Api; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumCapturePaymentRequestCommandProvider.php b/src/Sylius/Bundle/PayumBundle/Api/PayumCapturePaymentRequestCommandProvider.php similarity index 72% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumCapturePaymentRequestCommandProvider.php rename to src/Sylius/Bundle/PayumBundle/Api/PayumCapturePaymentRequestCommandProvider.php index 0fc941be20..20ad74ec82 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumCapturePaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PayumBundle/Api/PayumCapturePaymentRequestCommandProvider.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum; +namespace Sylius\Bundle\PayumBundle\Api; -use Sylius\Bundle\ApiBundle\Command\Payment\Payum\PayumCapturePaymentRequest; use Sylius\Bundle\ApiBundle\Payment\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\PayumBundle\Command\CapturePaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class PayumCapturePaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface @@ -17,6 +17,6 @@ final class PayumCapturePaymentRequestCommandProvider implements PaymentRequestC public function handle(PaymentRequestInterface $paymentRequest): object { - return new PayumCapturePaymentRequest($paymentRequest->getHash()); + return new CapturePaymentRequest($paymentRequest->getHash()); } } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php b/src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessor.php similarity index 96% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php rename to src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessor.php index 1abc713afb..45f56ec449 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessor.php +++ b/src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessor.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum; +namespace Sylius\Bundle\PayumBundle\Api; use Payum\Core\Payum; use Payum\Core\Security\TokenAggregateInterface; diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php b/src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessorInterface.php similarity index 91% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php rename to src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessorInterface.php index 81a9c0cbed..7d704b4368 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumRequestProcessorInterface.php +++ b/src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessorInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum; +namespace Sylius\Bundle\PayumBundle\Api; use Payum\Core\Security\TokenAggregateInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumStatusPaymentRequestCommandProvider.php b/src/Sylius/Bundle/PayumBundle/Api/PayumStatusPaymentRequestCommandProvider.php similarity index 73% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumStatusPaymentRequestCommandProvider.php rename to src/Sylius/Bundle/PayumBundle/Api/PayumStatusPaymentRequestCommandProvider.php index 34234e5fd1..bd60b82147 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumStatusPaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PayumBundle/Api/PayumStatusPaymentRequestCommandProvider.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum; +namespace Sylius\Bundle\PayumBundle\Api; -use Sylius\Bundle\ApiBundle\Command\Payment\Payum\PayumStatusPaymentRequest; use Sylius\Bundle\ApiBundle\Payment\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\PayumBundle\Command\StatusPaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class PayumStatusPaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface @@ -17,6 +17,6 @@ final class PayumStatusPaymentRequestCommandProvider implements PaymentRequestCo public function handle(PaymentRequestInterface $paymentRequest): object { - return new PayumStatusPaymentRequest($paymentRequest->getHash()); + return new StatusPaymentRequest($paymentRequest->getHash()); } } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php b/src/Sylius/Bundle/PayumBundle/Api/PayumTokenFactory.php similarity index 76% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php rename to src/Sylius/Bundle/PayumBundle/Api/PayumTokenFactory.php index 833d254770..adaeddc619 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactory.php +++ b/src/Sylius/Bundle/PayumBundle/Api/PayumTokenFactory.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum; +namespace Sylius\Bundle\PayumBundle\Api; use Payum\Core\Payum; use Payum\Core\Security\TokenInterface; @@ -40,19 +40,19 @@ final class PayumTokenFactory implements PayumTokenFactoryInterface $gatewayName = $gatewayConfig->getGatewayName(); - /** @var array|null $data */ - $data = $paymentRequest->getRequestPayload(); - Assert::notNull($data); + /** @var array|null $payload */ + $payload = $paymentRequest->getRequestPayload(); + Assert::notNull($payload); - $targetPath = $data['target_path'] ?? null; + $targetPath = $payload['target_path'] ?? null; Assert::notNull($targetPath); - $targetPathParameters = $data['target_path_parameters'] ?? []; + $targetPathParameters = $payload['target_path_parameters'] ?? []; - $afterPath = $data['after_path'] ?? null; + $afterPath = $payload['after_path'] ?? null; Assert::notNull($afterPath); - $afterPathParameters = $data['after_path_parameters'] ?? []; + $afterPathParameters = $payload['after_path_parameters'] ?? []; return $this->payum->getTokenFactory()->createToken( $gatewayName, diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactoryInterface.php b/src/Sylius/Bundle/PayumBundle/Api/PayumTokenFactoryInterface.php similarity index 90% rename from src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactoryInterface.php rename to src/Sylius/Bundle/PayumBundle/Api/PayumTokenFactoryInterface.php index ea6462dcb1..8413ce4a54 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Payum/PayumTokenFactoryInterface.php +++ b/src/Sylius/Bundle/PayumBundle/Api/PayumTokenFactoryInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Payum; +namespace Sylius\Bundle\PayumBundle\Api; use Payum\Core\Security\TokenInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php b/src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php new file mode 100644 index 0000000000..8e9f1a9765 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php @@ -0,0 +1,34 @@ +hash; + } + + public function setHash(string $hash): void + { + $this->hash = $hash; + } +} diff --git a/src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php b/src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php new file mode 100644 index 0000000000..df9e91683e --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php @@ -0,0 +1,34 @@ +hash; + } + + public function setHash(string $hash): void + { + $this->hash = $hash; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumPaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/PaymentRequestHandler.php similarity index 83% rename from src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumPaymentRequestHandler.php rename to src/Sylius/Bundle/PayumBundle/CommandHandler/PaymentRequestHandler.php index 90a94cdc94..94e70c4a2b 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/Payum/PayumPaymentRequestHandler.php +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/PaymentRequestHandler.php @@ -11,19 +11,19 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\CommandHandler\Payment\Payum; +namespace Sylius\Bundle\PayumBundle\CommandHandler; use Payum\Core\Security\TokenAggregateInterface; use Sylius\Bundle\ApiBundle\Command\PaymentRequestHashAwareInterface; -use Sylius\Bundle\ApiBundle\Payment\Payum\PayumRequestProcessorInterface; -use Sylius\Bundle\ApiBundle\Payment\Payum\PayumTokenFactoryInterface; +use Sylius\Bundle\PayumBundle\Api\PayumRequestProcessorInterface; +use Sylius\Bundle\PayumBundle\Api\PayumTokenFactoryInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; /** @experimental */ -final class PayumPaymentRequestHandler implements MessageHandlerInterface +final class PaymentRequestHandler implements MessageHandlerInterface { public function __construct( private RepositoryInterface $paymentRequestRepository, diff --git a/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/UnregisterPaypalGatewayTypePass.php b/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/UnregisterPaypalGatewayTypePass.php deleted file mode 100644 index ca0b76b679..0000000000 --- a/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/UnregisterPaypalGatewayTypePass.php +++ /dev/null @@ -1,35 +0,0 @@ -removeDefinition(self::PAYPAL_GATEWAY_TYPE_SERVICE_ID); - $container->removeDefinition(self::PAYPAL_CONVERT_ACTION_SERVICE_ID); - } -} diff --git a/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/UnregisterStripeGatewayTypePass.php b/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/UnregisterStripeGatewayTypePass.php deleted file mode 100644 index 201ff3ed7e..0000000000 --- a/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/UnregisterStripeGatewayTypePass.php +++ /dev/null @@ -1,32 +0,0 @@ -removeDefinition(self::STRIPE_GATEWAY_TYPE_SERVICE_ID); - } -} diff --git a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php index 760306e14a..96863230e7 100644 --- a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php +++ b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php @@ -13,6 +13,9 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\DependencyInjection; +use Payum\Offline\OfflineGatewayFactory; +use Payum\Paypal\ExpressCheckout\Nvp\PaypalExpressCheckoutGatewayFactory; +use Payum\Stripe\StripeCheckoutGatewayFactory; use Sylius\Bundle\PayumBundle\Attribute\AsGatewayConfigurationType; use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension; use Symfony\Component\Config\FileLocator; @@ -31,6 +34,14 @@ final class SyliusPayumExtension extends AbstractResourceExtension implements Pr $loader->load('services.xml'); + if (class_exists(PaypalExpressCheckoutGatewayFactory::class)) { + $loader->load('paypal.xml'); + } + + if (class_exists(StripeCheckoutGatewayFactory::class)) { + $loader->load('stripe.xml'); + } + $container->setParameter('payum.template.layout', $config['template']['layout']); $container->setParameter('payum.template.obtain_credit_card', $config['template']['obtain_credit_card']); $container->setParameter('sylius.payum.gateway_config.validation_groups', $config['gateway_config']['validation_groups']); @@ -39,6 +50,26 @@ final class SyliusPayumExtension extends AbstractResourceExtension implements Pr } public function prepend(ContainerBuilder $container): void + { + $this->prependSyliusPayment($container); + $this->prependSyliusApi($container); + } + + private function registerAutoconfiguration(ContainerBuilder $container): void + { + $container->registerAttributeForAutoconfiguration( + AsGatewayConfigurationType::class, + static function (ChildDefinition $definition, AsGatewayConfigurationType $attribute): void { + $definition->addTag(AsGatewayConfigurationType::SERVICE_TAG, [ + 'type' => $attribute->getType(), + 'label' => $attribute->getLabel(), + 'priority' => $attribute->getPriority(), + ]); + }, + ); + } + + private function prependSyliusPayment(ContainerBuilder $container): void { if (!$container->hasExtension('sylius_payment')) { return; @@ -60,17 +91,26 @@ final class SyliusPayumExtension extends AbstractResourceExtension implements Pr $container->prependExtensionConfig('sylius_payment', ['gateways' => $gateways]); } - private function registerAutoconfiguration(ContainerBuilder $container): void + private function prependSyliusApi(ContainerBuilder $container): void { - $container->registerAttributeForAutoconfiguration( - AsGatewayConfigurationType::class, - static function (ChildDefinition $definition, AsGatewayConfigurationType $attribute): void { - $definition->addTag(AsGatewayConfigurationType::SERVICE_TAG, [ - 'type' => $attribute->getType(), - 'label' => $attribute->getLabel(), - 'priority' => $attribute->getPriority(), - ]); - }, - ); + if (!$container->hasExtension('sylius_api')) { + return; + } + + $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + + $loader->load('integrations/sylius_api.xml'); + + if (class_exists(OfflineGatewayFactory::class)) { + $loader->load('integrations/offline.xml'); + } + + if (class_exists(PaypalExpressCheckoutGatewayFactory::class)) { + $loader->load('integrations/paypal.xml'); + } + + if (class_exists(StripeCheckoutGatewayFactory::class)) { + $loader->load('integrations/stripe.xml'); + } } } diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/offline.xml similarity index 100% rename from src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/offline.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/offline.xml diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal.xml similarity index 100% rename from src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/paypal.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal.xml diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml similarity index 100% rename from src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/stripe.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/all.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_api.xml similarity index 67% rename from src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/all.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_api.xml index 42c657ac64..15a744d9eb 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payum/all.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_api.xml @@ -22,42 +22,42 @@ - + - + - + - - + + %sylius_api.payment_request.payum.capture.class% - + - - + + %sylius_api.payment_request.payum.status.class% - + - + - + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/paypal.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/paypal.xml new file mode 100644 index 0000000000..cfefe3587c --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/paypal.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/services/action.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/services/action.xml index 28c7650375..cdff2fb237 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/services/action.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/services/action.xml @@ -23,12 +23,6 @@ - - - - - - diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/services/form.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/services/form.xml index 85ae98cc67..c9be25e5ba 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/services/form.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/services/form.xml @@ -31,15 +31,5 @@ - - - - - - - - - - diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/stripe.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/stripe.xml new file mode 100644 index 0000000000..362cac89ce --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/stripe.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PayumBundle/SyliusPayumBundle.php b/src/Sylius/Bundle/PayumBundle/SyliusPayumBundle.php index eb0601154c..212daa295b 100644 --- a/src/Sylius/Bundle/PayumBundle/SyliusPayumBundle.php +++ b/src/Sylius/Bundle/PayumBundle/SyliusPayumBundle.php @@ -15,8 +15,6 @@ namespace Sylius\Bundle\PayumBundle; use Sylius\Bundle\PayumBundle\DependencyInjection\Compiler\InjectContainerIntoControllersPass; use Sylius\Bundle\PayumBundle\DependencyInjection\Compiler\RegisterGatewayConfigTypePass; -use Sylius\Bundle\PayumBundle\DependencyInjection\Compiler\UnregisterPaypalGatewayTypePass; -use Sylius\Bundle\PayumBundle\DependencyInjection\Compiler\UnregisterStripeGatewayTypePass; use Sylius\Bundle\PayumBundle\DependencyInjection\Compiler\UseTweakedDoctrineStoragePass; use Sylius\Bundle\ResourceBundle\AbstractResourceBundle; use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; @@ -38,7 +36,5 @@ final class SyliusPayumBundle extends AbstractResourceBundle $container->addCompilerPass(new InjectContainerIntoControllersPass()); $container->addCompilerPass(new RegisterGatewayConfigTypePass()); $container->addCompilerPass(new UseTweakedDoctrineStoragePass()); - $container->addCompilerPass(new UnregisterPaypalGatewayTypePass(), priority: 128); - $container->addCompilerPass(new UnregisterStripeGatewayTypePass(), priority: 128); } } diff --git a/src/Sylius/Bundle/PayumBundle/composer.json b/src/Sylius/Bundle/PayumBundle/composer.json index 9f3b61ef4a..141a96db12 100644 --- a/src/Sylius/Bundle/PayumBundle/composer.json +++ b/src/Sylius/Bundle/PayumBundle/composer.json @@ -1,7 +1,7 @@ { "name": "sylius/payum-bundle", "type": "symfony-bundle", - "description": "Payum integration for Symfony e-commerce applications.", + "description": "CommandHandler integration for Symfony e-commerce applications.", "keywords": [ "payments", "payment", @@ -44,7 +44,8 @@ }, "suggest": { "payum/paypal-express-checkout-nvp": "To use PayPal Express Chekout NVP", - "payum/stripe": "To use Stripe Checkout" + "payum/stripe": "To use Stripe Checkout", + "sylius/api-bundle": "To use Payum with the Sylius API Bundle" }, "config": { "allow-plugins": { From c6f207af4537a56a25ce68c6b6a0cc6581145d25 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 30 Jan 2024 13:09:34 +0100 Subject: [PATCH 008/200] Move services from ApiBundle to PaymentBundle --- .../PaymentRequestCommandProviderPass.php | 45 ------------------- .../services/payment_request_offline.xml | 36 --------------- .../PaymentRequestDuplicationChecker.php | 16 +------ ...mentRequestDuplicationCheckerInterface.php | 2 +- .../Offline/CapturePaymentRequest.php | 4 +- .../Command/Offline/StatusPaymentRequest.php | 34 ++++++++++++++ .../PaymentRequestHashAwareInterface.php | 22 +++++++++ .../Offline/CapturePaymentRequestHandler.php | 20 +++++---- .../Doctrine/ORM/PaymentRequestRepository.php | 31 ++++++------- .../Processor/OfflineCaptureProcessor.php} | 4 +- .../OfflineCaptureProcessorInterface.php} | 4 +- .../CapturePaymentRequestCommandProvider.php | 8 ++-- .../StatusPaymentRequestCommandProvider.php | 8 ++-- .../PaymentRequestCommandProvider.php | 15 +++---- ...PaymentRequestCommandProviderInterface.php | 4 +- .../PaymentRequestTypeCommandProvider.php | 32 +++++++++++++ .../Resources/config/app/config.yml | 2 +- .../doctrine/model/PaymentRequest.orm.xml | 4 +- .../Resources/config/services.xml | 3 ++ .../Resources/config/services/checker.xml | 26 +++++++++++ .../Resources/config/services/offline.xml | 45 +++++++++++++++++++ .../Resources/config/services/provider.xml | 27 +++++++++++ 22 files changed, 244 insertions(+), 148 deletions(-) delete mode 100644 src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php delete mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request_offline.xml rename src/Sylius/Bundle/{ApiBundle/Payment => PaymentBundle}/Checker/PaymentRequestDuplicationChecker.php (61%) rename src/Sylius/Bundle/{ApiBundle/Payment => PaymentBundle}/Checker/PaymentRequestDuplicationCheckerInterface.php (82%) rename src/Sylius/Bundle/{ApiBundle/Command/Payment => PaymentBundle/Command}/Offline/CapturePaymentRequest.php (81%) create mode 100644 src/Sylius/Bundle/PaymentBundle/Command/Offline/StatusPaymentRequest.php create mode 100644 src/Sylius/Bundle/PaymentBundle/Command/PaymentRequestHashAwareInterface.php rename src/Sylius/Bundle/{ApiBundle/CommandHandler/Payment => PaymentBundle/CommandHandler}/Offline/CapturePaymentRequestHandler.php (69%) rename src/Sylius/Bundle/{ApiBundle/Payment/Offline/CapturePaymentRequestProcessor.php => PaymentBundle/Processor/OfflineCaptureProcessor.php} (86%) rename src/Sylius/Bundle/{ApiBundle/Payment/Offline/CapturePaymentRequestProcessorInterface.php => PaymentBundle/Processor/OfflineCaptureProcessorInterface.php} (79%) rename src/Sylius/Bundle/{ApiBundle/Payment => PaymentBundle/Provider}/Offline/CapturePaymentRequestCommandProvider.php (70%) rename src/Sylius/Bundle/{ApiBundle/Payment => PaymentBundle/Provider}/Offline/StatusPaymentRequestCommandProvider.php (70%) rename src/Sylius/Bundle/{ApiBundle/Payment => PaymentBundle/Provider}/PaymentRequestCommandProvider.php (74%) rename src/Sylius/Bundle/{ApiBundle/Payment => PaymentBundle/Provider}/PaymentRequestCommandProviderInterface.php (64%) create mode 100644 src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestTypeCommandProvider.php create mode 100644 src/Sylius/Bundle/PaymentBundle/Resources/config/services/checker.xml create mode 100644 src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml create mode 100644 src/Sylius/Bundle/PaymentBundle/Resources/config/services/provider.xml diff --git a/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php b/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php deleted file mode 100644 index 2f1a078b45..0000000000 --- a/src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/PaymentRequestCommandProviderPass.php +++ /dev/null @@ -1,45 +0,0 @@ -findTaggedServiceIds('sylius.api.payment_request.command_provider', true) as $serviceId => $tags) { - foreach ($tags as $tag) { - if (!isset($tag['id'])) { - $tag['id'] = $serviceId; - } - - $factoryName = $tag['factory'] ?? null; - Assert::notNull( - $factoryName, - sprintf('The tag "%s" must have a "factory" attribut.', 'sylius.api.payment_request.command_provider') - ); - - $type = $tag['type'] ?? null; - Assert::notNull( - $type, - sprintf('The tag "%s" must have a "type" attribut.', 'sylius.api.payment_request.command_provider') - ); - - $commandProviders[sprintf('%s::%s', $factoryName, $type)] = new Reference($serviceId); - }// offline::capture, - // stripe::capture - // stripe::status - // stripe::refund - } - - $container->getDefinition('sylius.api.payment_request.command_provider.locator')->addArgument($commandProviders); - } -} diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request_offline.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request_offline.xml deleted file mode 100644 index b55f84c9f2..0000000000 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payment_request_offline.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationChecker.php b/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php similarity index 61% rename from src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationChecker.php rename to src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php index bf7cb23a97..1fd79df091 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationChecker.php +++ b/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php @@ -2,15 +2,13 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Checker; +namespace Sylius\Bundle\PaymentBundle\Checker; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; -use Webmozart\Assert\Assert; final class PaymentRequestDuplicationChecker implements PaymentRequestDuplicationCheckerInterface { - public function __construct( private PaymentRequestRepositoryInterface $paymentRequestRepository, ) { @@ -18,17 +16,7 @@ final class PaymentRequestDuplicationChecker implements PaymentRequestDuplicatio public function hasDuplicates(PaymentRequestInterface $paymentRequest): bool { - $payment = $paymentRequest->getPayment(); - Assert::notNull($payment); - - $paymentMethod = $paymentRequest->getMethod(); - Assert::notNull($paymentMethod); - - $paymentRequests = $this->paymentRequestRepository->findExisting( - $payment, - $paymentMethod, - $paymentRequest->getType() - ); + $paymentRequests = $this->paymentRequestRepository->findOtherExisting($paymentRequest); return count($paymentRequests) > 0; } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationCheckerInterface.php b/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationCheckerInterface.php similarity index 82% rename from src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationCheckerInterface.php rename to src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationCheckerInterface.php index 78526585bb..ace56e7e47 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Checker/PaymentRequestDuplicationCheckerInterface.php +++ b/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationCheckerInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Checker; +namespace Sylius\Bundle\PaymentBundle\Checker; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/CapturePaymentRequest.php b/src/Sylius/Bundle/PaymentBundle/Command/Offline/CapturePaymentRequest.php similarity index 81% rename from src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/CapturePaymentRequest.php rename to src/Sylius/Bundle/PaymentBundle/Command/Offline/CapturePaymentRequest.php index 5b1b3c3ee6..215cad448c 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/CapturePaymentRequest.php +++ b/src/Sylius/Bundle/PaymentBundle/Command/Offline/CapturePaymentRequest.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Command\Payment\Offline; +namespace Sylius\Bundle\PaymentBundle\Command\Offline; -use Sylius\Bundle\ApiBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; class CapturePaymentRequest implements PaymentRequestHashAwareInterface { diff --git a/src/Sylius/Bundle/PaymentBundle/Command/Offline/StatusPaymentRequest.php b/src/Sylius/Bundle/PaymentBundle/Command/Offline/StatusPaymentRequest.php new file mode 100644 index 0000000000..b63267e30e --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Command/Offline/StatusPaymentRequest.php @@ -0,0 +1,34 @@ +hash; + } + + public function setHash(string $hash): void + { + $this->hash = $hash; + } +} diff --git a/src/Sylius/Bundle/PaymentBundle/Command/PaymentRequestHashAwareInterface.php b/src/Sylius/Bundle/PaymentBundle/Command/PaymentRequestHashAwareInterface.php new file mode 100644 index 0000000000..51444ee898 --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Command/PaymentRequestHashAwareInterface.php @@ -0,0 +1,22 @@ +getDetails() to retrieve last payment request `responseData` + $stateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH); if ($paymentRequest->getResponseData()['paid']) { - $this->paymentStateMachineTransitionApplicator->complete($payment); + $stateMachine->apply(PaymentTransitions::TRANSITION_COMPLETE); } else { - $this->paymentStateMachineTransitionApplicator->process($payment); + $stateMachine->apply(PaymentTransitions::TRANSITION_PROCESS); } } } diff --git a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php index cde996394a..77b2a5fe4d 100644 --- a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php +++ b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php @@ -14,25 +14,26 @@ declare(strict_types=1); namespace Sylius\Bundle\PaymentBundle\Doctrine\ORM; use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; -use Sylius\Component\Payment\Model\PaymentInterface; -use Sylius\Component\Payment\Model\PaymentMethodInterface; +use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; class PaymentRequestRepository extends EntityRepository implements PaymentRequestRepositoryInterface { - public function findExisting(PaymentInterface $payment, PaymentMethodInterface $paymentMethod, string $type): array + public function findOtherExisting(PaymentRequestInterface $paymentRequest): array { - return $this->createQueryBuilder('o') - ->innerJoin('o.payment', 'payment') - ->innerJoin('o.method', 'method') - ->andWhere('o.type = :type') - ->andWhere('o.payment = :payment') - ->andWhere('o.method = :method') - ->setParameter('type', $type) - ->setParameter('method', $paymentMethod) - ->setParameter('payment', $payment) - ->getQuery() - ->getResult() - ; + return $this->createQueryBuilder('o') + ->innerJoin('o.payment', 'payment') + ->innerJoin('o.method', 'method') + ->where('o != :paymentRequest') + ->andWhere('o.type = :type') + ->andWhere('o.payment = :payment') + ->andWhere('o.method = :method') + ->setParameter('paymentRequest', $paymentRequest) + ->setParameter('type', $paymentRequest->getType()) + ->setParameter('method', $paymentRequest->getMethod()) + ->setParameter('payment', $paymentRequest->getPayment()) + ->getQuery() + ->getResult() + ; } } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessor.php b/src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessor.php similarity index 86% rename from src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessor.php rename to src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessor.php index eabf53ec1e..2c4e4d75ea 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessor.php +++ b/src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessor.php @@ -11,13 +11,13 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Offline; +namespace Sylius\Bundle\PaymentBundle\Processor; use Sylius\Component\Payment\Model\PaymentInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Webmozart\Assert\Assert; -final class CapturePaymentRequestProcessor implements CapturePaymentRequestProcessorInterface +final class OfflineCaptureProcessor implements OfflineCaptureProcessorInterface { public function process(PaymentRequestInterface $paymentRequest): void { diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessorInterface.php b/src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessorInterface.php similarity index 79% rename from src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessorInterface.php rename to src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessorInterface.php index 5d66d98c18..48d24006b6 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestProcessorInterface.php +++ b/src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessorInterface.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Offline; +namespace Sylius\Bundle\PaymentBundle\Processor; use Sylius\Component\Payment\Model\PaymentRequestInterface; -interface CapturePaymentRequestProcessorInterface +interface OfflineCaptureProcessorInterface { public function process(PaymentRequestInterface $paymentRequest): void; } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestCommandProvider.php b/src/Sylius/Bundle/PaymentBundle/Provider/Offline/CapturePaymentRequestCommandProvider.php similarity index 70% rename from src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestCommandProvider.php rename to src/Sylius/Bundle/PaymentBundle/Provider/Offline/CapturePaymentRequestCommandProvider.php index 28cd3d83fe..2445f6d253 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Offline/CapturePaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PaymentBundle/Provider/Offline/CapturePaymentRequestCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Offline; +namespace Sylius\Bundle\PaymentBundle\Provider\Offline; -use Sylius\Bundle\ApiBundle\Command\Payment\Offline\CapturePaymentRequest; -use Sylius\Bundle\ApiBundle\Payment\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\PaymentBundle\Command\Offline\CapturePaymentRequest; +use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class CapturePaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface @@ -24,7 +24,7 @@ final class CapturePaymentRequestCommandProvider implements PaymentRequestComman return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_CAPTURE; } - public function handle(PaymentRequestInterface $paymentRequest): object + public function provide(PaymentRequestInterface $paymentRequest): object { return new CapturePaymentRequest($paymentRequest->getHash()); } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/Offline/StatusPaymentRequestCommandProvider.php b/src/Sylius/Bundle/PaymentBundle/Provider/Offline/StatusPaymentRequestCommandProvider.php similarity index 70% rename from src/Sylius/Bundle/ApiBundle/Payment/Offline/StatusPaymentRequestCommandProvider.php rename to src/Sylius/Bundle/PaymentBundle/Provider/Offline/StatusPaymentRequestCommandProvider.php index 36bd2d92e8..51b1e01b26 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/Offline/StatusPaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PaymentBundle/Provider/Offline/StatusPaymentRequestCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment\Offline; +namespace Sylius\Bundle\PaymentBundle\Provider\Offline; -use Sylius\Bundle\ApiBundle\Command\Payment\Offline\StatusPaymentRequest; -use Sylius\Bundle\ApiBundle\Payment\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\PaymentBundle\Command\Offline\StatusPaymentRequest; +use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class StatusPaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface @@ -24,7 +24,7 @@ final class StatusPaymentRequestCommandProvider implements PaymentRequestCommand return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_CAPTURE; } - public function handle(PaymentRequestInterface $paymentRequest): object + public function provide(PaymentRequestInterface $paymentRequest): object { return new StatusPaymentRequest($paymentRequest->getHash()); } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProvider.php b/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php similarity index 74% rename from src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProvider.php rename to src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php index 1a08a39887..1433be69e9 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment; +namespace Sylius\Bundle\PaymentBundle\Provider; -use Sylius\Bundle\ApiBundle\Payment\Checker\PaymentRequestDuplicationCheckerInterface; +use Sylius\Bundle\PaymentBundle\Checker\PaymentRequestDuplicationCheckerInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Contracts\Service\ServiceProviderInterface; @@ -23,7 +23,7 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid { public function __construct( private PaymentRequestDuplicationCheckerInterface $paymentRequestDuplicationChecker, - private ServiceProviderInterface $paymentRequestCommandProviderLocator, + private ServiceProviderInterface $locator, ) { } @@ -38,9 +38,9 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid return $this->getCommandProvider($paymentRequest)->supports($paymentRequest); } - public function handle(PaymentRequestInterface $paymentRequest): object + public function provide(PaymentRequestInterface $paymentRequest): object { - return $this->getCommandProvider($paymentRequest)->handle($paymentRequest); + return $this->getCommandProvider($paymentRequest)->provide($paymentRequest); } private function getCommandProvider(PaymentRequestInterface $paymentRequest): PaymentRequestCommandProviderInterface @@ -54,11 +54,8 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid /** @var PaymentRequestCommandProviderInterface $service */ $factoryName = $gatewayConfig->getConfig()['factory'] ?? $gatewayConfig->getFactoryName(); - /** @todo consider founding better nested service provider */ - $id = sprintf('%s::%s', $factoryName, $paymentRequest->getType()); - /** @var PaymentRequestCommandProviderInterface $provider */ - $provider = $this->paymentRequestCommandProviderLocator->get($id); + $provider = $this->locator->get($factoryName); return $provider; } diff --git a/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProviderInterface.php b/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProviderInterface.php similarity index 64% rename from src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProviderInterface.php rename to src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProviderInterface.php index a6927abd74..15f4f49140 100644 --- a/src/Sylius/Bundle/ApiBundle/Payment/PaymentRequestCommandProviderInterface.php +++ b/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProviderInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Payment; +namespace Sylius\Bundle\PaymentBundle\Provider; use Sylius\Component\Payment\Model\PaymentRequestInterface; @@ -10,5 +10,5 @@ interface PaymentRequestCommandProviderInterface { public function supports(PaymentRequestInterface $paymentRequest): bool; - public function handle(PaymentRequestInterface $paymentRequest): object; + public function provide(PaymentRequestInterface $paymentRequest): object; } diff --git a/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestTypeCommandProvider.php b/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestTypeCommandProvider.php new file mode 100644 index 0000000000..6e5d222f0a --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestTypeCommandProvider.php @@ -0,0 +1,32 @@ +locator->get($paymentRequest->getType()); + + return $provider->supports($paymentRequest); + } + + public function provide(PaymentRequestInterface $paymentRequest): object + { + /** @var PaymentRequestCommandProviderInterface $provider */ + $provider = $this->locator->get($paymentRequest->getType()); + + return $provider->provide($paymentRequest); + } +} diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml index 7748456355..619fe137f6 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml @@ -7,7 +7,7 @@ parameters: doctrine: dbal: types: - sylius_uuid: "%sylius.uuid_type%" + uuid: "%sylius.uuid_type%" jms_serializer: metadata: diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml index 34ea8cbf19..7617b94729 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml @@ -15,8 +15,8 @@ xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"> - - + + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml index fb9fadbbe9..ed7edb88a9 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml @@ -13,7 +13,10 @@ + + + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/checker.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/checker.xml new file mode 100644 index 0000000000..66c47db6cb --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/checker.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml new file mode 100644 index 0000000000..d81f5f7a86 --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/provider.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/provider.xml new file mode 100644 index 0000000000..8c5c5c48d5 --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/provider.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + From 84a02100d8c317a97b755acd367c7b9624695716 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 30 Jan 2024 13:12:25 +0100 Subject: [PATCH 009/200] Move services from ApiBundle to PayumBundle --- .../SyliusGetHttpRequestAction.php} | 21 +++--- .../SyliusRenderTemplateAction.php} | 8 +-- .../PayumBundle/Api/PayumRequestProcessor.php | 47 ------------ .../Command/AuthorizePaymentRequest.php | 34 +++++++++ .../Command/CapturePaymentRequest.php | 2 +- .../Command/StatusPaymentRequest.php | 2 +- ...php => AuthorizePaymentRequestHandler.php} | 26 +++---- .../CapturePaymentRequestHandler.php | 50 +++++++++++++ .../StatusPaymentRequestHandler.php | 57 +++++++++++++++ .../SyliusPayumExtension.php | 13 +--- .../PayumBundle/Factory/AuthorizeFactory.php | 17 +++++ .../AuthorizeRequestFactoryInterface.php | 13 ++++ .../PayumBundle/Factory/CaptureFactory.php | 17 +++++ .../CaptureRequestFactoryInterface.php | 13 ++++ .../Factory}/PayumTokenFactory.php | 9 ++- .../Factory}/PayumTokenFactoryInterface.php | 2 +- .../PayumPaymentRequestContext.php} | 4 +- .../PayumPaymentRequestContextInterface.php} | 4 +- .../Processor/PayumRequestProcessor.php | 60 ++++++++++++++++ .../PayumRequestProcessorInterface.php | 8 ++- ...AuthorizePaymentRequestCommandProvider.php | 22 ++++++ ...umCapturePaymentRequestCommandProvider.php | 6 +- ...yumStatusPaymentRequestCommandProvider.php | 6 +- .../Resources/config/integrations/offline.xml | 13 ++-- .../config/integrations/payment_request.xml | 71 +++++++++++++++++++ .../Resources/config/integrations/paypal.xml | 30 -------- .../integrations/paypal_express_checkout.xml | 39 ++++++++++ .../Resources/config/integrations/stripe.xml | 17 +++-- .../config/integrations/sylius_api.xml | 67 ----------------- .../Resources/config/services/factory.xml | 6 ++ 30 files changed, 475 insertions(+), 209 deletions(-) rename src/Sylius/Bundle/PayumBundle/Action/{SyliusApiGetHttpRequestAction.php => PaymentRequest/SyliusGetHttpRequestAction.php} (67%) rename src/Sylius/Bundle/PayumBundle/Action/{SyliusApiRenderTemplateAction.php => PaymentRequest/SyliusRenderTemplateAction.php} (79%) delete mode 100644 src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessor.php create mode 100644 src/Sylius/Bundle/PayumBundle/Command/AuthorizePaymentRequest.php rename src/Sylius/Bundle/PayumBundle/CommandHandler/{PaymentRequestHandler.php => AuthorizePaymentRequestHandler.php} (57%) create mode 100644 src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php create mode 100644 src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php create mode 100644 src/Sylius/Bundle/PayumBundle/Factory/AuthorizeFactory.php create mode 100644 src/Sylius/Bundle/PayumBundle/Factory/AuthorizeRequestFactoryInterface.php create mode 100644 src/Sylius/Bundle/PayumBundle/Factory/CaptureFactory.php create mode 100644 src/Sylius/Bundle/PayumBundle/Factory/CaptureRequestFactoryInterface.php rename src/Sylius/Bundle/PayumBundle/{Api => PaymentRequest/Factory}/PayumTokenFactory.php (83%) rename src/Sylius/Bundle/PayumBundle/{Api => PaymentRequest/Factory}/PayumTokenFactoryInterface.php (88%) rename src/Sylius/Bundle/PayumBundle/{Api/PayumApiContext.php => PaymentRequest/PayumPaymentRequestContext.php} (85%) rename src/Sylius/Bundle/PayumBundle/{Api/PayumApiContextInterface.php => PaymentRequest/PayumPaymentRequestContextInterface.php} (84%) create mode 100644 src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessor.php rename src/Sylius/Bundle/PayumBundle/{Api => PaymentRequest/Processor}/PayumRequestProcessorInterface.php (64%) create mode 100644 src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumAuthorizePaymentRequestCommandProvider.php rename src/Sylius/Bundle/PayumBundle/{Api => PaymentRequest/Provider}/PayumCapturePaymentRequestCommandProvider.php (70%) rename src/Sylius/Bundle/PayumBundle/{Api => PaymentRequest/Provider}/PayumStatusPaymentRequestCommandProvider.php (70%) create mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml delete mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal.xml create mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml delete mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_api.xml diff --git a/src/Sylius/Bundle/PayumBundle/Action/SyliusApiGetHttpRequestAction.php b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php similarity index 67% rename from src/Sylius/Bundle/PayumBundle/Action/SyliusApiGetHttpRequestAction.php rename to src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php index 882486714f..e74a88733f 100644 --- a/src/Sylius/Bundle/PayumBundle/Action/SyliusApiGetHttpRequestAction.php +++ b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php @@ -11,18 +11,18 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Action; +namespace Sylius\Bundle\PayumBundle\Action\PaymentRequest; use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Core\Request\GetHttpRequest; -use Sylius\Bundle\PayumBundle\Api\PayumApiContextInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\PayumPaymentRequestContextInterface; use Webmozart\Assert\Assert; -final class SyliusApiGetHttpRequestAction implements ActionInterface +final class SyliusGetHttpRequestAction implements ActionInterface { public function __construct( - private PayumApiContextInterface $payumApiContext, + private PayumPaymentRequestContextInterface $payumApiContext, ) { } @@ -43,15 +43,16 @@ final class SyliusApiGetHttpRequestAction implements ActionInterface $payload = $paymentRequest->getRequestPayload(); $httpRequest = $payload['http_request'] ?? []; - $request->query = $httpRequest['query']; - $request->request = $httpRequest['request']; - // Not existing property - $request->headers = $httpRequest['headers']; + $request->query = $httpRequest['query'] ?? []; + $request->request = $httpRequest['request'] ?? []; $request->method = $httpRequest['method'] ?? 'POST'; $request->uri = $httpRequest['uri'] ?? ''; $request->clientIp = $httpRequest['client_ip'] ?? ''; - $request->userAgent = $httpRequest['user_agent']; - $request->content = $httpRequest['content']; + $request->userAgent = $httpRequest['user_agent'] ?? ''; + $request->content = $httpRequest['content'] ?? ''; + + // Not existing property but used by the Symfony bridge + $request->headers = $httpRequest['headers'] ?? []; } public function supports($request): bool diff --git a/src/Sylius/Bundle/PayumBundle/Action/SyliusApiRenderTemplateAction.php b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php similarity index 79% rename from src/Sylius/Bundle/PayumBundle/Action/SyliusApiRenderTemplateAction.php rename to src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php index 4e4d58a849..ebc259c145 100644 --- a/src/Sylius/Bundle/PayumBundle/Action/SyliusApiRenderTemplateAction.php +++ b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php @@ -11,18 +11,18 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Action; +namespace Sylius\Bundle\PayumBundle\Action\PaymentRequest; use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Core\Request\RenderTemplate; -use Sylius\Bundle\PayumBundle\Api\PayumApiContextInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\PayumPaymentRequestContextInterface; use Webmozart\Assert\Assert; -final class SyliusApiRenderTemplateAction implements ActionInterface +final class SyliusRenderTemplateAction implements ActionInterface { public function __construct( - private PayumApiContextInterface $payumApiContext, + private PayumPaymentRequestContextInterface $payumApiContext, ) { } public function execute($request): void diff --git a/src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessor.php b/src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessor.php deleted file mode 100644 index 45f56ec449..0000000000 --- a/src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessor.php +++ /dev/null @@ -1,47 +0,0 @@ -getToken(); - Assert::notNull($token); - - $gateway = $this->payum->getGateway($token->getGatewayName()); - - $this->payumApiContext->enable($paymentRequest); - $reply = $gateway->execute($request, true); - $this->payumApiContext->disable(); - - $payment = $paymentRequest->getPayment(); - Assert::notNull($payment); - - if (null === $reply) { - $details['after_url'] = $token->getAfterUrl(); - } - } -} diff --git a/src/Sylius/Bundle/PayumBundle/Command/AuthorizePaymentRequest.php b/src/Sylius/Bundle/PayumBundle/Command/AuthorizePaymentRequest.php new file mode 100644 index 0000000000..2d822ac594 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/Command/AuthorizePaymentRequest.php @@ -0,0 +1,34 @@ +hash; + } + + public function setHash(string $hash): void + { + $this->hash = $hash; + } +} diff --git a/src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php b/src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php index 8e9f1a9765..b19e742b54 100644 --- a/src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php +++ b/src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php @@ -13,7 +13,7 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\Command; -use Sylius\Bundle\ApiBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; class CapturePaymentRequest implements PaymentRequestHashAwareInterface { diff --git a/src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php b/src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php index df9e91683e..2a367101ee 100644 --- a/src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php +++ b/src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php @@ -13,7 +13,7 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\Command; -use Sylius\Bundle\ApiBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; class StatusPaymentRequest implements PaymentRequestHashAwareInterface { diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/PaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php similarity index 57% rename from src/Sylius/Bundle/PayumBundle/CommandHandler/PaymentRequestHandler.php rename to src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php index 94e70c4a2b..27bf23916a 100644 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/PaymentRequestHandler.php +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php @@ -13,36 +13,38 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\CommandHandler; -use Payum\Core\Security\TokenAggregateInterface; -use Sylius\Bundle\ApiBundle\Command\PaymentRequestHashAwareInterface; -use Sylius\Bundle\PayumBundle\Api\PayumRequestProcessorInterface; -use Sylius\Bundle\PayumBundle\Api\PayumTokenFactoryInterface; +use Sylius\Bundle\PayumBundle\Command\AuthorizePaymentRequest; +use Sylius\Bundle\PayumBundle\Factory\AuthorizeRequestFactoryInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Factory\PayumTokenFactoryInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\PayumRequestProcessorInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; -/** @experimental */ -final class PaymentRequestHandler implements MessageHandlerInterface +final class AuthorizePaymentRequestHandler implements MessageHandlerInterface { public function __construct( private RepositoryInterface $paymentRequestRepository, private PayumTokenFactoryInterface $payumTokenFactory, private PayumRequestProcessorInterface $payumReplyProcessor, - /** @var class-string */ - private string $payumRequestClass, + private AuthorizeRequestFactoryInterface $factory, ) { } - public function __invoke(PaymentRequestHashAwareInterface $payumRequest): void + public function __invoke(AuthorizePaymentRequest $command): void { /** @var PaymentRequestInterface|null $paymentRequest */ - $paymentRequest = $this->paymentRequestRepository->find($payumRequest->getHash()); + $paymentRequest = $this->paymentRequestRepository->find($command->getHash()); Assert::notNull($paymentRequest); $token = $this->payumTokenFactory->createNew($paymentRequest); - $captureRequest = new $this->payumRequestClass($token); - $this->payumReplyProcessor->process($paymentRequest, $captureRequest); + $request = $this->factory->createNewWithToken($token); + + $token = $request->getToken(); + Assert::notNull($token); + + $this->payumReplyProcessor->process($paymentRequest, $request, $token->getGatewayName()); } } diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php new file mode 100644 index 0000000000..13df4e965a --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php @@ -0,0 +1,50 @@ +paymentRequestRepository->find($command->getHash()); + Assert::notNull($paymentRequest); + + $token = $this->payumTokenFactory->createNew($paymentRequest); + + $request = $this->factory->createNewWithToken($token); + + $token = $request->getToken(); + Assert::notNull($token); + + $this->payumReplyProcessor->process($paymentRequest, $request, $token->getGatewayName()); + } +} diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php new file mode 100644 index 0000000000..0f0255f519 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php @@ -0,0 +1,57 @@ +paymentRequestRepository->find($command->getHash()); + Assert::notNull($paymentRequest); + + $payment = $paymentRequest->getPayment(); + Assert::notNull($payment); + + $request = $this->factory->createNewWithModel($payment); + + /** @var PaymentMethodInterface|null $paymentMethod */ + $paymentMethod = $paymentRequest->getMethod(); + Assert::notNull($paymentMethod); + + $gatewayConfig = $paymentMethod->getGatewayConfig(); + Assert::notNull($gatewayConfig); + + $gatewayName = $gatewayConfig->getGatewayName(); + + $this->payumReplyProcessor->process($paymentRequest, $request, $gatewayName); + } +} diff --git a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php index 96863230e7..5c54f28244 100644 --- a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php +++ b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php @@ -52,7 +52,6 @@ final class SyliusPayumExtension extends AbstractResourceExtension implements Pr public function prepend(ContainerBuilder $container): void { $this->prependSyliusPayment($container); - $this->prependSyliusApi($container); } private function registerAutoconfiguration(ContainerBuilder $container): void @@ -89,24 +88,16 @@ final class SyliusPayumExtension extends AbstractResourceExtension implements Pr } $container->prependExtensionConfig('sylius_payment', ['gateways' => $gateways]); - } - - private function prependSyliusApi(ContainerBuilder $container): void - { - if (!$container->hasExtension('sylius_api')) { - return; - } $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - - $loader->load('integrations/sylius_api.xml'); + $loader->load('integrations/payment_request.xml'); if (class_exists(OfflineGatewayFactory::class)) { $loader->load('integrations/offline.xml'); } if (class_exists(PaypalExpressCheckoutGatewayFactory::class)) { - $loader->load('integrations/paypal.xml'); + $loader->load('integrations/paypal_express_checkout.xml'); } if (class_exists(StripeCheckoutGatewayFactory::class)) { diff --git a/src/Sylius/Bundle/PayumBundle/Factory/AuthorizeFactory.php b/src/Sylius/Bundle/PayumBundle/Factory/AuthorizeFactory.php new file mode 100644 index 0000000000..97a1faf7ce --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/Factory/AuthorizeFactory.php @@ -0,0 +1,17 @@ +getRequestPayload(); - Assert::notNull($payload); + Assert::notNull($payload, 'The request payload need to be not null!'); $targetPath = $payload['target_path'] ?? null; - Assert::notNull($targetPath); + Assert::notNull($targetPath, 'The request payload must have a "target_path" field!'); $targetPathParameters = $payload['target_path_parameters'] ?? []; $afterPath = $payload['after_path'] ?? null; - Assert::notNull($afterPath); + Assert::notNull($afterPath, 'The request payload must have an "after_path" field!'); $afterPathParameters = $payload['after_path_parameters'] ?? []; diff --git a/src/Sylius/Bundle/PayumBundle/Api/PayumTokenFactoryInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactoryInterface.php similarity index 88% rename from src/Sylius/Bundle/PayumBundle/Api/PayumTokenFactoryInterface.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactoryInterface.php index 8413ce4a54..16a21c8761 100644 --- a/src/Sylius/Bundle/PayumBundle/Api/PayumTokenFactoryInterface.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactoryInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Api; +namespace Sylius\Bundle\PayumBundle\PaymentRequest\Factory; use Payum\Core\Security\TokenInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/Api/PayumApiContext.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContext.php similarity index 85% rename from src/Sylius/Bundle/PayumBundle/Api/PayumApiContext.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContext.php index f34058ef22..e4f5ae409f 100644 --- a/src/Sylius/Bundle/PayumBundle/Api/PayumApiContext.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContext.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Api; +namespace Sylius\Bundle\PayumBundle\PaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; -final class PayumApiContext implements PayumApiContextInterface +final class PayumPaymentRequestContext implements PayumPaymentRequestContextInterface { private ?PaymentRequestInterface $paymentRequest = null; diff --git a/src/Sylius/Bundle/PayumBundle/Api/PayumApiContextInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContextInterface.php similarity index 84% rename from src/Sylius/Bundle/PayumBundle/Api/PayumApiContextInterface.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContextInterface.php index bedf49622e..1f5aad664d 100644 --- a/src/Sylius/Bundle/PayumBundle/Api/PayumApiContextInterface.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContextInterface.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Api; +namespace Sylius\Bundle\PayumBundle\PaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; -interface PayumApiContextInterface +interface PayumPaymentRequestContextInterface { public function isEnabled(): bool; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessor.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessor.php new file mode 100644 index 0000000000..b78e591828 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessor.php @@ -0,0 +1,60 @@ +payum->getGateway($gatewayName); + + $this->payumApiContext->enable($paymentRequest); + $reply = $gateway->execute($request, true); + $this->payumApiContext->disable(); + + if (null !== $reply) { + return; + } + + $paymentRequest->setState(PaymentRequestInterface::STATE_COMPLETED); + + if (false === $request instanceof TokenAggregateInterface) { + return; + } + + $token = $request->getToken(); + if (null === $token) { + return; + } + + $details = $paymentRequest->getResponseData(); + $details['after_url'] = $token->getAfterUrl(); + $paymentRequest->setResponseData($details); + } +} diff --git a/src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessorInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessorInterface.php similarity index 64% rename from src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessorInterface.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessorInterface.php index 7d704b4368..4d44304768 100644 --- a/src/Sylius/Bundle/PayumBundle/Api/PayumRequestProcessorInterface.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessorInterface.php @@ -11,12 +11,16 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Api; +namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor; use Payum\Core\Security\TokenAggregateInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; interface PayumRequestProcessorInterface { - public function process( PaymentRequestInterface $paymentRequest, TokenAggregateInterface $request): void; + public function process( + PaymentRequestInterface $paymentRequest, + TokenAggregateInterface $request, + string $gatewayName + ): void; } diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumAuthorizePaymentRequestCommandProvider.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumAuthorizePaymentRequestCommandProvider.php new file mode 100644 index 0000000000..fb79eae89c --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumAuthorizePaymentRequestCommandProvider.php @@ -0,0 +1,22 @@ +getType() === PaymentRequestInterface::DATA_TYPE_AUTHORIZE; + } + + public function provide(PaymentRequestInterface $paymentRequest): object + { + return new AuthorizePaymentRequest($paymentRequest->getHash()); + } +} diff --git a/src/Sylius/Bundle/PayumBundle/Api/PayumCapturePaymentRequestCommandProvider.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumCapturePaymentRequestCommandProvider.php similarity index 70% rename from src/Sylius/Bundle/PayumBundle/Api/PayumCapturePaymentRequestCommandProvider.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumCapturePaymentRequestCommandProvider.php index 20ad74ec82..b56c99e53c 100644 --- a/src/Sylius/Bundle/PayumBundle/Api/PayumCapturePaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumCapturePaymentRequestCommandProvider.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Api; +namespace Sylius\Bundle\PayumBundle\PaymentRequest\Provider; -use Sylius\Bundle\ApiBundle\Payment\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\PayumBundle\Command\CapturePaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; @@ -15,7 +15,7 @@ final class PayumCapturePaymentRequestCommandProvider implements PaymentRequestC return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_CAPTURE; } - public function handle(PaymentRequestInterface $paymentRequest): object + public function provide(PaymentRequestInterface $paymentRequest): object { return new CapturePaymentRequest($paymentRequest->getHash()); } diff --git a/src/Sylius/Bundle/PayumBundle/Api/PayumStatusPaymentRequestCommandProvider.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumStatusPaymentRequestCommandProvider.php similarity index 70% rename from src/Sylius/Bundle/PayumBundle/Api/PayumStatusPaymentRequestCommandProvider.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumStatusPaymentRequestCommandProvider.php index bd60b82147..6a0b6add22 100644 --- a/src/Sylius/Bundle/PayumBundle/Api/PayumStatusPaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumStatusPaymentRequestCommandProvider.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Api; +namespace Sylius\Bundle\PayumBundle\PaymentRequest\Provider; -use Sylius\Bundle\ApiBundle\Payment\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\PayumBundle\Command\StatusPaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; @@ -15,7 +15,7 @@ final class PayumStatusPaymentRequestCommandProvider implements PaymentRequestCo return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_STATUS; } - public function handle(PaymentRequestInterface $paymentRequest): object + public function provide(PaymentRequestInterface $paymentRequest): object { return new StatusPaymentRequest($paymentRequest->getHash()); } diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/offline.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/offline.xml index 4f5b8fc87a..31bfbffb8b 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/offline.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/offline.xml @@ -18,12 +18,17 @@ - - + + + - - + + + + + + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml new file mode 100644 index 0000000000..f9257b4925 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal.xml deleted file mode 100644 index 4b8a93dd56..0000000000 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml new file mode 100644 index 0000000000..f3aa832f81 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml index 6fae63e2e2..27b0a32360 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml @@ -18,12 +18,21 @@ - - + + + - - + + + + + + + + + + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_api.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_api.xml deleted file mode 100644 index 15a744d9eb..0000000000 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_api.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - Payum\Core\Request\Capture - Sylius\Bundle\PayumBundle\Request\GetStatus - - - - - - - - - - - - - - - - - - %sylius_api.payment_request.payum.capture.class% - - - - - - - - - %sylius_api.payment_request.payum.status.class% - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml index f194ce1a53..ce30756b56 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml @@ -12,5 +12,11 @@ + + + + + + From 75f028bda1f2902fd38591b0a73cb0e97b27bd66 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 30 Jan 2024 13:14:26 +0100 Subject: [PATCH 010/200] Update field in migration --- .../Bundle/CoreBundle/Migrations/Version20231106190918.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php b/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php index a38141a0cc..d226a42118 100644 --- a/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php +++ b/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php @@ -25,7 +25,7 @@ final class Version20231106190918 extends AbstractMigration public function up(Schema $schema): void { - $this->addSql('CREATE TABLE sylius_payment_request (hash CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, data LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\', details JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_86D904B19883967 (method_id), INDEX IDX_86D904B4C3A3BB (payment_id), PRIMARY KEY(hash)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE sylius_payment_request (hash CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, request_payload LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\', response_data JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_86D904B19883967 (method_id), INDEX IDX_86D904B4C3A3BB (payment_id), PRIMARY KEY(hash)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B19883967 FOREIGN KEY (method_id) REFERENCES sylius_payment_method (id)'); $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B4C3A3BB FOREIGN KEY (payment_id) REFERENCES sylius_payment (id)'); } From 7ee2363dc1a12316000d988bfe7584e3e9c0ded0 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 30 Jan 2024 13:15:13 +0100 Subject: [PATCH 011/200] Add validation on adding payment request --- .../config/validation/AddPaymentRequest.xml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml new file mode 100644 index 0000000000..0010c3cc42 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + From 4be681c83158055c4950bf26534d90dc36bab6f8 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 30 Jan 2024 13:16:19 +0100 Subject: [PATCH 012/200] Behat api scenario for PayPal --- ...paying_with_paypal_during_checkout.feature | 10 +- .../Behat/Context/Api/PaypalContext.php | 183 ++++++++++++++++++ src/Sylius/Behat/Context/Api/Resources.php | 2 + .../Checkout/CheckoutOrderDetailsContext.php | 118 +++++++++++ .../Behat/Context/Setup/PaymentContext.php | 2 + src/Sylius/Behat/Context/Ui/PaypalContext.php | 19 +- .../config/services/contexts/api/shop.xml | 15 ++ .../suites/api/checkout/paying_for_order.yml | 5 + .../Behat/Service/Mocker/PaypalApiMocker.php | 40 ++-- .../Command/Payment/AddPaymentRequest.php | 30 ++- .../Payment/Offline/StatusPaymentRequest.php | 34 ---- .../Command/Payment/UpdatePaymentRequest.php | 43 ++++ .../PaymentRequestHashAwareInterface.php | 6 +- .../Payment/AddPaymentRequestHandler.php | 28 +-- .../Payment/UpdatePaymentRequestHandler.php | 54 ++++++ ...stHashAwareInputCommandDataTransformer.php | 36 ++++ .../config/api_resources/PaymentRequest.xml | 19 +- .../Commands/Payment/AddPaymentRequest.xml | 11 +- .../Commands/Payment/UpdatePaymentRequest.xml | 23 +++ .../ApiBundle/Resources/config/services.xml | 4 + .../config/services/command_handlers.xml | 13 +- .../Resources/config/services/payments.xml | 13 -- .../Bundle/ApiBundle/SyliusApiBundle.php | 2 - .../PaymentRequestRepositoryInterface.php | 5 +- 24 files changed, 590 insertions(+), 125 deletions(-) create mode 100644 src/Sylius/Behat/Context/Api/PaypalContext.php create mode 100644 src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php delete mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/StatusPaymentRequest.php create mode 100644 src/Sylius/Bundle/ApiBundle/Command/Payment/UpdatePaymentRequest.php create mode 100644 src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php create mode 100644 src/Sylius/Bundle/ApiBundle/DataTransformer/PaymentRequestHashAwareInputCommandDataTransformer.php create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/UpdatePaymentRequest.xml diff --git a/features/shop/checkout/paying_for_order/paying_with_paypal_during_checkout.feature b/features/shop/checkout/paying_for_order/paying_with_paypal_during_checkout.feature index 5f6d8c2d39..35f9536287 100644 --- a/features/shop/checkout/paying_for_order/paying_with_paypal_during_checkout.feature +++ b/features/shop/checkout/paying_for_order/paying_with_paypal_during_checkout.feature @@ -12,7 +12,7 @@ Feature: Paying with paypal during checkout And the store ships everywhere for Free And I am logged in as "john@example.com" - @ui + @ui @api Scenario: Successfully authorize payment Given I added product "PHP T-Shirt" to the cart And I have proceeded selecting "PayPal" payment method @@ -23,7 +23,7 @@ Feature: Paying with paypal during checkout And I should see the thank you page And the latest order should have a payment with state "completed" - @ui + @ui @api Scenario: Successful payment Given I added product "PHP T-Shirt" to the cart And I have proceeded selecting "PayPal" payment method @@ -32,7 +32,7 @@ Feature: Paying with paypal during checkout Then I should be notified that my payment has been completed And I should see the thank you page - @ui + @ui @api Scenario: Cancelling the payment Given I added product "PHP T-Shirt" to the cart And I have proceeded selecting "PayPal" payment method @@ -41,7 +41,7 @@ Feature: Paying with paypal during checkout Then I should be notified that my payment has been cancelled And I should be able to pay again - @ui + @ui @api Scenario: Retrying the payment with success Given I added product "PHP T-Shirt" to the cart And I have proceeded selecting "PayPal" payment method @@ -52,7 +52,7 @@ Feature: Paying with paypal during checkout Then I should be notified that my payment has been completed And I should see the thank you page - @ui + @ui @api Scenario: Retrying the payment and failing Given I added product "PHP T-Shirt" to the cart And I have proceeded selecting "PayPal" payment method diff --git a/src/Sylius/Behat/Context/Api/PaypalContext.php b/src/Sylius/Behat/Context/Api/PaypalContext.php new file mode 100644 index 0000000000..b72f57e4eb --- /dev/null +++ b/src/Sylius/Behat/Context/Api/PaypalContext.php @@ -0,0 +1,183 @@ +completeOrder(); + + $this->paypalApiMocker->performActionInApiInitializeScope(function () { + $payment = $this->responseChecker->getValue($this->client->getLastResponse(), 'payments')[0]; + $this->postPaymentRequest($payment); + + $uri = $this->responseChecker->getValue($this->client->getLastResponse(), '@id'); + $this->sharedStorage->set('payment_request_uri', $uri); + }); + } + + /** + * @When I sign in to PayPal and authorize successfully + */ + public function iSignInToPaypalAndAuthorizeSuccessfully(): void + { + $this->paypalApiMocker->performActionInApiSuccessfulScope(function () { + $uri = $this->sharedStorage->get('payment_request_uri'); + $request = $this->requestFactory->custom( + $uri, + HttpRequest::METHOD_PUT, + [], + $this->client->getToken(), + ); + + $request->setContent([ + 'requestPayload' => [ + 'target_path' => 'https://myshop.tld/target-path', + 'after_path' => 'https://myshop.tld/after-path', + 'http_request' => [ + 'query' => [ + 'token'=>'EC-2d9EV13959UR209410U', + 'PayerID'=>'UX8WBNYWGBVMG', + ] + ], + ], + ]); + + $this->client->executeCustomRequest($request); + }); + } + + /** + * @When I sign in to PayPal and pay successfully + */ + public function iSignInToPaypalAndPaySuccessfully(): void + { + $this->paypalApiMocker->performActionInApiSuccessfulScope(function () { + $this->paypalExpressCheckoutPage->pay(); + }); + } + + /** + * @Given /^I have cancelled (?:|my )PayPal payment$/ + * @When /^I cancel (?:|my )PayPal payment$/ + */ + public function iCancelMyPaypalPayment(): void + { + $this->paypalExpressCheckoutPage->cancel(); + } + + /** + * @When /^I try to pay(?:| again)$/ + */ + public function iTryToPayAgain(): void + { + $this->paypalApiMocker->performActionInApiInitializeScope(function () { + $this->orderDetails->pay(); + }); + } + + /** + * @Then I should be notified that my payment has been cancelled + */ + public function iShouldBeNotifiedThatMyPaymentHasBeenCancelled(): void + { + $this->assertNotification('Payment has been cancelled.'); + } + + /** + * @Then I should be notified that my payment has been completed + */ + public function iShouldBeNotifiedThatMyPaymentHasBeenCompleted(): void + { + Assert::true( + $this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()), + sprintf( + 'Payment request could not be edited: %s', + $this->responseChecker->getError($this->client->getLastResponse()), + ), + ); + } + + private function completeOrder(): void + { + $request = $this->requestFactory->customItemAction( + 'shop', + Resources::ORDERS, + $this->sharedStorage->get('cart_token'), + HTTPRequest::METHOD_PATCH, + 'complete', + ); + + $this->client->executeCustomRequest($request); + } + + private function postPaymentRequest(array $payment): void + { + $request = $this->requestFactory->create( + 'shop', + Resources::PAYMENT_REQUESTS, + 'Authorization', + $this->client->getToken(), + ); + + /** @var PaymentMethodInterface $paymentMethod */ + $paymentMethod = $this->paymentMethodRepository->findOneBy([]); + /** @var GatewayConfigInterface $gatewayConfig */ + $gatewayConfig = $paymentMethod->getGatewayConfig(); + $authorize = $gatewayConfig->getConfig()['use_authorize'] ?? false; + + $request->setContent([ + 'paymentId' => $payment['@id'], + 'paymentMethodCode' => $payment['method'], + 'type' => $authorize + ? PaymentRequestInterface::DATA_TYPE_AUTHORIZE + : PaymentRequestInterface::DATA_TYPE_CAPTURE + , + 'requestPayload' => [ + 'target_path' => 'https://myshop.tld/target-path', + 'after_path' => 'https://myshop.tld/after-path', + ], + ]); + + $this->client->executeCustomRequest($request); + } +} diff --git a/src/Sylius/Behat/Context/Api/Resources.php b/src/Sylius/Behat/Context/Api/Resources.php index d17212bbca..c0cbca789a 100644 --- a/src/Sylius/Behat/Context/Api/Resources.php +++ b/src/Sylius/Behat/Context/Api/Resources.php @@ -55,6 +55,8 @@ final class Resources public const PAYMENTS = 'payments'; + public const PAYMENT_REQUESTS = 'payment-requests'; + public const PRODUCT_ASSOCIATION_TYPES = 'product-association-types'; public const PRODUCT_ASSOCIATIONS = 'product-associations'; diff --git a/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php b/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php new file mode 100644 index 0000000000..744e06c7cc --- /dev/null +++ b/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php @@ -0,0 +1,118 @@ +orderDetails->open(['tokenValue' => $order->getTokenValue()]); + } + + /** + * @When I try to pay with :paymentMethodName payment method + */ + public function iChangePaymentMethodTo(string $paymentMethodName): void + { + $this->orderDetails->choosePaymentMethod($paymentMethodName); + $this->orderDetails->pay(); + } + + /** + * @When I retry the payment with :paymentMethodName payment method + */ + public function iChangePaymentMethodAfterCheckout(string $paymentMethodName): void + { + $this->thankYouPage->goToTheChangePaymentMethodPage(); + $this->orderDetails->choosePaymentMethod($paymentMethodName); + $this->orderDetails->pay(); + } + + /** + * @When I want to pay for my order + */ + public function iWantToPayForMyOrder(): void + { + $this->thankYouPage->goToTheChangePaymentMethodPage(); + } + + /** + * @When I try to pay for my order + */ + public function iTryToPayForMyOrder(): void + { + $this->thankYouPage->goToTheChangePaymentMethodPage(); + $this->orderDetails->pay(); + } + + /** + * @Then I should be able to pay (again) + */ + public function iShouldBeAbleToPay(): void + { + Assert::true($this->orderDetails->hasPayAction()); + } + + /** + * @Then I should not be able to pay (again) + */ + public function iShouldNotBeAbleToPay(): void + { + Assert::false($this->orderDetails->canBePaid()); + } + + /** + * @Then I should see :quantity as number of items + */ + public function iShouldSeeAsNumberOfItems(int $quantity): void + { + Assert::same($this->orderDetails->getAmountOfItems(), $quantity); + } + + /** + * @Then I should have chosen :paymentMethodName payment method + */ + public function iShouldHaveChosenPaymentMethod(string $paymentMethodName): void + { + $this->thankYouPage->goToTheChangePaymentMethodPage(); + Assert::same($this->orderDetails->getChosenPaymentMethod(), $paymentMethodName); + } + + /** + * @Then I should be notified to choose a payment method + */ + public function iShouldBeNotifiedToChooseAPaymentMethod(): void + { + Assert::contains($this->orderDetails->getPaymentValidationMessage(), 'Please select a payment method.'); + } +} diff --git a/src/Sylius/Behat/Context/Setup/PaymentContext.php b/src/Sylius/Behat/Context/Setup/PaymentContext.php index 9fa1a569e2..fc677d192a 100644 --- a/src/Sylius/Behat/Context/Setup/PaymentContext.php +++ b/src/Sylius/Behat/Context/Setup/PaymentContext.php @@ -17,6 +17,7 @@ use Behat\Behat\Context\Context; use Doctrine\Persistence\ObjectManager; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; +use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; use Sylius\Component\Core\Formatter\StringInflector; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\OrderInterface; @@ -161,6 +162,7 @@ final readonly class PaymentContext implements Context */ public function thePaymentMethodRequiresAuthorizationBeforeCapturing(PaymentMethodInterface $paymentMethod) { + /** @var GatewayConfigInterface $config */ $config = $paymentMethod->getGatewayConfig(); $config->setConfig(array_merge($config->getConfig(), ['use_authorize' => true])); $paymentMethod->setGatewayConfig($config); diff --git a/src/Sylius/Behat/Context/Ui/PaypalContext.php b/src/Sylius/Behat/Context/Ui/PaypalContext.php index e3d45ba0c8..760d461551 100644 --- a/src/Sylius/Behat/Context/Ui/PaypalContext.php +++ b/src/Sylius/Behat/Context/Ui/PaypalContext.php @@ -33,7 +33,7 @@ final class PaypalContext implements Context * @When /^I confirm my order with paypal payment$/ * @Given /^I have confirmed my order with paypal payment$/ */ - public function iConfirmMyOrderWithPaypalPayment() + public function iConfirmMyOrderWithPaypalPayment(): void { $this->paypalApiMocker->performActionInApiInitializeScope(function () { $this->summaryPage->confirmOrder(); @@ -43,7 +43,7 @@ final class PaypalContext implements Context /** * @When I sign in to PayPal and authorize successfully */ - public function iSignInToPaypalAndAuthorizeSuccessfully() + public function iSignInToPaypalAndAuthorizeSuccessfully(): void { $this->paypalApiMocker->performActionInApiSuccessfulScope(function () { $this->paypalExpressCheckoutPage->authorize(); @@ -53,7 +53,7 @@ final class PaypalContext implements Context /** * @When I sign in to PayPal and pay successfully */ - public function iSignInToPaypalAndPaySuccessfully() + public function iSignInToPaypalAndPaySuccessfully(): void { $this->paypalApiMocker->performActionInApiSuccessfulScope(function () { $this->paypalExpressCheckoutPage->pay(); @@ -64,7 +64,7 @@ final class PaypalContext implements Context * @Given /^I have cancelled (?:|my )PayPal payment$/ * @When /^I cancel (?:|my )PayPal payment$/ */ - public function iCancelMyPaypalPayment() + public function iCancelMyPaypalPayment(): void { $this->paypalExpressCheckoutPage->cancel(); } @@ -72,7 +72,7 @@ final class PaypalContext implements Context /** * @When /^I try to pay(?:| again)$/ */ - public function iTryToPayAgain() + public function iTryToPayAgain(): void { $this->paypalApiMocker->performActionInApiInitializeScope(function () { $this->orderDetails->pay(); @@ -82,7 +82,7 @@ final class PaypalContext implements Context /** * @Then I should be notified that my payment has been cancelled */ - public function iShouldBeNotifiedThatMyPaymentHasBeenCancelled() + public function iShouldBeNotifiedThatMyPaymentHasBeenCancelled(): void { $this->assertNotification('Payment has been cancelled.'); } @@ -90,15 +90,12 @@ final class PaypalContext implements Context /** * @Then I should be notified that my payment has been completed */ - public function iShouldBeNotifiedThatMyPaymentHasBeenCompleted() + public function iShouldBeNotifiedThatMyPaymentHasBeenCompleted(): void { $this->assertNotification('Payment has been completed.'); } - /** - * @param string $expectedNotification - */ - private function assertNotification($expectedNotification) + private function assertNotification(string $expectedNotification): void { $notifications = $this->orderDetails->getNotifications(); $hasNotifications = ''; diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml index c6d117e1c2..cec644c8ee 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml @@ -166,6 +166,15 @@ + + + + + + + + + @@ -190,6 +199,12 @@ + + + + + + diff --git a/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml b/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml index 7918de3352..8a29cd9251 100644 --- a/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml +++ b/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml @@ -11,8 +11,10 @@ default: - sylius.behat.context.transform.cart - sylius.behat.context.transform.channel - sylius.behat.context.transform.country + - sylius.behat.context.transform.customer - sylius.behat.context.transform.lexical - sylius.behat.context.transform.locale + - sylius.behat.context.transform.order - sylius.behat.context.transform.payment - sylius.behat.context.transform.product - sylius.behat.context.transform.product_variant @@ -25,6 +27,7 @@ default: - sylius.behat.context.setup.cart - sylius.behat.context.setup.channel + - sylius.behat.context.setup.currency - sylius.behat.context.setup.checkout - sylius.behat.context.setup.geographical - sylius.behat.context.setup.locale @@ -34,8 +37,10 @@ default: - sylius.behat.context.setup.shipping - sylius.behat.context.setup.shop_api_security - sylius.behat.context.setup.taxation + - sylius.behat.context.setup.user - sylius.behat.context.setup.zone + - sylius.behat.context.api.paypal - sylius.behat.context.api.shop.cart - sylius.behat.context.api.shop.checkout - sylius.behat.context.api.shop.checkout.complete diff --git a/src/Sylius/Behat/Service/Mocker/PaypalApiMocker.php b/src/Sylius/Behat/Service/Mocker/PaypalApiMocker.php index 42282c2756..8d1e953830 100644 --- a/src/Sylius/Behat/Service/Mocker/PaypalApiMocker.php +++ b/src/Sylius/Behat/Service/Mocker/PaypalApiMocker.php @@ -13,7 +13,7 @@ declare(strict_types=1); namespace Sylius\Behat\Service\Mocker; -use Mockery\Mock; +use Mockery\MockInterface; use Payum\Core\HttpClientInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -27,21 +27,21 @@ class PaypalApiMocker ) { } - public function performActionInApiInitializeScope(callable $action) + public function performActionInApiInitializeScope(callable $action): void { $this->mockApiPaymentInitializeResponse(); $action(); $this->mocker->unmockAll(); } - public function performActionInApiSuccessfulScope(callable $action) + public function performActionInApiSuccessfulScope(callable $action): void { $this->mockApiSuccessfulPaymentResponse(); $action(); $this->mocker->unmockAll(); } - private function mockApiSuccessfulPaymentResponse() + private function mockApiSuccessfulPaymentResponse(): void { $mockedResponse = $this->responseLoader->getMockedResponse('Paypal/paypal_api_successful_payment.json'); $firstGetExpressCheckoutDetailsStream = $this->mockStream($mockedResponse['firstGetExpressCheckoutDetails']); @@ -57,13 +57,13 @@ class PaypalApiMocker $getTransactionDetailsResponse = $this->mockHttpResponse(200, $getTransactionDetailsStream); $this->mocker->mockService('sylius.payum.http_client', HttpClientInterface::class) - ->shouldReceive('send') + ->expects('send') ->times(4) - ->andReturn($firstGetExpressCheckoutDetailsResponse, $doExpressCheckoutPaymentResponse, $secondGetExpressCheckoutDetailsResponse, $getTransactionDetailsResponse) + ->andReturns($firstGetExpressCheckoutDetailsResponse, $doExpressCheckoutPaymentResponse, $secondGetExpressCheckoutDetailsResponse, $getTransactionDetailsResponse) ; } - private function mockApiPaymentInitializeResponse() + private function mockApiPaymentInitializeResponse(): void { $mockedResponse = $this->responseLoader->getMockedResponse('Paypal/paypal_api_initialize_payment.json'); $setExpressCheckoutStream = $this->mockStream($mockedResponse['setExpressCheckout']); @@ -73,36 +73,26 @@ class PaypalApiMocker $getExpressCheckoutDetailsResponse = $this->mockHttpResponse(200, $getExpressCheckoutDetailsStream); $this->mocker->mockService('sylius.payum.http_client', HttpClientInterface::class) - ->shouldReceive('send') + ->expects('send') ->twice() - ->andReturn($setExpressCheckoutResponse, $getExpressCheckoutDetailsResponse) + ->andReturns($setExpressCheckoutResponse, $getExpressCheckoutDetailsResponse) ; } - /** - * @param string $content - * - * @return Mock - */ - private function mockStream($content) + private function mockStream(string $content): MockInterface { $mockedStream = $this->mocker->mockCollaborator(StreamInterface::class); - $mockedStream->shouldReceive('getContents')->once()->andReturn($content); - $mockedStream->shouldReceive('close')->once()->andReturn(); + $mockedStream->expects('getContents')->andReturns($content); + $mockedStream->expects('close')->andReturns(); return $mockedStream; } - /** - * @param int $statusCode - * - * @return Mock - */ - private function mockHttpResponse($statusCode, $streamMock) + private function mockHttpResponse(int $statusCode, MockInterface $streamMock): MockInterface { $mockedHttpResponse = $this->mocker->mockCollaborator(ResponseInterface::class); - $mockedHttpResponse->shouldReceive('getStatusCode')->once()->andReturn($statusCode); - $mockedHttpResponse->shouldReceive('getBody')->once()->andReturn($streamMock); + $mockedHttpResponse->expects('getStatusCode')->andReturns($statusCode); + $mockedHttpResponse->expects('getBody')->andReturns($streamMock); return $mockedHttpResponse; } diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php index 6bc6d8243b..0acf1e7922 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php @@ -13,18 +13,36 @@ declare(strict_types=1); namespace Sylius\Bundle\ApiBundle\Command\Payment; -use Sylius\Bundle\ApiBundle\Command\CustomerEmailAwareInterface; use Sylius\Bundle\ApiBundle\Command\IriToIdentifierConversionAwareInterface; -use Sylius\Bundle\ApiBundle\Command\PaymentMethodCodeAwareInterface; /** @experimental */ class AddPaymentRequest implements IriToIdentifierConversionAwareInterface { public function __construct( - public string $type, - public mixed $requestPayload, - public ?string $paymentId, - public ?string $paymentMethodCode, + private string $paymentId, + private string $paymentMethodCode, + private string $type, + private mixed $requestPayload = null, ) { } + + public function getPaymentId(): string + { + return $this->paymentId; + } + + public function getPaymentMethodCode(): string + { + return $this->paymentMethodCode; + } + + public function getType(): string + { + return $this->type; + } + + public function getRequestPayload(): mixed + { + return $this->requestPayload; + } } diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/StatusPaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/StatusPaymentRequest.php deleted file mode 100644 index f014a9fed4..0000000000 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/Offline/StatusPaymentRequest.php +++ /dev/null @@ -1,34 +0,0 @@ -hash; - } - - public function setHash(string $hash): void - { - $this->hash = $hash; - } -} diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/UpdatePaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/UpdatePaymentRequest.php new file mode 100644 index 0000000000..9250d43aa8 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/UpdatePaymentRequest.php @@ -0,0 +1,43 @@ +requestPayload; + } + + public function getHash(): ?string + { + return $this->hash; + } + + public function setHash(?string $hash): void + { + $this->hash = $hash; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Command/PaymentRequestHashAwareInterface.php b/src/Sylius/Bundle/ApiBundle/Command/PaymentRequestHashAwareInterface.php index f2e075002a..ca52ce4df7 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/PaymentRequestHashAwareInterface.php +++ b/src/Sylius/Bundle/ApiBundle/Command/PaymentRequestHashAwareInterface.php @@ -14,9 +14,9 @@ declare(strict_types=1); namespace Sylius\Bundle\ApiBundle\Command; /** @experimental */ -interface PaymentRequestHashAwareInterface +interface PaymentRequestHashAwareInterface extends CommandAwareDataTransformerInterface { - public function getHash(): string; + public function getHash(): ?string; - public function setHash(string $hash): void; + public function setHash(?string $hash): void; } diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index cb10665cc7..d6d86c537a 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -13,10 +13,9 @@ declare(strict_types=1); namespace Sylius\Bundle\ApiBundle\CommandHandler\Payment; -use Doctrine\Persistence\ObjectManager; use Sylius\Bundle\ApiBundle\Command\Payment\AddPaymentRequest; use Sylius\Bundle\ApiBundle\Exception\PaymentRequestNotSupportedException; -use Sylius\Bundle\ApiBundle\Payment\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; @@ -34,7 +33,6 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface private FactoryInterface $paymentRequestFactory, private PaymentMethodRepositoryInterface $paymentMethodRepository, private PaymentRepositoryInterface $paymentRepository, - private ObjectManager $paymentRequestManager, private PaymentRequestCommandProviderInterface $paymentRequestCommandProvider, private MessageBusInterface $commandBus, ) { @@ -47,7 +45,7 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface throw new PaymentRequestNotSupportedException(); } - $command = $this->paymentRequestCommandProvider->handle($paymentRequest); + $command = $this->paymentRequestCommandProvider->provide($paymentRequest); $this->commandBus->dispatch($command); @@ -57,20 +55,28 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface private function createPaymentRequest(AddPaymentRequest $addPaymentRequest): PaymentRequestInterface { /** @var PaymentMethodInterface|null $paymentMethod */ - $paymentMethod = $this->paymentMethodRepository->findOneBy(['code' => $addPaymentRequest->paymentMethodCode]); - Assert::notNull($paymentMethod); + $paymentMethod = $this->paymentMethodRepository->findOneBy([ + 'code' => $addPaymentRequest->getPaymentMethodCode() + ]); + Assert::notNull($paymentMethod, sprintf( + 'Payment method code "%s", can not be found!', + $addPaymentRequest->getPaymentMethodCode() + )); /** @var PaymentInterface|null $payment */ - $payment = $this->paymentRepository->find($addPaymentRequest->paymentId); - Assert::notNull($payment); + $payment = $this->paymentRepository->find($addPaymentRequest->getPaymentId()); + Assert::notNull( + $payment, + sprintf('Payment ID "%s" can not be found!', $addPaymentRequest->getPaymentId()) + ); /** @var PaymentRequestInterface $paymentRequest */ $paymentRequest = $this->paymentRequestFactory->createNew(); $paymentRequest->setPayment($payment); $paymentRequest->setMethod($paymentMethod); - $paymentRequest->setType($addPaymentRequest->type); - $paymentRequest->setRequestPayload($addPaymentRequest->requestPayload); + $paymentRequest->setType($addPaymentRequest->getType()); + $paymentRequest->setRequestPayload($addPaymentRequest->getRequestPayload()); - $this->paymentRequestManager->persist($paymentRequest); + $this->paymentRepository->add($paymentRequest); return $paymentRequest; } } diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php new file mode 100644 index 0000000000..170e75a01b --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php @@ -0,0 +1,54 @@ +getHash(); + Assert::notNull($hash); + /** @var PaymentRequestInterface $paymentRequest */ + $paymentRequest = $this->paymentRequestRepository->find($hash); + + $paymentRequest->setRequestPayload($updatePaymentRequest->getRequestPayload()); + + if (!$this->paymentRequestCommandProvider->supports($paymentRequest)) { + throw new PaymentRequestNotSupportedException(); + } + + $command = $this->paymentRequestCommandProvider->provide($paymentRequest); + + $this->commandBus->dispatch($command); + + return $paymentRequest; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/DataTransformer/PaymentRequestHashAwareInputCommandDataTransformer.php b/src/Sylius/Bundle/ApiBundle/DataTransformer/PaymentRequestHashAwareInputCommandDataTransformer.php new file mode 100644 index 0000000000..2b2591abc4 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/DataTransformer/PaymentRequestHashAwareInputCommandDataTransformer.php @@ -0,0 +1,36 @@ +setHash($paymentRequest->getHash()); + + return $object; + } + + public function supportsTransformation($object): bool + { + return $object instanceof PaymentRequestHashAwareInterface; + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml index 9b05ee9b12..659ad5a262 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml @@ -40,10 +40,10 @@ input Sylius\Bundle\ApiBundle\Command\Payment\AddPaymentRequest - shop:product_review:create + shop:payment_request:create - shop:product_review:read + shop:payment_request:read @@ -56,6 +56,21 @@ shop:payment_request:read + + + PUT + /shop/payment-requests/{hash} + input + Sylius\Bundle\ApiBundle\Command\Payment\UpdatePaymentRequest + + shop:payment_request:update + + + + shop:payment_request:read + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml index ce75fb1877..62ce8a8c04 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml @@ -16,19 +16,16 @@ xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd" > - - shop:payment_request:create - - - shop:payment_request:create - shop:payment_request:create shop:payment_request:create - + + shop:payment_request:create + + shop:payment_request:create diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/UpdatePaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/UpdatePaymentRequest.xml new file mode 100644 index 0000000000..65bd2e1abc --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/UpdatePaymentRequest.xml @@ -0,0 +1,23 @@ + + + + + + + + shop:payment_request:update + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services.xml index 0e37411843..b50b971f63 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services.xml @@ -69,6 +69,10 @@ + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml index 5d7412ea2f..948afa00ad 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml @@ -240,11 +240,18 @@ - + - - + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml index 377da87e5f..18c92fc7ec 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/payments.xml @@ -23,18 +23,5 @@ - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ApiBundle/SyliusApiBundle.php b/src/Sylius/Bundle/ApiBundle/SyliusApiBundle.php index 50bb0ca71a..f74852f938 100644 --- a/src/Sylius/Bundle/ApiBundle/SyliusApiBundle.php +++ b/src/Sylius/Bundle/ApiBundle/SyliusApiBundle.php @@ -17,7 +17,6 @@ use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\CommandDataTransformerP use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\ExtractorMergingCompilerPass; use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\FlattenExceptionNormalizerDecoratorCompilerPass; use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\LegacyErrorHandlingCompilerPass; -use Sylius\Bundle\ApiBundle\DependencyInjection\Compiler\PaymentRequestCommandProviderPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -28,7 +27,6 @@ final class SyliusApiBundle extends Bundle $container->addCompilerPass(new CommandDataTransformerPass()); $container->addCompilerPass(new FlattenExceptionNormalizerDecoratorCompilerPass()); $container->addCompilerPass(new LegacyErrorHandlingCompilerPass()); - $container->addCompilerPass(new PaymentRequestCommandProviderPass()); $container->addCompilerPass(new ExtractorMergingCompilerPass()); } } diff --git a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php index 98797e75c1..42cb38aeaa 100644 --- a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php +++ b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php @@ -13,13 +13,12 @@ declare(strict_types=1); namespace Sylius\Component\Payment\Repository; -use Sylius\Component\Payment\Model\PaymentInterface; -use Sylius\Component\Payment\Model\PaymentMethodInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; + interface PaymentRequestRepositoryInterface { /** * @return PaymentRequestInterface[] */ - public function findExisting(PaymentInterface $payment, PaymentMethodInterface $paymentMethod, string $type): array; + public function findOtherExisting(PaymentRequestInterface $paymentRequest): array; } From a7154bdbaf5d43c50af83a31654ad22fc57da99b Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 1 Feb 2024 11:22:05 +0100 Subject: [PATCH 013/200] Attempt to get a real object instead of proxy one --- .../Payment/UpdatePaymentRequestHandler.php | 5 +++-- .../Doctrine/ORM/PaymentRequestRepository.php | 14 ++++++++++++++ .../PaymentRequestRepositoryInterface.php | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php index 170e75a01b..4a6eec2f7f 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php @@ -36,8 +36,9 @@ final class UpdatePaymentRequestHandler implements MessageHandlerInterface { $hash = $updatePaymentRequest->getHash(); Assert::notNull($hash); - /** @var PaymentRequestInterface $paymentRequest */ - $paymentRequest = $this->paymentRequestRepository->find($hash); + + $paymentRequest = $this->paymentRequestRepository->findOneByHash($hash); + Assert::notNull($paymentRequest); $paymentRequest->setRequestPayload($updatePaymentRequest->getRequestPayload()); diff --git a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php index 77b2a5fe4d..25a6cabc0a 100644 --- a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php +++ b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php @@ -36,4 +36,18 @@ class PaymentRequestRepository extends EntityRepository implements PaymentReques ->getResult() ; } + + public function findOneByHash(string $hash): ?PaymentRequestInterface + { + return $this->createQueryBuilder('o') + ->addSelect('payment') + ->addSelect('method') + ->innerJoin('o.payment', 'payment') + ->innerJoin('o.method', 'method') + ->where('o.hash = :hash') + ->setParameter('hash', $hash) + ->getQuery() + ->getOneOrNullResult() + ; + } } diff --git a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php index 42cb38aeaa..9c7c5381e0 100644 --- a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php +++ b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php @@ -21,4 +21,6 @@ interface PaymentRequestRepositoryInterface * @return PaymentRequestInterface[] */ public function findOtherExisting(PaymentRequestInterface $paymentRequest): array; + + public function findOneByHash(string $hash): ?PaymentRequestInterface; } From df7111d773ca43348e9beae739df39d15ff81afb Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 1 Feb 2024 20:03:52 +0100 Subject: [PATCH 014/200] Pay with PayPal via authorize working --- .../Behat/Context/Api/PaypalContext.php | 48 +++++++++-------- .../Payment/AddPaymentRequestHandler.php | 8 ++- .../config/services/command_handlers.xml | 2 +- .../config/services/fixtures_factories.xml | 2 +- .../Doctrine/ORM/PaymentRequestRepository.php | 5 ++ .../Resources/config/services.xml | 5 ++ .../SyliusGetHttpRequestAction.php | 4 +- .../SyliusRenderTemplateAction.php | 4 +- .../AuthorizePaymentRequestHandler.php | 18 ++++--- .../CapturePaymentRequestHandler.php | 16 +++--- .../StatusPaymentRequestHandler.php | 15 +++--- ...tContext.php => PaymentRequestContext.php} | 2 +- ...php => PaymentRequestContextInterface.php} | 2 +- .../AfterTokenizedRequestProcessor.php | 50 +++++++++++++++++ ...fterTokenizedRequestProcessorInterface.php | 16 ++++++ ...uestProcessor.php => RequestProcessor.php} | 21 ++------ ...face.php => RequestProcessorInterface.php} | 2 +- ...vider.php => AuthorizeCommandProvider.php} | 2 +- ...rovider.php => CaptureCommandProvider.php} | 2 +- .../Provider/PaymentRequestProvider.php | 49 +++++++++++++++++ .../PaymentRequestProviderInterface.php | 12 +++++ ...Provider.php => StatusCommandProvider.php} | 2 +- .../Resources/config/integrations/offline.xml | 4 +- .../config/integrations/payment_request.xml | 30 ++++++++--- .../integrations/paypal_express_checkout.xml | 6 +-- .../Resources/config/integrations/stripe.xml | 6 +-- .../Payment/Factory/PaymentRequestFactory.php | 54 +++++++++++++++++++ .../PaymentRequestFactoryInterface.php | 31 +++++++++++ .../PaymentRequestRepositoryInterface.php | 8 ++- 29 files changed, 327 insertions(+), 99 deletions(-) rename src/Sylius/Bundle/PayumBundle/PaymentRequest/{PayumPaymentRequestContext.php => PaymentRequestContext.php} (90%) rename src/Sylius/Bundle/PayumBundle/PaymentRequest/{PayumPaymentRequestContextInterface.php => PaymentRequestContextInterface.php} (92%) create mode 100644 src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessor.php create mode 100644 src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php rename src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/{PayumRequestProcessor.php => RequestProcessor.php} (59%) rename src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/{PayumRequestProcessorInterface.php => RequestProcessorInterface.php} (93%) rename src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/{PayumAuthorizePaymentRequestCommandProvider.php => AuthorizeCommandProvider.php} (85%) rename src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/{PayumCapturePaymentRequestCommandProvider.php => CaptureCommandProvider.php} (86%) create mode 100644 src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProvider.php create mode 100644 src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProviderInterface.php rename src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/{PayumStatusPaymentRequestCommandProvider.php => StatusCommandProvider.php} (86%) create mode 100644 src/Sylius/Component/Payment/Factory/PaymentRequestFactory.php create mode 100644 src/Sylius/Component/Payment/Factory/PaymentRequestFactoryInterface.php diff --git a/src/Sylius/Behat/Context/Api/PaypalContext.php b/src/Sylius/Behat/Context/Api/PaypalContext.php index b72f57e4eb..06645c1654 100644 --- a/src/Sylius/Behat/Context/Api/PaypalContext.php +++ b/src/Sylius/Behat/Context/Api/PaypalContext.php @@ -61,28 +61,7 @@ final class PaypalContext implements Context public function iSignInToPaypalAndAuthorizeSuccessfully(): void { $this->paypalApiMocker->performActionInApiSuccessfulScope(function () { - $uri = $this->sharedStorage->get('payment_request_uri'); - $request = $this->requestFactory->custom( - $uri, - HttpRequest::METHOD_PUT, - [], - $this->client->getToken(), - ); - - $request->setContent([ - 'requestPayload' => [ - 'target_path' => 'https://myshop.tld/target-path', - 'after_path' => 'https://myshop.tld/after-path', - 'http_request' => [ - 'query' => [ - 'token'=>'EC-2d9EV13959UR209410U', - 'PayerID'=>'UX8WBNYWGBVMG', - ] - ], - ], - ]); - - $this->client->executeCustomRequest($request); + $this->putPaymentRequest($this->sharedStorage->get('payment_request_uri')); }); } @@ -180,4 +159,29 @@ final class PaypalContext implements Context $this->client->executeCustomRequest($request); } + + function putPaymentRequest(string $paymentRequestUri): void + { + $request = $this->requestFactory->custom( + $paymentRequestUri, + HttpRequest::METHOD_PUT, + [], + $this->client->getToken(), + ); + + $request->setContent([ + 'requestPayload' => [ + 'target_path' => 'https://myshop.tld/target-path', + 'after_path' => 'https://myshop.tld/after-path', + 'http_request' => [ + 'query' => [ + 'token' => 'EC-2d9EV13959UR209410U', + 'PayerID' => 'UX8WBNYWGBVMG', + ] + ], + ], + ]); + + $this->client->executeCustomRequest($request); + } } diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index d6d86c537a..177753c0c0 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -20,6 +20,7 @@ use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; use Sylius\Component\Core\Repository\PaymentRepositoryInterface; +use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Resource\Factory\FactoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; @@ -30,7 +31,7 @@ use Webmozart\Assert\Assert; final class AddPaymentRequestHandler implements MessageHandlerInterface { public function __construct( - private FactoryInterface $paymentRequestFactory, + private PaymentRequestFactoryInterface $paymentRequestFactory, private PaymentMethodRepositoryInterface $paymentMethodRepository, private PaymentRepositoryInterface $paymentRepository, private PaymentRequestCommandProviderInterface $paymentRequestCommandProvider, @@ -69,10 +70,7 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface sprintf('Payment ID "%s" can not be found!', $addPaymentRequest->getPaymentId()) ); - /** @var PaymentRequestInterface $paymentRequest */ - $paymentRequest = $this->paymentRequestFactory->createNew(); - $paymentRequest->setPayment($payment); - $paymentRequest->setMethod($paymentMethod); + $paymentRequest = $this->paymentRequestFactory->createWithPaymentAndPaymentMethod($payment, $paymentMethod); $paymentRequest->setType($addPaymentRequest->getType()); $paymentRequest->setRequestPayload($addPaymentRequest->getRequestPayload()); diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml index 948afa00ad..2c2eb8facb 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml @@ -240,7 +240,7 @@ - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_factories.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_factories.xml index 90c9ca561a..bcc182fde8 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_factories.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_factories.xml @@ -32,7 +32,7 @@ - + diff --git a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php index 25a6cabc0a..af750bf70f 100644 --- a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php +++ b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php @@ -17,6 +17,11 @@ use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; +/** + * @template T of PaymentRequestInterface + * + * @implements PaymentRequestRepositoryInterface + */ class PaymentRequestRepository extends EntityRepository implements PaymentRequestRepositoryInterface { public function findOtherExisting(PaymentRequestInterface $paymentRequest): array diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml index ed7edb88a9..6bb5900350 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml @@ -31,6 +31,11 @@ + + + + + %sylius.payment_methods_resolver.interface% Payment methods resolver diff --git a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php index e74a88733f..add075ffac 100644 --- a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php +++ b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php @@ -16,13 +16,13 @@ namespace Sylius\Bundle\PayumBundle\Action\PaymentRequest; use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Core\Request\GetHttpRequest; -use Sylius\Bundle\PayumBundle\PaymentRequest\PayumPaymentRequestContextInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\PaymentRequestContextInterface; use Webmozart\Assert\Assert; final class SyliusGetHttpRequestAction implements ActionInterface { public function __construct( - private PayumPaymentRequestContextInterface $payumApiContext, + private PaymentRequestContextInterface $payumApiContext, ) { } diff --git a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php index ebc259c145..759c286539 100644 --- a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php +++ b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php @@ -16,13 +16,13 @@ namespace Sylius\Bundle\PayumBundle\Action\PaymentRequest; use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Core\Request\RenderTemplate; -use Sylius\Bundle\PayumBundle\PaymentRequest\PayumPaymentRequestContextInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\PaymentRequestContextInterface; use Webmozart\Assert\Assert; final class SyliusRenderTemplateAction implements ActionInterface { public function __construct( - private PayumPaymentRequestContextInterface $payumApiContext, + private PaymentRequestContextInterface $payumApiContext, ) { } public function execute($request): void diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php index 27bf23916a..3e5db4a1fc 100644 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php @@ -13,29 +13,31 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\CommandHandler; +use Payum\Core\Security\TokenAggregateInterface; use Sylius\Bundle\PayumBundle\Command\AuthorizePaymentRequest; use Sylius\Bundle\PayumBundle\Factory\AuthorizeRequestFactoryInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Factory\PayumTokenFactoryInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\PayumRequestProcessorInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenizedRequestProcessorInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; final class AuthorizePaymentRequestHandler implements MessageHandlerInterface { public function __construct( - private RepositoryInterface $paymentRequestRepository, + private PaymentRequestProviderInterface $paymentRequestProvider, private PayumTokenFactoryInterface $payumTokenFactory, - private PayumRequestProcessorInterface $payumReplyProcessor, + private RequestProcessorInterface $requestProcessor, private AuthorizeRequestFactoryInterface $factory, + private AfterTokenizedRequestProcessorInterface $afterTokenizedRequestProcessor, ) { } public function __invoke(AuthorizePaymentRequest $command): void { - /** @var PaymentRequestInterface|null $paymentRequest */ - $paymentRequest = $this->paymentRequestRepository->find($command->getHash()); + $paymentRequest = $this->paymentRequestProvider->provideFromHash($command->getHash()); Assert::notNull($paymentRequest); $token = $this->payumTokenFactory->createNew($paymentRequest); @@ -45,6 +47,8 @@ final class AuthorizePaymentRequestHandler implements MessageHandlerInterface $token = $request->getToken(); Assert::notNull($token); - $this->payumReplyProcessor->process($paymentRequest, $request, $token->getGatewayName()); + $this->requestProcessor->process($paymentRequest, $request, $token->getGatewayName()); + + $this->afterTokenizedRequestProcessor->process($paymentRequest, $token); } } diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php index 13df4e965a..e07faefdba 100644 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php @@ -16,26 +16,24 @@ namespace Sylius\Bundle\PayumBundle\CommandHandler; use Sylius\Bundle\PayumBundle\Command\CapturePaymentRequest; use Sylius\Bundle\PayumBundle\Factory\CaptureRequestFactoryInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Factory\PayumTokenFactoryInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\PayumRequestProcessorInterface; -use Sylius\Component\Payment\Model\PaymentRequestInterface; -use Sylius\Component\Resource\Repository\RepositoryInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; final class CapturePaymentRequestHandler implements MessageHandlerInterface { public function __construct( - private RepositoryInterface $paymentRequestRepository, - private PayumTokenFactoryInterface $payumTokenFactory, - private PayumRequestProcessorInterface $payumReplyProcessor, + private PaymentRequestProviderInterface $paymentRequestProvider, + private PayumTokenFactoryInterface $payumTokenFactory, + private RequestProcessorInterface $requestProcessor, private CaptureRequestFactoryInterface $factory, ) { } public function __invoke(CapturePaymentRequest $command): void { - /** @var PaymentRequestInterface|null $paymentRequest */ - $paymentRequest = $this->paymentRequestRepository->find($command->getHash()); + $paymentRequest = $this->paymentRequestProvider->provideFromHash($command->getHash()); Assert::notNull($paymentRequest); $token = $this->payumTokenFactory->createNew($paymentRequest); @@ -45,6 +43,6 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface $token = $request->getToken(); Assert::notNull($token); - $this->payumReplyProcessor->process($paymentRequest, $request, $token->getGatewayName()); + $this->requestProcessor->process($paymentRequest, $request, $token->getGatewayName()); } } diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php index 0f0255f519..d74a7152b6 100644 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php @@ -13,29 +13,26 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\CommandHandler; -use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; use Sylius\Bundle\PayumBundle\Command\StatusPaymentRequest; use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\PayumRequestProcessorInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; -use Sylius\Component\Payment\Model\PaymentRequestInterface; -use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; final class StatusPaymentRequestHandler implements MessageHandlerInterface { public function __construct( - private RepositoryInterface $paymentRequestRepository, - private PayumRequestProcessorInterface $payumReplyProcessor, + private PaymentRequestProviderInterface $paymentRequestProvider, + private RequestProcessorInterface $requestProcessor, private GetStatusFactoryInterface $factory, ) { } public function __invoke(StatusPaymentRequest $command): void { - /** @var PaymentRequestInterface|null $paymentRequest */ - $paymentRequest = $this->paymentRequestRepository->find($command->getHash()); + $paymentRequest = $this->paymentRequestProvider->provideFromHash($command->getHash()); Assert::notNull($paymentRequest); $payment = $paymentRequest->getPayment(); @@ -52,6 +49,6 @@ final class StatusPaymentRequestHandler implements MessageHandlerInterface $gatewayName = $gatewayConfig->getGatewayName(); - $this->payumReplyProcessor->process($paymentRequest, $request, $gatewayName); + $this->requestProcessor->process($paymentRequest, $request, $gatewayName); } } diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContext.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContext.php similarity index 90% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContext.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContext.php index e4f5ae409f..4c8640c2c0 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContext.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContext.php @@ -15,7 +15,7 @@ namespace Sylius\Bundle\PayumBundle\PaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; -final class PayumPaymentRequestContext implements PayumPaymentRequestContextInterface +final class PaymentRequestContext implements PaymentRequestContextInterface { private ?PaymentRequestInterface $paymentRequest = null; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContextInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContextInterface.php similarity index 92% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContextInterface.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContextInterface.php index 1f5aad664d..871cb2f83d 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/PayumPaymentRequestContextInterface.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContextInterface.php @@ -15,7 +15,7 @@ namespace Sylius\Bundle\PayumBundle\PaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; -interface PayumPaymentRequestContextInterface +interface PaymentRequestContextInterface { public function isEnabled(): bool; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessor.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessor.php new file mode 100644 index 0000000000..ba579bbcb5 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessor.php @@ -0,0 +1,50 @@ +getState()) { + return; + } + + $details = $paymentRequest->getResponseData(); + $details['after_url'] = $token->getAfterUrl(); + $paymentRequest->setResponseData($details); + + $newPaymentRequest = $this->paymentRequestFactory->createFromPaymentRequest($paymentRequest); + $newPaymentRequest->setType(PaymentRequestInterface::DATA_TYPE_STATUS); + + $this->paymentRepository->add($newPaymentRequest); + + if (!$this->paymentRequestCommandProvider->supports($newPaymentRequest)) { + throw new PaymentRequestNotSupportedException(); + } + + $command = $this->paymentRequestCommandProvider->provide($newPaymentRequest); + + $this->commandBus->dispatch($command); + } +} diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php new file mode 100644 index 0000000000..26917f4286 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php @@ -0,0 +1,16 @@ +setState(PaymentRequestInterface::STATE_COMPLETED); - - if (false === $request instanceof TokenAggregateInterface) { - return; - } - - $token = $request->getToken(); - if (null === $token) { - return; - } - - $details = $paymentRequest->getResponseData(); - $details['after_url'] = $token->getAfterUrl(); - $paymentRequest->setResponseData($details); } } diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessorInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php similarity index 93% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessorInterface.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php index 4d44304768..2397c18236 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/PayumRequestProcessorInterface.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php @@ -16,7 +16,7 @@ namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor; use Payum\Core\Security\TokenAggregateInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -interface PayumRequestProcessorInterface +interface RequestProcessorInterface { public function process( PaymentRequestInterface $paymentRequest, diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumAuthorizePaymentRequestCommandProvider.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/AuthorizeCommandProvider.php similarity index 85% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumAuthorizePaymentRequestCommandProvider.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/AuthorizeCommandProvider.php index fb79eae89c..0a28108ab2 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumAuthorizePaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/AuthorizeCommandProvider.php @@ -8,7 +8,7 @@ use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\PayumBundle\Command\AuthorizePaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; -final class PayumAuthorizePaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface +final class AuthorizeCommandProvider implements PaymentRequestCommandProviderInterface { public function supports(PaymentRequestInterface $paymentRequest): bool { diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumCapturePaymentRequestCommandProvider.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/CaptureCommandProvider.php similarity index 86% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumCapturePaymentRequestCommandProvider.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/CaptureCommandProvider.php index b56c99e53c..4adc2c325b 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PayumCapturePaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/CaptureCommandProvider.php @@ -8,7 +8,7 @@ use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\PayumBundle\Command\CapturePaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; -final class PayumCapturePaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface +final class CaptureCommandProvider implements PaymentRequestCommandProviderInterface { public function supports(PaymentRequestInterface $paymentRequest): bool { diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProvider.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProvider.php new file mode 100644 index 0000000000..7f9ca523c1 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProvider.php @@ -0,0 +1,49 @@ +paymentRequestRepository->findOneByHash($hash); + + if (null === $paymentRequest) { + return null; + } + + // Needed to get a real object to give to Payum which is not handling + // Proxy class from Doctrine when a token is created for ex. + $payment = $paymentRequest->getPayment(); + if ($payment instanceof Proxy) { + $this->entityManager->detach($payment); + $payment = $this->entityManager->find(PaymentInterface::class, $payment->getId()); + $paymentRequest->setPayment($payment); + } + + return $paymentRequest; + } +} diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProviderInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProviderInterface.php new file mode 100644 index 0000000000..30f87f1d60 --- /dev/null +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProviderInterface.php @@ -0,0 +1,12 @@ + - + - + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml index f9257b4925..9964dcf6ab 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml @@ -18,42 +18,56 @@ - + + + + + + + + + + + + + - + - + - + - + + - - + + - + + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml index f3aa832f81..167e282ec3 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml @@ -23,15 +23,15 @@ - + - + - + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml index 27b0a32360..2ec2316e93 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml @@ -23,15 +23,15 @@ - + - + - + diff --git a/src/Sylius/Component/Payment/Factory/PaymentRequestFactory.php b/src/Sylius/Component/Payment/Factory/PaymentRequestFactory.php new file mode 100644 index 0000000000..5c65ab32a1 --- /dev/null +++ b/src/Sylius/Component/Payment/Factory/PaymentRequestFactory.php @@ -0,0 +1,54 @@ + + */ +final class PaymentRequestFactory implements PaymentRequestFactoryInterface +{ + public function __construct(private FactoryInterface $factory) + { + } + + public function createNew(): PaymentRequestInterface + { + return $this->factory->createNew(); + } + + public function createWithPaymentAndPaymentMethod(PaymentInterface $payment, PaymentMethodInterface $paymentMethod): PaymentRequestInterface + { + $paymentRequest = $this->createNew(); + + $paymentRequest->setPayment($payment); + $paymentRequest->setMethod($paymentMethod); + + return $paymentRequest; + } + + public function createFromPaymentRequest(PaymentRequestInterface $paymentRequest): PaymentRequestInterface + { + $newPaymentRequest = $this->createNew(); + + $newPaymentRequest->setPayment($paymentRequest->getPayment()); + $newPaymentRequest->setMethod($paymentRequest->getMethod()); + + return $newPaymentRequest; + } +} diff --git a/src/Sylius/Component/Payment/Factory/PaymentRequestFactoryInterface.php b/src/Sylius/Component/Payment/Factory/PaymentRequestFactoryInterface.php new file mode 100644 index 0000000000..2b0243783a --- /dev/null +++ b/src/Sylius/Component/Payment/Factory/PaymentRequestFactoryInterface.php @@ -0,0 +1,31 @@ + + */ +interface PaymentRequestFactoryInterface extends FactoryInterface +{ + public function createWithPaymentAndPaymentMethod(PaymentInterface $payment, PaymentMethodInterface $paymentMethod): PaymentRequestInterface; + + public function createFromPaymentRequest(PaymentRequestInterface $paymentRequest): PaymentRequestInterface; +} diff --git a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php index 9c7c5381e0..00331ede59 100644 --- a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php +++ b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php @@ -14,8 +14,14 @@ declare(strict_types=1); namespace Sylius\Component\Payment\Repository; use Sylius\Component\Payment\Model\PaymentRequestInterface; +use Sylius\Component\Resource\Repository\RepositoryInterface; -interface PaymentRequestRepositoryInterface +/** + * @template T of PaymentRequestInterface + * + * @extends RepositoryInterface + */ +interface PaymentRequestRepositoryInterface extends RepositoryInterface { /** * @return PaymentRequestInterface[] From be639b907c98a1dda076c14c9052922ccf908156 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 1 Feb 2024 23:07:41 +0100 Subject: [PATCH 015/200] Refactor some repeated processes and fix ECS --- .../Payment/AddPaymentRequestHandler.php | 22 +++----- .../Payment/UpdatePaymentRequestHandler.php | 15 ++---- .../config/api_resources/PaymentRequest.xml | 8 +-- .../config/serialization/PaymentRequest.xml | 54 ++++++++++++------- .../config/services/command_handlers.xml | 6 +-- .../PaymentRequestDuplicationChecker.php | 9 ++++ ...mentRequestDuplicationCheckerInterface.php | 9 ++++ .../PaymentRequestCommandDispatcher.php | 48 +++++++++++++++++ ...ymentRequestCommandDispatcherInterface.php | 23 ++++++++ .../Offline/CapturePaymentRequestHandler.php | 27 +++------- .../PaymentRequestNotSupportedException.php | 2 +- .../AfterOfflineCaptureProcessor.php | 40 ++++++++++++++ .../AfterOfflineCaptureProcessorInterface.php | 21 ++++++++ ...PaymentRequestCommandProviderInterface.php | 9 ++++ .../PaymentRequestTypeCommandProvider.php | 9 ++++ .../Resources/config/services.xml | 1 + .../config/services/command_dispatcher.xml | 28 ++++++++++ .../Resources/config/services/offline.xml | 5 +- .../SyliusGetHttpRequestAction.php | 2 +- .../SyliusRenderTemplateAction.php | 3 +- .../CapturePaymentRequestHandler.php | 48 ----------------- ...ler.php => ModelPaymentRequestHandler.php} | 6 +-- ...ler.php => TokenPaymentRequestHandler.php} | 14 +++-- .../PayumBundle/Factory/AuthorizeFactory.php | 11 +++- .../AuthorizeRequestFactoryInterface.php | 13 ----- .../PayumBundle/Factory/CaptureFactory.php | 11 +++- .../Factory/GetStatusFactoryInterface.php | 2 +- .../ModelAggregateRequestFactoryInterface.php | 21 ++++++++ ...TokenAggregateRequestFactoryInterface.php} | 11 +++- .../AfterTokenizedRequestProcessor.php | 28 +++++----- ...fterTokenizedRequestProcessorInterface.php | 9 ++++ .../Processor/RequestProcessorInterface.php | 2 +- .../Provider/AuthorizeCommandProvider.php | 9 ++++ .../Provider/CaptureCommandProvider.php | 9 ++++ .../PaymentRequestProviderInterface.php | 9 ++++ .../Provider/StatusCommandProvider.php | 9 ++++ .../config/integrations/payment_request.xml | 39 +++++++------- .../Resources/config/services/factory.xml | 2 +- .../Payment/spec/Model/PaymentRequestSpec.php | 2 +- 39 files changed, 405 insertions(+), 191 deletions(-) create mode 100644 src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcher.php create mode 100644 src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php rename src/Sylius/Bundle/{ApiBundle => PaymentBundle}/Exception/PaymentRequestNotSupportedException.php (92%) create mode 100644 src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php create mode 100644 src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessorInterface.php create mode 100644 src/Sylius/Bundle/PaymentBundle/Resources/config/services/command_dispatcher.xml delete mode 100644 src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php rename src/Sylius/Bundle/PayumBundle/CommandHandler/{StatusPaymentRequestHandler.php => ModelPaymentRequestHandler.php} (87%) rename src/Sylius/Bundle/PayumBundle/CommandHandler/{AuthorizePaymentRequestHandler.php => TokenPaymentRequestHandler.php} (75%) delete mode 100644 src/Sylius/Bundle/PayumBundle/Factory/AuthorizeRequestFactoryInterface.php create mode 100644 src/Sylius/Bundle/PayumBundle/Factory/ModelAggregateRequestFactoryInterface.php rename src/Sylius/Bundle/PayumBundle/Factory/{CaptureRequestFactoryInterface.php => TokenAggregateRequestFactoryInterface.php} (50%) diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index 177753c0c0..b182c3c551 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -14,17 +14,14 @@ declare(strict_types=1); namespace Sylius\Bundle\ApiBundle\CommandHandler\Payment; use Sylius\Bundle\ApiBundle\Command\Payment\AddPaymentRequest; -use Sylius\Bundle\ApiBundle\Exception\PaymentRequestNotSupportedException; -use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\PaymentBundle\CommandDispatcher\PaymentRequestCommandDispatcherInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; use Sylius\Component\Core\Repository\PaymentRepositoryInterface; use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -use Sylius\Component\Resource\Factory\FactoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; -use Symfony\Component\Messenger\MessageBusInterface; use Webmozart\Assert\Assert; /** @experimental */ @@ -34,21 +31,15 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface private PaymentRequestFactoryInterface $paymentRequestFactory, private PaymentMethodRepositoryInterface $paymentMethodRepository, private PaymentRepositoryInterface $paymentRepository, - private PaymentRequestCommandProviderInterface $paymentRequestCommandProvider, - private MessageBusInterface $commandBus, + private PaymentRequestCommandDispatcherInterface $paymentRequestCommandDispatcher, ) { } public function __invoke(AddPaymentRequest $addPaymentRequest): PaymentRequestInterface { $paymentRequest = $this->createPaymentRequest($addPaymentRequest); - if (!$this->paymentRequestCommandProvider->supports($paymentRequest)) { - throw new PaymentRequestNotSupportedException(); - } - $command = $this->paymentRequestCommandProvider->provide($paymentRequest); - - $this->commandBus->dispatch($command); + $this->paymentRequestCommandDispatcher->add($paymentRequest); return $paymentRequest; } @@ -57,24 +48,23 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface { /** @var PaymentMethodInterface|null $paymentMethod */ $paymentMethod = $this->paymentMethodRepository->findOneBy([ - 'code' => $addPaymentRequest->getPaymentMethodCode() + 'code' => $addPaymentRequest->getPaymentMethodCode(), ]); Assert::notNull($paymentMethod, sprintf( 'Payment method code "%s", can not be found!', - $addPaymentRequest->getPaymentMethodCode() + $addPaymentRequest->getPaymentMethodCode(), )); /** @var PaymentInterface|null $payment */ $payment = $this->paymentRepository->find($addPaymentRequest->getPaymentId()); Assert::notNull( $payment, - sprintf('Payment ID "%s" can not be found!', $addPaymentRequest->getPaymentId()) + sprintf('Payment ID "%s" can not be found!', $addPaymentRequest->getPaymentId()), ); $paymentRequest = $this->paymentRequestFactory->createWithPaymentAndPaymentMethod($payment, $paymentMethod); $paymentRequest->setType($addPaymentRequest->getType()); $paymentRequest->setRequestPayload($addPaymentRequest->getRequestPayload()); - $this->paymentRepository->add($paymentRequest); return $paymentRequest; } } diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php index 4a6eec2f7f..fcd4301cc9 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php @@ -14,12 +14,10 @@ declare(strict_types=1); namespace Sylius\Bundle\ApiBundle\CommandHandler\Payment; use Sylius\Bundle\ApiBundle\Command\Payment\UpdatePaymentRequest; -use Sylius\Bundle\ApiBundle\Exception\PaymentRequestNotSupportedException; -use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\PaymentBundle\CommandDispatcher\PaymentRequestCommandDispatcherInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; -use Symfony\Component\Messenger\MessageBusInterface; use Webmozart\Assert\Assert; /** @experimental */ @@ -27,8 +25,7 @@ final class UpdatePaymentRequestHandler implements MessageHandlerInterface { public function __construct( private PaymentRequestRepositoryInterface $paymentRequestRepository, - private PaymentRequestCommandProviderInterface $paymentRequestCommandProvider, - private MessageBusInterface $commandBus, + private PaymentRequestCommandDispatcherInterface $paymentRequestCommandDispatcher, ) { } @@ -42,13 +39,7 @@ final class UpdatePaymentRequestHandler implements MessageHandlerInterface $paymentRequest->setRequestPayload($updatePaymentRequest->getRequestPayload()); - if (!$this->paymentRequestCommandProvider->supports($paymentRequest)) { - throw new PaymentRequestNotSupportedException(); - } - - $command = $this->paymentRequestCommandProvider->provide($paymentRequest); - - $this->commandBus->dispatch($command); + $this->paymentRequestCommandDispatcher->add($paymentRequest); return $paymentRequest; } diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml index 659ad5a262..d9a548c385 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml @@ -30,7 +30,7 @@ sylius.api.search_payment_request_filter - admin:payment_request:read + admin:payment_request:show @@ -43,7 +43,7 @@ shop:payment_request:create - shop:payment_request:read + shop:payment_request:show @@ -53,7 +53,7 @@ GET /shop/payment-requests/{hash} - shop:payment_request:read + shop:payment_request:show @@ -67,7 +67,7 @@ - shop:payment_request:read + shop:payment_request:show diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml index dd280a5e69..009c851f2f 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml @@ -17,40 +17,58 @@ > - admin:payment_request:read - shop:payment_request:read + admin:payment_request:show + admin:payment_request:index + shop:payment_request:show + shop:payment_request:index - admin:payment_request:read - shop:payment_request:read + admin:payment_request:show + admin:payment_request:index + shop:payment_request:show + shop:payment_request:index - admin:payment_request:read - shop:payment_request:read + admin:payment_request:show + admin:payment_request:index + shop:payment_request:show + shop:payment_request:index - admin:payment_request:read - shop:payment_request:read + admin:payment_request:show + admin:payment_request:index + shop:payment_request:show + shop:payment_request:index - admin:payment_request:read - shop:payment_request:read + admin:payment_request:show + admin:payment_request:index + shop:payment_request:show + shop:payment_request:index - admin:payment_request:read - shop:payment_request:read + admin:payment_request:show + admin:payment_request:index + shop:payment_request:show + shop:payment_request:index - admin:payment_request:read - shop:payment_request:read + admin:payment_request:show + admin:payment_request:index + shop:payment_request:show + shop:payment_request:index - admin:payment_request:read - shop:payment_request:read + admin:payment_request:show + admin:payment_request:index + shop:payment_request:show + shop:payment_request:index - admin:payment_request:read - shop:payment_request:read + admin:payment_request:show + admin:payment_request:index + shop:payment_request:show + shop:payment_request:index diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml index 2c2eb8facb..811701d6f4 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml @@ -243,16 +243,14 @@ - - + - - + diff --git a/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php b/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php index 1fd79df091..0a44de5ed4 100644 --- a/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php +++ b/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php @@ -1,5 +1,14 @@ paymentRequestRepository->add($paymentRequest); + + $this->update($paymentRequest); + } + + public function update(PaymentRequestInterface $paymentRequest): void + { + if (!$this->paymentRequestCommandProvider->supports($paymentRequest)) { + throw new PaymentRequestNotSupportedException(); + } + + $command = $this->paymentRequestCommandProvider->provide($paymentRequest); + + $this->commandBus->dispatch($command); + } +} diff --git a/src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php b/src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php new file mode 100644 index 0000000000..13eb34b222 --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php @@ -0,0 +1,23 @@ +paymentRequestRepository->find($capturePaymentRequest->getHash()); + $paymentRequest = $this->paymentRequestRepository->findOneByHash($capturePaymentRequest->getHash()); Assert::notNull($paymentRequest); /** @var PaymentMethodInterface|null $paymentMethod */ @@ -53,15 +50,7 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface $payment = $paymentRequest->getPayment(); Assert::notNull($payment); - $this->capturePaymentRequestProcessor->process($paymentRequest); - - // @todo modify Payment->getDetails() to retrieve last payment request `responseData` - - $stateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH); - if ($paymentRequest->getResponseData()['paid']) { - $stateMachine->apply(PaymentTransitions::TRANSITION_COMPLETE); - } else { - $stateMachine->apply(PaymentTransitions::TRANSITION_PROCESS); - } + $this->offlineCaptureProcessor->process($paymentRequest); + $this->afterOfflineCaptureProcessor->process($paymentRequest); } } diff --git a/src/Sylius/Bundle/ApiBundle/Exception/PaymentRequestNotSupportedException.php b/src/Sylius/Bundle/PaymentBundle/Exception/PaymentRequestNotSupportedException.php similarity index 92% rename from src/Sylius/Bundle/ApiBundle/Exception/PaymentRequestNotSupportedException.php rename to src/Sylius/Bundle/PaymentBundle/Exception/PaymentRequestNotSupportedException.php index bf31ca989b..e7460fc3eb 100644 --- a/src/Sylius/Bundle/ApiBundle/Exception/PaymentRequestNotSupportedException.php +++ b/src/Sylius/Bundle/PaymentBundle/Exception/PaymentRequestNotSupportedException.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Exception; +namespace Sylius\Bundle\PaymentBundle\Exception; /** @experimental */ final class PaymentRequestNotSupportedException extends \RuntimeException diff --git a/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php b/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php new file mode 100644 index 0000000000..a133704e7b --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php @@ -0,0 +1,40 @@ +getPayment(); + Assert::notNull($payment); + + $stateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH); + if ($paymentRequest->getResponseData()['paid']) { + $stateMachine->apply(PaymentTransitions::TRANSITION_COMPLETE); + } else { + $stateMachine->apply(PaymentTransitions::TRANSITION_PROCESS); + } + } +} diff --git a/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessorInterface.php b/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessorInterface.php new file mode 100644 index 0000000000..22af327d5a --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessorInterface.php @@ -0,0 +1,21 @@ + + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/command_dispatcher.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/command_dispatcher.xml new file mode 100644 index 0000000000..c21b39ee50 --- /dev/null +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/command_dispatcher.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml index d81f5f7a86..e1159d7e56 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml @@ -34,12 +34,15 @@ - + + + + diff --git a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php index add075ffac..3721540fa8 100644 --- a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php +++ b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php @@ -28,7 +28,7 @@ final class SyliusGetHttpRequestAction implements ActionInterface public function execute($request): void { - /** @var $request GetHttpRequest */ + /** @var GetHttpRequest $request */ RequestNotSupportedException::assertSupports($this, $request); $this->updateRequest($request); diff --git a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php index 759c286539..ea522256c4 100644 --- a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php +++ b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php @@ -25,9 +25,10 @@ final class SyliusRenderTemplateAction implements ActionInterface private PaymentRequestContextInterface $payumApiContext, ) { } + public function execute($request): void { - /** @var $request RenderTemplate */ + /** @var RenderTemplate $request */ RequestNotSupportedException::assertSupports($this, $request); $paymentRequest = $this->payumApiContext->getPaymentRequest(); diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php deleted file mode 100644 index e07faefdba..0000000000 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/CapturePaymentRequestHandler.php +++ /dev/null @@ -1,48 +0,0 @@ -paymentRequestProvider->provideFromHash($command->getHash()); - Assert::notNull($paymentRequest); - - $token = $this->payumTokenFactory->createNew($paymentRequest); - - $request = $this->factory->createNewWithToken($token); - - $token = $request->getToken(); - Assert::notNull($token); - - $this->requestProcessor->process($paymentRequest, $request, $token->getGatewayName()); - } -} diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/ModelPaymentRequestHandler.php similarity index 87% rename from src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php rename to src/Sylius/Bundle/PayumBundle/CommandHandler/ModelPaymentRequestHandler.php index d74a7152b6..980eec3a1e 100644 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/StatusPaymentRequestHandler.php +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/ModelPaymentRequestHandler.php @@ -13,7 +13,7 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\CommandHandler; -use Sylius\Bundle\PayumBundle\Command\StatusPaymentRequest; +use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; @@ -21,7 +21,7 @@ use Sylius\Component\Core\Model\PaymentMethodInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; -final class StatusPaymentRequestHandler implements MessageHandlerInterface +final class ModelPaymentRequestHandler implements MessageHandlerInterface { public function __construct( private PaymentRequestProviderInterface $paymentRequestProvider, @@ -30,7 +30,7 @@ final class StatusPaymentRequestHandler implements MessageHandlerInterface ) { } - public function __invoke(StatusPaymentRequest $command): void + public function __invoke(PaymentRequestHashAwareInterface $command): void { $paymentRequest = $this->paymentRequestProvider->provideFromHash($command->getHash()); Assert::notNull($paymentRequest); diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php similarity index 75% rename from src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php rename to src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php index 3e5db4a1fc..a76b3a10e9 100644 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/AuthorizePaymentRequestHandler.php +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php @@ -13,36 +13,34 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\CommandHandler; -use Payum\Core\Security\TokenAggregateInterface; -use Sylius\Bundle\PayumBundle\Command\AuthorizePaymentRequest; -use Sylius\Bundle\PayumBundle\Factory\AuthorizeRequestFactoryInterface; +use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\PayumBundle\Factory\TokenAggregateRequestFactoryInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Factory\PayumTokenFactoryInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenizedRequestProcessorInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; -use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; -final class AuthorizePaymentRequestHandler implements MessageHandlerInterface +final class TokenPaymentRequestHandler implements MessageHandlerInterface { public function __construct( private PaymentRequestProviderInterface $paymentRequestProvider, private PayumTokenFactoryInterface $payumTokenFactory, private RequestProcessorInterface $requestProcessor, - private AuthorizeRequestFactoryInterface $factory, private AfterTokenizedRequestProcessorInterface $afterTokenizedRequestProcessor, + private TokenAggregateRequestFactoryInterface $payumRequestFactory, ) { } - public function __invoke(AuthorizePaymentRequest $command): void + public function __invoke(PaymentRequestHashAwareInterface $command): void { $paymentRequest = $this->paymentRequestProvider->provideFromHash($command->getHash()); Assert::notNull($paymentRequest); $token = $this->payumTokenFactory->createNew($paymentRequest); - $request = $this->factory->createNewWithToken($token); + $request = $this->payumRequestFactory->createNewWithToken($token); $token = $request->getToken(); Assert::notNull($token); diff --git a/src/Sylius/Bundle/PayumBundle/Factory/AuthorizeFactory.php b/src/Sylius/Bundle/PayumBundle/Factory/AuthorizeFactory.php index 97a1faf7ce..1946ac30c6 100644 --- a/src/Sylius/Bundle/PayumBundle/Factory/AuthorizeFactory.php +++ b/src/Sylius/Bundle/PayumBundle/Factory/AuthorizeFactory.php @@ -1,5 +1,14 @@ paymentRequestFactory->createFromPaymentRequest($paymentRequest); $newPaymentRequest->setType(PaymentRequestInterface::DATA_TYPE_STATUS); - $this->paymentRepository->add($newPaymentRequest); - - if (!$this->paymentRequestCommandProvider->supports($newPaymentRequest)) { - throw new PaymentRequestNotSupportedException(); - } - - $command = $this->paymentRequestCommandProvider->provide($newPaymentRequest); - - $this->commandBus->dispatch($command); + $this->paymentRequestCommandDispatcher->add($newPaymentRequest); } } diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php index 26917f4286..f97c0b9c92 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php @@ -1,5 +1,14 @@ - - - + - + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - + + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml index ce30756b56..62ee359335 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml @@ -14,7 +14,7 @@ - + diff --git a/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php b/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php index dad5d6a8aa..7b3764573c 100644 --- a/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php +++ b/src/Sylius/Component/Payment/spec/Model/PaymentRequestSpec.php @@ -16,8 +16,8 @@ namespace spec\Sylius\Component\Payment\Model; use PhpSpec\ObjectBehavior; use stdClass; use Sylius\Component\Payment\Model\PaymentInterface; -use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Model\PaymentMethodInterface; +use Sylius\Component\Payment\Model\PaymentRequestInterface; final class PaymentRequestSpec extends ObjectBehavior { From 18358d107b6d54c29e636f2a8a4b6fe573aa181b Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 2 Feb 2024 00:07:40 +0100 Subject: [PATCH 016/200] 3/5 behat tests ok --- .../Behat/Context/Api/PaypalContext.php | 59 ++++++++++++------- .../TokenPaymentRequestHandler.php | 6 +- ...sor.php => AfterTokenRequestProcessor.php} | 2 +- ...> AfterTokenRequestProcessorInterface.php} | 2 +- .../Processor/RequestProcessor.php | 12 ++++ .../config/integrations/payment_request.xml | 4 +- 6 files changed, 56 insertions(+), 29 deletions(-) rename src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/{AfterTokenizedRequestProcessor.php => AfterTokenRequestProcessor.php} (93%) rename src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/{AfterTokenizedRequestProcessorInterface.php => AfterTokenRequestProcessorInterface.php} (91%) diff --git a/src/Sylius/Behat/Context/Api/PaypalContext.php b/src/Sylius/Behat/Context/Api/PaypalContext.php index 06645c1654..cf29190285 100644 --- a/src/Sylius/Behat/Context/Api/PaypalContext.php +++ b/src/Sylius/Behat/Context/Api/PaypalContext.php @@ -57,21 +57,20 @@ final class PaypalContext implements Context /** * @When I sign in to PayPal and authorize successfully - */ - public function iSignInToPaypalAndAuthorizeSuccessfully(): void - { - $this->paypalApiMocker->performActionInApiSuccessfulScope(function () { - $this->putPaymentRequest($this->sharedStorage->get('payment_request_uri')); - }); - } - - /** * @When I sign in to PayPal and pay successfully */ - public function iSignInToPaypalAndPaySuccessfully(): void + public function iSignInToPaypalAndAuthorizeOrPaySuccessfully(): void { $this->paypalApiMocker->performActionInApiSuccessfulScope(function () { - $this->paypalExpressCheckoutPage->pay(); + $this->putPaymentRequest( + $this->sharedStorage->get('payment_request_uri'), + [ + 'query' => [ + 'token' => 'EC-2d9EV13959UR209410U', + 'PayerID' => 'UX8WBNYWGBVMG', + ] + ] + ); }); } @@ -81,7 +80,15 @@ final class PaypalContext implements Context */ public function iCancelMyPaypalPayment(): void { - $this->paypalExpressCheckoutPage->cancel(); + $this->putPaymentRequest( + $this->sharedStorage->get('payment_request_uri'), + [ + 'query' => [ + 'token' => 'EC-2d9EV13959UR209410U', + 'cancelled' => 1, + ] + ] + ); } /** @@ -89,8 +96,15 @@ final class PaypalContext implements Context */ public function iTryToPayAgain(): void { + $this->client->show(Resources::ORDERS, $this->sharedStorage->get('cart_token')); + $this->paypalApiMocker->performActionInApiInitializeScope(function () { - $this->orderDetails->pay(); + $payments = $this->responseChecker->getValue($this->client->getLastResponse(), 'payments'); + $payment = end($payments); + $this->postPaymentRequest($payment); + + $uri = $this->responseChecker->getValue($this->client->getLastResponse(), '@id'); + $this->sharedStorage->set('payment_request_uri', $uri); }); } @@ -99,7 +113,13 @@ final class PaypalContext implements Context */ public function iShouldBeNotifiedThatMyPaymentHasBeenCancelled(): void { - $this->assertNotification('Payment has been cancelled.'); + Assert::true( + $this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()), + sprintf( + 'Payment request could not be updated: %s', + $this->responseChecker->getError($this->client->getLastResponse()), + ), + ); } /** @@ -110,7 +130,7 @@ final class PaypalContext implements Context Assert::true( $this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()), sprintf( - 'Payment request could not be edited: %s', + 'Payment request could not be updated: %s', $this->responseChecker->getError($this->client->getLastResponse()), ), ); @@ -160,7 +180,7 @@ final class PaypalContext implements Context $this->client->executeCustomRequest($request); } - function putPaymentRequest(string $paymentRequestUri): void + function putPaymentRequest(string $paymentRequestUri, array $httpRequest = []): void { $request = $this->requestFactory->custom( $paymentRequestUri, @@ -173,12 +193,7 @@ final class PaypalContext implements Context 'requestPayload' => [ 'target_path' => 'https://myshop.tld/target-path', 'after_path' => 'https://myshop.tld/after-path', - 'http_request' => [ - 'query' => [ - 'token' => 'EC-2d9EV13959UR209410U', - 'PayerID' => 'UX8WBNYWGBVMG', - ] - ], + 'http_request' => $httpRequest, ], ]); diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php b/src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php index a76b3a10e9..e57d4e55fe 100644 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php +++ b/src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php @@ -16,7 +16,7 @@ namespace Sylius\Bundle\PayumBundle\CommandHandler; use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; use Sylius\Bundle\PayumBundle\Factory\TokenAggregateRequestFactoryInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Factory\PayumTokenFactoryInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenizedRequestProcessorInterface; +use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenRequestProcessorInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; @@ -28,7 +28,7 @@ final class TokenPaymentRequestHandler implements MessageHandlerInterface private PaymentRequestProviderInterface $paymentRequestProvider, private PayumTokenFactoryInterface $payumTokenFactory, private RequestProcessorInterface $requestProcessor, - private AfterTokenizedRequestProcessorInterface $afterTokenizedRequestProcessor, + private AfterTokenRequestProcessorInterface $afterTokenRequestProcessor, private TokenAggregateRequestFactoryInterface $payumRequestFactory, ) { } @@ -47,6 +47,6 @@ final class TokenPaymentRequestHandler implements MessageHandlerInterface $this->requestProcessor->process($paymentRequest, $request, $token->getGatewayName()); - $this->afterTokenizedRequestProcessor->process($paymentRequest, $token); + $this->afterTokenRequestProcessor->process($paymentRequest, $token); } } diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessor.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessor.php similarity index 93% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessor.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessor.php index 469d868bf3..50b4dd16af 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessor.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessor.php @@ -18,7 +18,7 @@ use Sylius\Bundle\PaymentBundle\CommandDispatcher\PaymentRequestCommandDispatche use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -final class AfterTokenizedRequestProcessor implements AfterTokenizedRequestProcessorInterface +final class AfterTokenRequestProcessor implements AfterTokenRequestProcessorInterface { public function __construct( private PaymentRequestFactoryInterface $paymentRequestFactory, diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessorInterface.php similarity index 91% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php rename to src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessorInterface.php index f97c0b9c92..a16770dfcc 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenizedRequestProcessorInterface.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessorInterface.php @@ -16,7 +16,7 @@ namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor; use Payum\Core\Security\TokenInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -interface AfterTokenizedRequestProcessorInterface +interface AfterTokenRequestProcessorInterface { public function process( PaymentRequestInterface $paymentRequest, diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessor.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessor.php index e012a2b4cf..816e4013a8 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessor.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessor.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor; use Payum\Core\Payum; +use Payum\Core\Security\TokenAggregateInterface; use Sylius\Bundle\PayumBundle\PaymentRequest\PaymentRequestContextInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; @@ -41,5 +42,16 @@ final class RequestProcessor implements RequestProcessorInterface } $paymentRequest->setState(PaymentRequestInterface::STATE_COMPLETED); + + if (false === $request instanceof TokenAggregateInterface) { + return; + } + + $token = $request->getToken(); + if (null === $token) { + return; + } + + $this->payum->getHttpRequestVerifier()->invalidate($token); } } diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml index addaddd3f4..160ea0255f 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml @@ -28,7 +28,7 @@ - + @@ -41,7 +41,7 @@ - + From 8adbd8b31edaf689ed0281e8895e8c3411b5343e Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 2 Feb 2024 00:08:18 +0100 Subject: [PATCH 017/200] Behat ecs fix --- src/Sylius/Behat/Context/Api/PaypalContext.php | 13 ++++++------- .../Shop/Checkout/CheckoutOrderDetailsContext.php | 2 -- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Sylius/Behat/Context/Api/PaypalContext.php b/src/Sylius/Behat/Context/Api/PaypalContext.php index cf29190285..fb14fb641d 100644 --- a/src/Sylius/Behat/Context/Api/PaypalContext.php +++ b/src/Sylius/Behat/Context/Api/PaypalContext.php @@ -68,8 +68,8 @@ final class PaypalContext implements Context 'query' => [ 'token' => 'EC-2d9EV13959UR209410U', 'PayerID' => 'UX8WBNYWGBVMG', - ] - ] + ], + ], ); }); } @@ -86,8 +86,8 @@ final class PaypalContext implements Context 'query' => [ 'token' => 'EC-2d9EV13959UR209410U', 'cancelled' => 1, - ] - ] + ], + ], ); } @@ -169,8 +169,7 @@ final class PaypalContext implements Context 'paymentMethodCode' => $payment['method'], 'type' => $authorize ? PaymentRequestInterface::DATA_TYPE_AUTHORIZE - : PaymentRequestInterface::DATA_TYPE_CAPTURE - , + : PaymentRequestInterface::DATA_TYPE_CAPTURE, 'requestPayload' => [ 'target_path' => 'https://myshop.tld/target-path', 'after_path' => 'https://myshop.tld/after-path', @@ -180,7 +179,7 @@ final class PaypalContext implements Context $this->client->executeCustomRequest($request); } - function putPaymentRequest(string $paymentRequestUri, array $httpRequest = []): void + public function putPaymentRequest(string $paymentRequestUri, array $httpRequest = []): void { $request = $this->requestFactory->custom( $paymentRequestUri, diff --git a/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php b/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php index 744e06c7cc..f464f6ea41 100644 --- a/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php @@ -16,8 +16,6 @@ namespace Sylius\Behat\Context\Api\Shop\Checkout; use Behat\Behat\Context\Context; use Sylius\Behat\Client\ApiClientInterface; use Sylius\Behat\Client\RequestFactoryInterface; -use Sylius\Behat\Page\Shop\Order\ShowPageInterface; -use Sylius\Behat\Page\Shop\Order\ThankYouPageInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\OrderInterface; use Webmozart\Assert\Assert; From 8bdba2209c964431979872c66f8e624e68ddc43f Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 2 Feb 2024 17:26:51 +0100 Subject: [PATCH 018/200] @paying_for_order&&@api fully working --- ...venting_to_pay_for_cancelled_order.feature | 2 +- ...t_methods_based_on_current_channel.feature | 2 +- .../Checkout/CheckoutOrderDetailsContext.php | 87 ++++++------------- .../config/services/contexts/api/shop.xml | 2 +- .../suites/api/checkout/paying_for_order.yml | 1 + 5 files changed, 30 insertions(+), 64 deletions(-) diff --git a/features/shop/checkout/paying_for_order/preventing_to_pay_for_cancelled_order.feature b/features/shop/checkout/paying_for_order/preventing_to_pay_for_cancelled_order.feature index ff3246c153..aa90747179 100644 --- a/features/shop/checkout/paying_for_order/preventing_to_pay_for_cancelled_order.feature +++ b/features/shop/checkout/paying_for_order/preventing_to_pay_for_cancelled_order.feature @@ -13,7 +13,7 @@ Feature: Preventing to pay for the cancelled order And the store allows paying Offline And there is a customer "sylius@example.com" that placed an order "#00000022" - @ui @no-api + @ui @api Scenario: Not being able to pay for cancelled order Given the customer bought 3 "Iron Maiden T-Shirt" products And the customer chose "Free" shipping method to "United States" with "Offline" payment diff --git a/features/shop/checkout/paying_for_order/viewing_available_payment_methods_based_on_current_channel.feature b/features/shop/checkout/paying_for_order/viewing_available_payment_methods_based_on_current_channel.feature index e92aa3f02c..4db36a7ca4 100644 --- a/features/shop/checkout/paying_for_order/viewing_available_payment_methods_based_on_current_channel.feature +++ b/features/shop/checkout/paying_for_order/viewing_available_payment_methods_based_on_current_channel.feature @@ -30,7 +30,7 @@ Feature: Viewing available payment methods based on current channel And I should see "Bank of America" and "Offline" payment methods But I should not see "Bank of Poland" and "Bank of Universe" payment methods - @api @ui + @ui @api Scenario: Seeing shipping methods that are available in another channel as an logged in customer Given I am a logged in customer And I am in the "Poland" channel diff --git a/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php b/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php index f464f6ea41..c05130fc41 100644 --- a/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php @@ -15,17 +15,20 @@ namespace Sylius\Behat\Context\Api\Shop\Checkout; use Behat\Behat\Context\Context; use Sylius\Behat\Client\ApiClientInterface; -use Sylius\Behat\Client\RequestFactoryInterface; +use Sylius\Behat\Client\ResponseCheckerInterface; +use Sylius\Behat\Context\Api\Resources; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Core\OrderPaymentStates; +use Sylius\Component\Payment\Model\PaymentInterface; use Webmozart\Assert\Assert; final class CheckoutOrderDetailsContext implements Context { public function __construct( - private RequestFactoryInterface $requestFactory, private SharedStorageInterface $sharedStorage, private ApiClientInterface $client, + private ResponseCheckerInterface $responseChecker, ) { } @@ -34,43 +37,8 @@ final class CheckoutOrderDetailsContext implements Context */ public function iWantToBrowseOrderDetailsForThisOrder(OrderInterface $order): void { - $this->orderDetails->open(['tokenValue' => $order->getTokenValue()]); - } - - /** - * @When I try to pay with :paymentMethodName payment method - */ - public function iChangePaymentMethodTo(string $paymentMethodName): void - { - $this->orderDetails->choosePaymentMethod($paymentMethodName); - $this->orderDetails->pay(); - } - - /** - * @When I retry the payment with :paymentMethodName payment method - */ - public function iChangePaymentMethodAfterCheckout(string $paymentMethodName): void - { - $this->thankYouPage->goToTheChangePaymentMethodPage(); - $this->orderDetails->choosePaymentMethod($paymentMethodName); - $this->orderDetails->pay(); - } - - /** - * @When I want to pay for my order - */ - public function iWantToPayForMyOrder(): void - { - $this->thankYouPage->goToTheChangePaymentMethodPage(); - } - - /** - * @When I try to pay for my order - */ - public function iTryToPayForMyOrder(): void - { - $this->thankYouPage->goToTheChangePaymentMethodPage(); - $this->orderDetails->pay(); + $this->sharedStorage->set('cart_token', $order->getTokenValue()); + $this->client->show(Resources::ORDERS, $order->getTokenValue()); } /** @@ -78,7 +46,8 @@ final class CheckoutOrderDetailsContext implements Context */ public function iShouldBeAbleToPay(): void { - Assert::true($this->orderDetails->hasPayAction()); + $state = $this->getLatestPaymentState(); + Assert::eq($state, PaymentInterface::STATE_NEW); } /** @@ -86,31 +55,27 @@ final class CheckoutOrderDetailsContext implements Context */ public function iShouldNotBeAbleToPay(): void { - Assert::false($this->orderDetails->canBePaid()); + $state = $this->getLatestPaymentState(); + Assert::notEq($state, PaymentInterface::STATE_NEW); } - /** - * @Then I should see :quantity as number of items - */ - public function iShouldSeeAsNumberOfItems(int $quantity): void - { - Assert::same($this->orderDetails->getAmountOfItems(), $quantity); - } - /** - * @Then I should have chosen :paymentMethodName payment method - */ - public function iShouldHaveChosenPaymentMethod(string $paymentMethodName): void + private function getLatestPaymentState(): ?string { - $this->thankYouPage->goToTheChangePaymentMethodPage(); - Assert::same($this->orderDetails->getChosenPaymentMethod(), $paymentMethodName); - } + $response = $this->client->show(Resources::ORDERS, $this->sharedStorage->get('cart_token')); + Assert::same($this->client->getLastResponse()->getStatusCode(), 200); - /** - * @Then I should be notified to choose a payment method - */ - public function iShouldBeNotifiedToChooseAPaymentMethod(): void - { - Assert::contains($this->orderDetails->getPaymentValidationMessage(), 'Please select a payment method.'); + // If the payment is canceled we won't be able to retrieve it because only new one are retrievable + if (OrderPaymentStates::STATE_CANCELLED === $this->responseChecker->getValue($response, 'paymentState')) { + return PaymentInterface::STATE_CANCELLED; + } + + $payments = $this->responseChecker->getValue($response, 'payments'); + $payment = end($payments); + + $paymentId = $payment['id']; + $response = $this->client->show(Resources::PAYMENTS, (string) $paymentId); + + return $this->responseChecker->getValue($response, 'state'); } } diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml index cec644c8ee..38afcbd193 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml @@ -200,9 +200,9 @@ - + diff --git a/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml b/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml index 8a29cd9251..4f6a7a5bb8 100644 --- a/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml +++ b/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml @@ -44,6 +44,7 @@ default: - sylius.behat.context.api.shop.cart - sylius.behat.context.api.shop.checkout - sylius.behat.context.api.shop.checkout.complete + - sylius.behat.context.api.shop.checkout.order_details - sylius.behat.context.api.shop.order - sylius.behat.context.api.shop.response From 166e1a97da0bb7e341eccd0e74cc9461f3f2aaa9 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 2 Feb 2024 20:03:14 +0100 Subject: [PATCH 019/200] Fix PHPStan real issue and regenrate baseline for the rest --- .../Provider/PaymentRequestCommandProvider.php | 1 - .../PaymentRequest/SyliusGetHttpRequestAction.php | 15 ++++++++++++++- .../PayumBundle/Factory/GetStatusFactory.php | 2 +- .../Factory/GetStatusFactoryInterface.php | 2 +- .../ModelAggregateRequestFactoryInterface.php | 2 +- .../Factory/ResolveNextRouteFactory.php | 2 +- .../Factory/ResolveNextRouteFactoryInterface.php | 2 +- .../PaymentRequest/Factory/PayumTokenFactory.php | 8 +++++++- .../Processor/RequestProcessorInterface.php | 3 +-- 9 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php b/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php index 1433be69e9..cf95d2731c 100644 --- a/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php @@ -51,7 +51,6 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid $gatewayConfig = $paymentMethod->getGatewayConfig(); Assert::notNull($gatewayConfig); - /** @var PaymentRequestCommandProviderInterface $service */ $factoryName = $gatewayConfig->getConfig()['factory'] ?? $gatewayConfig->getFactoryName(); /** @var PaymentRequestCommandProviderInterface $provider */ diff --git a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php index 3721540fa8..3a9abfe070 100644 --- a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php +++ b/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php @@ -39,7 +39,19 @@ final class SyliusGetHttpRequestAction implements ActionInterface $paymentRequest = $this->payumApiContext->getPaymentRequest(); Assert::notNull($paymentRequest); - /** @var array $payload */ + /** @var array{ + * 'http_request'?: array{ + * 'query'?: array, + * 'request'?: array, + * 'method'?: string, + * 'uri'?: string, + * 'client_ip'?: string, + * 'user_agent'?: string, + * 'content'?: string, + * 'headers'?: array, + * }, + * } $payload + */ $payload = $paymentRequest->getRequestPayload(); $httpRequest = $payload['http_request'] ?? []; @@ -52,6 +64,7 @@ final class SyliusGetHttpRequestAction implements ActionInterface $request->content = $httpRequest['content'] ?? ''; // Not existing property but used by the Symfony bridge + /** @phpstan-ignore-next-line */ $request->headers = $httpRequest['headers'] ?? []; } diff --git a/src/Sylius/Bundle/PayumBundle/Factory/GetStatusFactory.php b/src/Sylius/Bundle/PayumBundle/Factory/GetStatusFactory.php index e4e9634610..2220d9ef26 100644 --- a/src/Sylius/Bundle/PayumBundle/Factory/GetStatusFactory.php +++ b/src/Sylius/Bundle/PayumBundle/Factory/GetStatusFactory.php @@ -18,7 +18,7 @@ use Sylius\Bundle\PayumBundle\Request\GetStatus; final class GetStatusFactory implements GetStatusFactoryInterface { - public function createNewWithModel($model): GetStatusInterface + public function createNewWithModel(mixed $model): GetStatusInterface { return new GetStatus($model); } diff --git a/src/Sylius/Bundle/PayumBundle/Factory/GetStatusFactoryInterface.php b/src/Sylius/Bundle/PayumBundle/Factory/GetStatusFactoryInterface.php index 10fb0ebd6a..45c039a8cc 100644 --- a/src/Sylius/Bundle/PayumBundle/Factory/GetStatusFactoryInterface.php +++ b/src/Sylius/Bundle/PayumBundle/Factory/GetStatusFactoryInterface.php @@ -17,5 +17,5 @@ use Payum\Core\Request\GetStatusInterface; interface GetStatusFactoryInterface extends ModelAggregateRequestFactoryInterface { - public function createNewWithModel($model): GetStatusInterface; + public function createNewWithModel(mixed $model): GetStatusInterface; } diff --git a/src/Sylius/Bundle/PayumBundle/Factory/ModelAggregateRequestFactoryInterface.php b/src/Sylius/Bundle/PayumBundle/Factory/ModelAggregateRequestFactoryInterface.php index 21c5e26059..b7707fa190 100644 --- a/src/Sylius/Bundle/PayumBundle/Factory/ModelAggregateRequestFactoryInterface.php +++ b/src/Sylius/Bundle/PayumBundle/Factory/ModelAggregateRequestFactoryInterface.php @@ -17,5 +17,5 @@ use Payum\Core\Model\ModelAggregateInterface; interface ModelAggregateRequestFactoryInterface { - public function createNewWithModel($model): ModelAggregateInterface; + public function createNewWithModel(mixed $model): ModelAggregateInterface; } diff --git a/src/Sylius/Bundle/PayumBundle/Factory/ResolveNextRouteFactory.php b/src/Sylius/Bundle/PayumBundle/Factory/ResolveNextRouteFactory.php index a05f40cc00..4a4fed188e 100644 --- a/src/Sylius/Bundle/PayumBundle/Factory/ResolveNextRouteFactory.php +++ b/src/Sylius/Bundle/PayumBundle/Factory/ResolveNextRouteFactory.php @@ -18,7 +18,7 @@ use Sylius\Bundle\PayumBundle\Request\ResolveNextRouteInterface; final class ResolveNextRouteFactory implements ResolveNextRouteFactoryInterface { - public function createNewWithModel($model): ResolveNextRouteInterface + public function createNewWithModel(mixed $model): ResolveNextRouteInterface { return new ResolveNextRoute($model); } diff --git a/src/Sylius/Bundle/PayumBundle/Factory/ResolveNextRouteFactoryInterface.php b/src/Sylius/Bundle/PayumBundle/Factory/ResolveNextRouteFactoryInterface.php index 9dcc8a16e7..66d2e231b6 100644 --- a/src/Sylius/Bundle/PayumBundle/Factory/ResolveNextRouteFactoryInterface.php +++ b/src/Sylius/Bundle/PayumBundle/Factory/ResolveNextRouteFactoryInterface.php @@ -17,5 +17,5 @@ use Sylius\Bundle\PayumBundle\Request\ResolveNextRouteInterface; interface ResolveNextRouteFactoryInterface { - public function createNewWithModel($model): ResolveNextRouteInterface; + public function createNewWithModel(mixed $model): ResolveNextRouteInterface; } diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactory.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactory.php index 7a0bfa62ec..5aa05e5322 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactory.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactory.php @@ -39,7 +39,13 @@ final class PayumTokenFactory implements PayumTokenFactoryInterface $gatewayName = $gatewayConfig->getGatewayName(); - /** @var array|null $payload */ + /** @var array{ + * 'target_path'?: string, + * 'target_path_parameters'?: array, + * 'after_path'?: string, + * 'after_path_parameters'?: array, + * }|null $payload + */ $payload = $paymentRequest->getRequestPayload(); Assert::notNull($payload, 'The request payload need to be not null!'); diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php index 2795d3fc9c..9791a51e15 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php +++ b/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php @@ -13,14 +13,13 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor; -use Payum\Core\Security\TokenAggregateInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; interface RequestProcessorInterface { public function process( PaymentRequestInterface $paymentRequest, - TokenAggregateInterface $request, + mixed $request, string $gatewayName, ): void; } From b9b3cd2b2d9abc245f9770311a33dbdeae0fd7d0 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 17:19:49 +0100 Subject: [PATCH 020/200] Fix service definition and use state machine absctraction --- .../Processor/AfterOfflineCaptureProcessor.php | 14 +++++++++++++- .../Resources/config/services/offline.xml | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php b/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php index a133704e7b..988c7e6753 100644 --- a/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php +++ b/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Sylius\Bundle\PaymentBundle\Processor; use SM\Factory\FactoryInterface as StateMachineFactoryInterface; +use Sylius\Abstraction\StateMachine\StateMachineInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\PaymentTransitions; use Webmozart\Assert\Assert; @@ -21,8 +22,19 @@ use Webmozart\Assert\Assert; final class AfterOfflineCaptureProcessor implements AfterOfflineCaptureProcessorInterface { public function __construct( - private StateMachineFactoryInterface $stateMachineFactory, + private StateMachineFactoryInterface|StateMachineInterface $stateMachineFactory, ) { + if ($this->stateMachineFactory instanceof StateMachineFactoryInterface) { + trigger_deprecation( + 'sylius/payment-bundle', + '1.13', + sprintf( + 'Passing an instance of "%s" as the first argument is deprecated. It will accept only instances of "%s" in Sylius 2.0.', + StateMachineFactoryInterface::class, + StateMachineInterface::class, + ), + ); + } } public function process(PaymentRequestInterface $paymentRequest): void diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml index e1159d7e56..94d08b44b2 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml @@ -40,8 +40,9 @@ + - + From bd3337bceb2527b69246b2af01a44d370cdaf544 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 17:33:41 +0100 Subject: [PATCH 021/200] Move Payum related integrations to a dedicated folder --- .../DependencyInjection/SyliusPayumExtension.php | 14 +++++++------- .../config/{ => integrations/payum}/paypal.xml | 4 ---- .../config/{ => integrations/payum}/stripe.xml | 4 ---- .../integrations/{ => sylius_payment}/offline.xml | 0 .../paypal_express_checkout.xml | 0 .../services.xml} | 0 .../integrations/{ => sylius_payment}/stripe.xml | 0 7 files changed, 7 insertions(+), 15 deletions(-) rename src/Sylius/Bundle/PayumBundle/Resources/config/{ => integrations/payum}/paypal.xml (94%) rename src/Sylius/Bundle/PayumBundle/Resources/config/{ => integrations/payum}/stripe.xml (92%) rename src/Sylius/Bundle/PayumBundle/Resources/config/integrations/{ => sylius_payment}/offline.xml (100%) rename src/Sylius/Bundle/PayumBundle/Resources/config/integrations/{ => sylius_payment}/paypal_express_checkout.xml (100%) rename src/Sylius/Bundle/PayumBundle/Resources/config/integrations/{payment_request.xml => sylius_payment/services.xml} (100%) rename src/Sylius/Bundle/PayumBundle/Resources/config/integrations/{ => sylius_payment}/stripe.xml (100%) diff --git a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php index 5c54f28244..551bfa876f 100644 --- a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php +++ b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php @@ -35,11 +35,11 @@ final class SyliusPayumExtension extends AbstractResourceExtension implements Pr $loader->load('services.xml'); if (class_exists(PaypalExpressCheckoutGatewayFactory::class)) { - $loader->load('paypal.xml'); + $loader->load('integrations/payum/paypal.xml'); } if (class_exists(StripeCheckoutGatewayFactory::class)) { - $loader->load('stripe.xml'); + $loader->load('integrations/payum/stripe.xml'); } $container->setParameter('payum.template.layout', $config['template']['layout']); @@ -89,19 +89,19 @@ final class SyliusPayumExtension extends AbstractResourceExtension implements Pr $container->prependExtensionConfig('sylius_payment', ['gateways' => $gateways]); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('integrations/payment_request.xml'); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/integrations/sylius_payment')); + $loader->load('services.xml'); if (class_exists(OfflineGatewayFactory::class)) { - $loader->load('integrations/offline.xml'); + $loader->load('offline.xml'); } if (class_exists(PaypalExpressCheckoutGatewayFactory::class)) { - $loader->load('integrations/paypal_express_checkout.xml'); + $loader->load('paypal_express_checkout.xml'); } if (class_exists(StripeCheckoutGatewayFactory::class)) { - $loader->load('integrations/stripe.xml'); + $loader->load('stripe.xml'); } } } diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/paypal.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/paypal.xml similarity index 94% rename from src/Sylius/Bundle/PayumBundle/Resources/config/paypal.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/paypal.xml index cfefe3587c..3bc5725d4a 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/paypal.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/paypal.xml @@ -16,10 +16,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - - diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/stripe.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/stripe.xml similarity index 92% rename from src/Sylius/Bundle/PayumBundle/Resources/config/stripe.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/stripe.xml index 362cac89ce..4cc237ab63 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/stripe.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/stripe.xml @@ -16,10 +16,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - - diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/offline.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/offline.xml similarity index 100% rename from src/Sylius/Bundle/PayumBundle/Resources/config/integrations/offline.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/offline.xml diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/paypal_express_checkout.xml similarity index 100% rename from src/Sylius/Bundle/PayumBundle/Resources/config/integrations/paypal_express_checkout.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/paypal_express_checkout.xml diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/services.xml similarity index 100% rename from src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payment_request.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/services.xml diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/stripe.xml similarity index 100% rename from src/Sylius/Bundle/PayumBundle/Resources/config/integrations/stripe.xml rename to src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/stripe.xml From e513585b807d341de4160267893407aaf28e5687 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 17:49:50 +0100 Subject: [PATCH 022/200] Fix composer require checker missing new usages --- composer-require-checker.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/composer-require-checker.json b/composer-require-checker.json index 4d09255eff..6e16f40361 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -36,6 +36,7 @@ "Payum\\Core\\Model\\GatewayConfig", "Payum\\Core\\Model\\GatewayConfigInterface", "Payum\\Core\\Model\\Identity", + "Payum\\Core\\Model\\ModelAggregateInterface", "Payum\\Core\\Model\\Payment", "Payum\\Core\\Model\\PaymentInterface", "Payum\\Core\\Payum", @@ -44,11 +45,14 @@ "Payum\\Core\\Request\\Capture", "Payum\\Core\\Request\\Convert", "Payum\\Core\\Request\\Generic", + "Payum\\Core\\Request\\GetHttpRequest", "Payum\\Core\\Request\\GetStatusInterface", "Payum\\Core\\Request\\Notify", + "Payum\\Core\\Request\\RenderTemplate", "Payum\\Core\\Security\\CryptedInterface", "Payum\\Core\\Security\\GenericTokenFactoryInterface", "Payum\\Core\\Security\\HttpRequestVerifierInterface", + "Payum\\Core\\Security\\TokenAggregateInterface", "Payum\\Core\\Security\\TokenInterface", "Payum\\Core\\Security\\Util\\Random", "Payum\\Core\\Storage\\AbstractStorage", From b79ac33fa374255306e1f5806b70c8eca2fdf5b8 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 18:02:31 +0100 Subject: [PATCH 023/200] Regenerate baseline for PHP8.2 and Sf 6.4 --- phpstan-baseline.neon | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 954e6a233c..0bc5ada03d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3835,6 +3835,16 @@ parameters: count: 1 path: src/Sylius/Bundle/PaymentBundle/Form/Type/PaymentMethodChoiceType.php + - + message: "#^Method Sylius\\\\Bundle\\\\PaymentBundle\\\\Provider\\\\PaymentRequestCommandProvider\\:\\:__construct\\(\\) has parameter \\$locator with generic interface Symfony\\\\Contracts\\\\Service\\\\ServiceProviderInterface but does not specify its types\\: T$#" + count: 1 + path: src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php + + - + message: "#^Method Sylius\\\\Bundle\\\\PaymentBundle\\\\Provider\\\\PaymentRequestTypeCommandProvider\\:\\:__construct\\(\\) has parameter \\$locator with generic interface Symfony\\\\Contracts\\\\Service\\\\ServiceProviderInterface but does not specify its types\\: T$#" + count: 1 + path: src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestTypeCommandProvider.php + - message: "#^Method Sylius\\\\Bundle\\\\PaymentBundle\\\\SyliusPaymentBundle\\:\\:getSupportedDrivers\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 From 607ce05ff7de5132a3856bfc342ebd5846b72ec6 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 18:14:57 +0100 Subject: [PATCH 024/200] Fix baseline --- phpstan-baseline.neon | 138 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 134 insertions(+), 4 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0bc5ada03d..14cb76378b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1235,6 +1235,21 @@ parameters: count: 1 path: src/Sylius/Bundle/ApiBundle/DataTransformer/SubresourceIdAwareCommandDataTransformer.php + - + message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DependencyInjection\\\\Compiler\\\\CommandDataTransformerPass\\:\\:process\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/CommandDataTransformerPass.php + + - + message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DependencyInjection\\\\Compiler\\\\FlattenExceptionNormalizerDecoratorCompilerPass\\:\\:process\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/FlattenExceptionNormalizerDecoratorCompilerPass.php + + - + message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DependencyInjection\\\\Compiler\\\\LegacyErrorHandlingCompilerPass\\:\\:process\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Sylius/Bundle/ApiBundle/DependencyInjection/Compiler/LegacyErrorHandlingCompilerPass.php + - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryCollectionExtension\\\\AcceptedProductReviewsExtension\\:\\:applyToCollection\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" count: 1 @@ -2120,6 +2135,11 @@ parameters: count: 1 path: src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php + - + message: "#^Method Sylius\\\\Bundle\\\\CoreBundle\\\\DependencyInjection\\\\SyliusCoreExtension\\:\\:switchOrderProcessorsPriorities\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php + - message: "#^Property Sylius\\\\Bundle\\\\CoreBundle\\\\DependencyInjection\\\\SyliusCoreExtension\\:\\:\\$bundles type has no value type specified in iterable type array\\.$#" count: 1 @@ -3300,6 +3320,11 @@ parameters: count: 1 path: src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/TotalOfItemsFromTaxonConfigurationType.php + - + message: "#^Method Sylius\\\\Bundle\\\\CoreBundle\\\\Form\\\\Type\\\\ShopBillingDataType\\:\\:configureOptions\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Form/Type/ShopBillingDataType.php + - message: "#^Method Sylius\\\\Bundle\\\\CoreBundle\\\\Form\\\\Type\\\\TaxCalculationStrategyChoiceType\\:\\:__construct\\(\\) has parameter \\$strategies with no value type specified in iterable type array\\.$#" count: 1 @@ -4186,12 +4211,12 @@ parameters: path: src/Sylius/Bundle/PromotionBundle/Validator/CatalogPromotionActionValidator.php - - message: "#^Property Sylius\\\\Bundle\\\\PromotionBundle\\\\Validator\\\\CatalogPromotionActionValidator\\:\\:\\$actionTypes is never read, only written\\.$#" + message: "#^Property Sylius\\\\Bundle\\\\PromotionBundle\\\\Validator\\\\CatalogPromotionActionValidator\\:\\:\\$actionValidators type has no value type specified in iterable type array\\.$#" count: 1 path: src/Sylius/Bundle/PromotionBundle/Validator/CatalogPromotionActionValidator.php - - message: "#^Property Sylius\\\\Bundle\\\\PromotionBundle\\\\Validator\\\\CatalogPromotionActionValidator\\:\\:\\$actionValidators type has no value type specified in iterable type array\\.$#" + message: "#^Property Sylius\\\\Bundle\\\\PromotionBundle\\\\Validator\\\\CatalogPromotionActionValidator\\:\\:\\$actionTypes is never read, only written.$#" count: 1 path: src/Sylius/Bundle/PromotionBundle/Validator/CatalogPromotionActionValidator.php @@ -4206,12 +4231,12 @@ parameters: path: src/Sylius/Bundle/PromotionBundle/Validator/CatalogPromotionScopeValidator.php - - message: "#^Method Sylius\\\\Bundle\\\\PromotionBundle\\\\Validator\\\\CatalogPromotionScopeValidator\\:\\:__construct\\(\\) has parameter \\$scopeValidators with no value type specified in iterable type iterable\\.$#" + message: "#^Property Sylius\\\\Bundle\\\\PromotionBundle\\\\Validator\\\\CatalogPromotionScopeValidator\\:\\:\\$scopeTypes is never read, only written.$#" count: 1 path: src/Sylius/Bundle/PromotionBundle/Validator/CatalogPromotionScopeValidator.php - - message: "#^Property Sylius\\\\Bundle\\\\PromotionBundle\\\\Validator\\\\CatalogPromotionScopeValidator\\:\\:\\$scopeTypes is never read, only written\\.$#" + message: "#^Method Sylius\\\\Bundle\\\\PromotionBundle\\\\Validator\\\\CatalogPromotionScopeValidator\\:\\:__construct\\(\\) has parameter \\$scopeValidators with no value type specified in iterable type iterable\\.$#" count: 1 path: src/Sylius/Bundle/PromotionBundle/Validator/CatalogPromotionScopeValidator.php @@ -4370,6 +4395,11 @@ parameters: count: 1 path: src/Sylius/Bundle/ShopBundle/Router/LocaleStrippingRouter.php + - + message: "#^Method Sylius\\\\Bundle\\\\ShopBundle\\\\SyliusShopBundle\\:\\:build\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Sylius/Bundle/ShopBundle/SyliusShopBundle.php + - message: "#^Method Sylius\\\\Bundle\\\\TaxationBundle\\\\Form\\\\Type\\\\TaxCalculatorChoiceType\\:\\:__construct\\(\\) has parameter \\$calculators with no value type specified in iterable type array\\.$#" count: 1 @@ -4520,6 +4550,16 @@ parameters: count: 1 path: src/Sylius/Bundle/UserBundle/Console/Command/AbstractRoleCommand.php + - + message: "#^Method Sylius\\\\Bundle\\\\UserBundle\\\\Command\\\\DemoteUserCommand\\:\\:executeRoleCommand\\(\\) has parameter \\$securityRoles with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Sylius/Bundle/UserBundle/Command/DemoteUserCommand.php + + - + message: "#^Method Sylius\\\\Bundle\\\\UserBundle\\\\Command\\\\PromoteUserCommand\\:\\:executeRoleCommand\\(\\) has parameter \\$securityRoles with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Sylius/Bundle/UserBundle/Command/PromoteUserCommand.php + - message: "#^Method Sylius\\\\Bundle\\\\UserBundle\\\\Controller\\\\UserController\\:\\:getSyliusAttribute\\(\\) has no return type specified\\.$#" count: 1 @@ -6289,3 +6329,93 @@ parameters: message: "#^Method Sylius\\\\Component\\\\User\\\\Security\\\\Checker\\\\TokenUniquenessChecker\\:\\:__construct\\(\\) has parameter \\$repository with generic interface Sylius\\\\Component\\\\Resource\\\\Repository\\\\RepositoryInterface but does not specify its types\\: T$#" count: 1 path: src/Sylius/Component/User/Security/Checker/TokenUniquenessChecker.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/AbstractInstallCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/CancelUnpaidOrdersCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/CheckRequirementsCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/InformAboutGUSCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/InstallAssetsCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/InstallCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/InstallDatabaseCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/InstallSampleDataCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/JwtConfigurationCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/ShowAvailablePluginsCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/CoreBundle/Command/Model/PluginInfo.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/OrderBundle/Command/RemoveExpiredCartsCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/PromotionBundle/Command/GenerateCouponsCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/UiBundle/Command/DebugTemplateEventCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/UserBundle/Command/AbstractRoleCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/UserBundle/Command/DemoteUserCommand.php + + - + message: "#^If condition is always false.$#" + count: 1 + path: src/Sylius/Bundle/UserBundle/Command/PromoteUserCommand.php From 3892a5f6c90dad535e5a3a206ca91b3222a67aec Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 19:15:10 +0100 Subject: [PATCH 025/200] Add missing deps --- src/Sylius/Bundle/PaymentBundle/composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sylius/Bundle/PaymentBundle/composer.json b/src/Sylius/Bundle/PaymentBundle/composer.json index 3ebb64ae54..c2a03d9159 100644 --- a/src/Sylius/Bundle/PaymentBundle/composer.json +++ b/src/Sylius/Bundle/PaymentBundle/composer.json @@ -30,6 +30,7 @@ "sylius/payment": "^2.0", "sylius/resource-bundle": "^1.10", "symfony/framework-bundle": "^6.4.1", + "symfony/messenger": "^6.4.0", "ramsey/uuid-doctrine": "^2.0" }, "conflict": { From 9fae92399379e934e48775a77638bb0db8b0cb1e Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 19:16:51 +0100 Subject: [PATCH 026/200] Fix old ignore --- src/Sylius/Bundle/PaymentBundle/.gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/PaymentBundle/.gitignore b/src/Sylius/Bundle/PaymentBundle/.gitignore index a24566fdcc..d9a7ab6005 100644 --- a/src/Sylius/Bundle/PaymentBundle/.gitignore +++ b/src/Sylius/Bundle/PaymentBundle/.gitignore @@ -4,5 +4,5 @@ bin/ composer.phar composer.lock -test/app/cache -test/app/logs +test/var/cache +test/var/logs From 9704d93c3a01a227f2681a15f5ee342eceef9898 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 19:21:25 +0100 Subject: [PATCH 027/200] Use Sylius abstract doctrine migration to allow PostgreSQL --- .../Bundle/CoreBundle/Migrations/Version20231106190918.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php b/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php index d226a42118..ee601d69b5 100644 --- a/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php +++ b/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\Migrations; use Doctrine\DBAL\Schema\Schema; -use Doctrine\Migrations\AbstractMigration; +use Sylius\Bundle\CoreBundle\Doctrine\Migrations\AbstractMigration; final class Version20231106190918 extends AbstractMigration { From 8c72284fa6b9c27e60e53e176739692530f277fb Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 23:26:50 +0100 Subject: [PATCH 028/200] Create migration for PostgreSQL --- .../Migrations/Version20240203222417.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Sylius/Bundle/CoreBundle/Migrations/Version20240203222417.php diff --git a/src/Sylius/Bundle/CoreBundle/Migrations/Version20240203222417.php b/src/Sylius/Bundle/CoreBundle/Migrations/Version20240203222417.php new file mode 100644 index 0000000000..6f4b946d5a --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Migrations/Version20240203222417.php @@ -0,0 +1,55 @@ +addSql('CREATE TABLE sylius_payment_request (hash UUID NOT NULL, method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, request_payload TEXT NOT NULL, response_data JSON NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(hash))'); + $this->addSql('CREATE INDEX IDX_86D904B19883967 ON sylius_payment_request (method_id)'); + $this->addSql('CREATE INDEX IDX_86D904B4C3A3BB ON sylius_payment_request (payment_id)'); + $this->addSql('COMMENT ON COLUMN sylius_payment_request.hash IS \'(DC2Type:uuid)\''); + $this->addSql('COMMENT ON COLUMN sylius_payment_request.request_payload IS \'(DC2Type:object)\''); + $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B19883967 FOREIGN KEY (method_id) REFERENCES sylius_payment_method (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B4C3A3BB FOREIGN KEY (payment_id) REFERENCES sylius_payment (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE messenger_messages ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('ALTER TABLE messenger_messages ALTER available_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('ALTER TABLE messenger_messages ALTER delivered_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'(DC2Type:datetime_immutable)\''); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE sylius_payment_request DROP CONSTRAINT FK_86D904B19883967'); + $this->addSql('ALTER TABLE sylius_payment_request DROP CONSTRAINT FK_86D904B4C3A3BB'); + $this->addSql('DROP TABLE sylius_payment_request'); + $this->addSql('ALTER TABLE messenger_messages ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('ALTER TABLE messenger_messages ALTER available_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('ALTER TABLE messenger_messages ALTER delivered_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); + $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS NULL'); + $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS NULL'); + $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS NULL'); + } +} From 5473573ea09a4b2dc3eefc7d1d375d70ff858971 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sat, 3 Feb 2024 23:44:08 +0100 Subject: [PATCH 029/200] Add missing messenger buses --- .../Resources/config/app/config.yml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml index 619fe137f6..c4b179aaf9 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml @@ -15,3 +15,23 @@ jms_serializer: sylius-payment: namespace_prefix: "Sylius\\Component\\Payment" path: "@SyliusPaymentBundle/Resources/config/serializer" + +sylius_payum: + gateway_config: + validation_groups: + paypal_express_checkout: + - 'sylius' + - 'sylius_paypal_express_checkout' + stripe_checkout: + - 'sylius' + - 'sylius_stripe_checkout' + +framework: + messenger: + buses: + sylius.event_bus: + default_middleware: allow_no_handlers + sylius.command_bus: + middleware: + - 'validation' + - 'doctrine_transaction' From a1378b593827c00ea9b452c10bd4335aa6f6c3e5 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Sun, 4 Feb 2024 18:12:50 +0100 Subject: [PATCH 030/200] Refactor to use CoreBundle instead of SyliusPay(um|ment)Bundle --- .../Payment/AddPaymentRequestHandler.php | 2 +- .../Payment/UpdatePaymentRequestHandler.php | 2 +- .../config/services/command_handlers.xml | 4 +- .../SyliusCoreExtension.php | 21 +++++ .../PaymentRequestDuplicationChecker.php | 2 +- ...mentRequestDuplicationCheckerInterface.php | 2 +- .../Offline}/CapturePaymentRequest.php | 4 +- .../Command/Offline}/StatusPaymentRequest.php | 4 +- .../PaymentRequestHashAwareInterface.php | 2 +- .../PaymentRequestCommandDispatcher.php | 4 +- ...ymentRequestCommandDispatcherInterface.php | 2 +- .../Offline/CapturePaymentRequestHandler.php | 8 +- .../Action}/SyliusGetHttpRequestAction.php | 11 +-- .../Action}/SyliusRenderTemplateAction.php | 4 +- .../Command/AuthorizePaymentRequest.php | 4 +- .../Payum/Command}/CapturePaymentRequest.php | 4 +- .../Payum/Command}/StatusPaymentRequest.php | 4 +- .../ModelPaymentRequestHandler.php | 8 +- .../TokenPaymentRequestHandler.php | 12 +-- .../Payum}/Factory/PayumTokenFactory.php | 2 +- .../Factory/PayumTokenFactoryInterface.php | 2 +- .../Payum}/PaymentRequestContext.php | 2 +- .../Payum}/PaymentRequestContextInterface.php | 2 +- .../Processor/AfterTokenRequestProcessor.php | 4 +- .../AfterTokenRequestProcessorInterface.php | 2 +- .../Payum}/Processor/RequestProcessor.php | 4 +- .../Processor/RequestProcessorInterface.php | 2 +- .../Provider/AuthorizeCommandProvider.php | 6 +- .../Provider/CaptureCommandProvider.php | 6 +- .../Provider/PaymentRequestProvider.php | 2 +- .../PaymentRequestProviderInterface.php | 2 +- .../Payum}/Provider/StatusCommandProvider.php | 6 +- .../AfterOfflineCaptureProcessor.php | 2 +- .../AfterOfflineCaptureProcessorInterface.php | 2 +- .../Processor/OfflineCaptureProcessor.php | 2 +- .../OfflineCaptureProcessorInterface.php | 2 +- .../CapturePaymentRequestCommandProvider.php | 6 +- .../StatusPaymentRequestCommandProvider.php | 6 +- .../PaymentRequestCommandProvider.php | 4 +- ...PaymentRequestCommandProviderInterface.php | 2 +- .../PaymentRequestTypeCommandProvider.php | 2 +- .../services/integrations/payum}/offline.xml | 6 +- .../payum}/paypal_express_checkout.xml | 8 +- .../services/integrations/payum}/stripe.xml | 8 +- .../config/services/payment_request.xml | 27 ++++++ .../services/payment_request}/checker.xml | 2 +- .../payment_request}/command_dispatcher.xml | 4 +- .../services/payment_request}/offline.xml | 16 ++-- .../payment_request/payum/actions.xml | 34 ++++++++ .../payment_request/payum/comman_handlers.xml | 52 +++++++++++ .../payment_request/payum/factory.xml | 31 +++++++ .../payment_request/payum/processors.xml | 27 ++++++ .../payment_request/payum/providers.xml | 27 ++++++ .../services/payment_request}/provider.xml | 4 +- .../Resources/config/app/config.yml | 10 --- .../Resources/config/services.xml | 4 - .../SyliusPayumExtension.php | 15 ---- .../integrations/sylius_payment/services.xml | 86 ------------------- src/Sylius/Bundle/PayumBundle/composer.json | 2 +- 59 files changed, 321 insertions(+), 216 deletions(-) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Checker/PaymentRequestDuplicationChecker.php (93%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Checker/PaymentRequestDuplicationCheckerInterface.php (88%) rename src/Sylius/Bundle/{PayumBundle/Command => CoreBundle/PaymentRequest/Command/Offline}/CapturePaymentRequest.php (78%) rename src/Sylius/Bundle/{PayumBundle/Command => CoreBundle/PaymentRequest/Command/Offline}/StatusPaymentRequest.php (78%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Command/PaymentRequestHashAwareInterface.php (87%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/CommandDispatcher/PaymentRequestCommandDispatcher.php (89%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php (88%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/CommandHandler/Offline/CapturePaymentRequestHandler.php (84%) rename src/Sylius/Bundle/{PayumBundle/Action/PaymentRequest => CoreBundle/PaymentRequest/Payum/Action}/SyliusGetHttpRequestAction.php (86%) rename src/Sylius/Bundle/{PayumBundle/Action/PaymentRequest => CoreBundle/PaymentRequest/Payum/Action}/SyliusRenderTemplateAction.php (89%) rename src/Sylius/Bundle/{PayumBundle => CoreBundle/PaymentRequest/Payum}/Command/AuthorizePaymentRequest.php (79%) rename src/Sylius/Bundle/{PaymentBundle/Command/Offline => CoreBundle/PaymentRequest/Payum/Command}/CapturePaymentRequest.php (79%) rename src/Sylius/Bundle/{PaymentBundle/Command/Offline => CoreBundle/PaymentRequest/Payum/Command}/StatusPaymentRequest.php (78%) rename src/Sylius/Bundle/{PayumBundle => CoreBundle/PaymentRequest/Payum}/CommandHandler/ModelPaymentRequestHandler.php (82%) rename src/Sylius/Bundle/{PayumBundle => CoreBundle/PaymentRequest/Payum}/CommandHandler/TokenPaymentRequestHandler.php (74%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Factory/PayumTokenFactory.php (97%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Factory/PayumTokenFactoryInterface.php (87%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/PaymentRequestContext.php (93%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/PaymentRequestContextInterface.php (90%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Processor/AfterTokenRequestProcessor.php (88%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Processor/AfterTokenRequestProcessorInterface.php (88%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Processor/RequestProcessor.php (90%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Processor/RequestProcessorInterface.php (87%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Provider/AuthorizeCommandProvider.php (75%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Provider/CaptureCommandProvider.php (75%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Provider/PaymentRequestProvider.php (95%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Provider/PaymentRequestProviderInterface.php (86%) rename src/Sylius/Bundle/{PayumBundle/PaymentRequest => CoreBundle/PaymentRequest/Payum}/Provider/StatusCommandProvider.php (75%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Processor/AfterOfflineCaptureProcessor.php (96%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Processor/AfterOfflineCaptureProcessorInterface.php (87%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Processor/OfflineCaptureProcessor.php (94%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Processor/OfflineCaptureProcessorInterface.php (87%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Provider/Offline/CapturePaymentRequestCommandProvider.php (75%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Provider/Offline/StatusPaymentRequestCommandProvider.php (75%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Provider/PaymentRequestCommandProvider.php (92%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Provider/PaymentRequestCommandProviderInterface.php (89%) rename src/Sylius/Bundle/{PaymentBundle => CoreBundle/PaymentRequest}/Provider/PaymentRequestTypeCommandProvider.php (94%) rename src/Sylius/Bundle/{PayumBundle/Resources/config/integrations/sylius_payment => CoreBundle/Resources/config/services/integrations/payum}/offline.xml (79%) rename src/Sylius/Bundle/{PayumBundle/Resources/config/integrations/sylius_payment => CoreBundle/Resources/config/services/integrations/payum}/paypal_express_checkout.xml (74%) rename src/Sylius/Bundle/{PayumBundle/Resources/config/integrations/sylius_payment => CoreBundle/Resources/config/services/integrations/payum}/stripe.xml (76%) create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request.xml rename src/Sylius/Bundle/{PaymentBundle/Resources/config/services => CoreBundle/Resources/config/services/payment_request}/checker.xml (76%) rename src/Sylius/Bundle/{PaymentBundle/Resources/config/services => CoreBundle/Resources/config/services/payment_request}/command_dispatcher.xml (67%) rename src/Sylius/Bundle/{PaymentBundle/Resources/config/services => CoreBundle/Resources/config/services/payment_request}/offline.xml (60%) create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/actions.xml create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/factory.xml create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/processors.xml create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/providers.xml rename src/Sylius/Bundle/{PaymentBundle/Resources/config/services => CoreBundle/Resources/config/services/payment_request}/provider.xml (67%) delete mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/services.xml diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index b182c3c551..3800b698b7 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Sylius\Bundle\ApiBundle\CommandHandler\Payment; use Sylius\Bundle\ApiBundle\Command\Payment\AddPaymentRequest; -use Sylius\Bundle\PaymentBundle\CommandDispatcher\PaymentRequestCommandDispatcherInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandDispatcher\PaymentRequestCommandDispatcherInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php index fcd4301cc9..8d9f5129b2 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Sylius\Bundle\ApiBundle\CommandHandler\Payment; use Sylius\Bundle\ApiBundle\Command\Payment\UpdatePaymentRequest; -use Sylius\Bundle\PaymentBundle\CommandDispatcher\PaymentRequestCommandDispatcherInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandDispatcher\PaymentRequestCommandDispatcherInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml index 811701d6f4..0c1daf639c 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml @@ -243,14 +243,14 @@ - + - + diff --git a/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php b/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php index 5074aab2e9..c1c499e664 100644 --- a/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php +++ b/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php @@ -13,6 +13,9 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\DependencyInjection; +use Payum\Offline\OfflineGatewayFactory; +use Payum\Paypal\ExpressCheckout\Nvp\PaypalExpressCheckoutGatewayFactory; +use Payum\Stripe\StripeCheckoutGatewayFactory; use Sylius\Bundle\CoreBundle\Attribute\AsCatalogPromotionApplicatorCriteria; use Sylius\Bundle\CoreBundle\Attribute\AsCatalogPromotionPriceCalculator; use Sylius\Bundle\CoreBundle\Attribute\AsEntityObserver; @@ -105,6 +108,7 @@ final class SyliusCoreExtension extends AbstractResourceExtension implements Pre $this->prependDoctrineMigrations($container); $this->prependJmsSerializerIfAdminApiBundleIsNotPresent($container); $this->prependSyliusOrderBundle($container, $config); + $this->prependPayum($container); } protected function getMigrationsNamespace(): string @@ -184,6 +188,23 @@ final class SyliusCoreExtension extends AbstractResourceExtension implements Pre ]); } + private function prependPayum(ContainerBuilder $container): void + { + $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + + if (class_exists(OfflineGatewayFactory::class)) { + $loader->load('services/integrations/payum/offline.xml'); + } + + if (class_exists(PaypalExpressCheckoutGatewayFactory::class)) { + $loader->load('services/integrations/payum/paypal_express_checkout.xml'); + } + + if (class_exists(StripeCheckoutGatewayFactory::class)) { + $loader->load('services/integrations/payum/stripe.xml'); + } + } + private function registerAutoconfiguration(ContainerBuilder $container): void { $container->registerAttributeForAutoconfiguration( diff --git a/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Checker/PaymentRequestDuplicationChecker.php similarity index 93% rename from src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Checker/PaymentRequestDuplicationChecker.php index 0a44de5ed4..69ba683192 100644 --- a/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationChecker.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Checker/PaymentRequestDuplicationChecker.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Checker; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Checker; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; diff --git a/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationCheckerInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Checker/PaymentRequestDuplicationCheckerInterface.php similarity index 88% rename from src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationCheckerInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Checker/PaymentRequestDuplicationCheckerInterface.php index 7597ef86f2..86702e11e1 100644 --- a/src/Sylius/Bundle/PaymentBundle/Checker/PaymentRequestDuplicationCheckerInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Checker/PaymentRequestDuplicationCheckerInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Checker; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Checker; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/CapturePaymentRequest.php similarity index 78% rename from src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/CapturePaymentRequest.php index b19e742b54..1921179890 100644 --- a/src/Sylius/Bundle/PayumBundle/Command/CapturePaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/CapturePaymentRequest.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Command; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline; -use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; class CapturePaymentRequest implements PaymentRequestHashAwareInterface { diff --git a/src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/StatusPaymentRequest.php similarity index 78% rename from src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/StatusPaymentRequest.php index 2a367101ee..ef2b56900c 100644 --- a/src/Sylius/Bundle/PayumBundle/Command/StatusPaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/StatusPaymentRequest.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Command; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline; -use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; class StatusPaymentRequest implements PaymentRequestHashAwareInterface { diff --git a/src/Sylius/Bundle/PaymentBundle/Command/PaymentRequestHashAwareInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareInterface.php similarity index 87% rename from src/Sylius/Bundle/PaymentBundle/Command/PaymentRequestHashAwareInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareInterface.php index 51444ee898..e821b42819 100644 --- a/src/Sylius/Bundle/PaymentBundle/Command/PaymentRequestHashAwareInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Command; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Command; /** @experimental */ interface PaymentRequestHashAwareInterface diff --git a/src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcher.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcher.php similarity index 89% rename from src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcher.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcher.php index 4342744900..4332579230 100644 --- a/src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcher.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcher.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\CommandDispatcher; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandDispatcher; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\PaymentBundle\Exception\PaymentRequestNotSupportedException; -use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; use Symfony\Component\Messenger\MessageBusInterface; diff --git a/src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php similarity index 88% rename from src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php index 13eb34b222..6012579785 100644 --- a/src/Sylius/Bundle/PaymentBundle/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcherInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\CommandDispatcher; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandDispatcher; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PaymentBundle/CommandHandler/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php similarity index 84% rename from src/Sylius/Bundle/PaymentBundle/CommandHandler/Offline/CapturePaymentRequestHandler.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php index 930858162c..26750e90e4 100644 --- a/src/Sylius/Bundle/PaymentBundle/CommandHandler/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\CommandHandler\Offline; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandHandler\Offline; -use Sylius\Bundle\PaymentBundle\Command\Offline\CapturePaymentRequest; -use Sylius\Bundle\PaymentBundle\Processor\AfterOfflineCaptureProcessorInterface; -use Sylius\Bundle\PaymentBundle\Processor\OfflineCaptureProcessorInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline\CapturePaymentRequest; +use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\AfterOfflineCaptureProcessorInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\OfflineCaptureProcessorInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; diff --git a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Action/SyliusGetHttpRequestAction.php similarity index 86% rename from src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Action/SyliusGetHttpRequestAction.php index 3a9abfe070..9fbe434966 100644 --- a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusGetHttpRequestAction.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Action/SyliusGetHttpRequestAction.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Action\PaymentRequest; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Action; use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Core\Request\GetHttpRequest; -use Sylius\Bundle\PayumBundle\PaymentRequest\PaymentRequestContextInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\PaymentRequestContextInterface; use Webmozart\Assert\Assert; final class SyliusGetHttpRequestAction implements ActionInterface @@ -63,9 +63,10 @@ final class SyliusGetHttpRequestAction implements ActionInterface $request->userAgent = $httpRequest['user_agent'] ?? ''; $request->content = $httpRequest['content'] ?? ''; - // Not existing property but used by the Symfony bridge - /** @phpstan-ignore-next-line */ - $request->headers = $httpRequest['headers'] ?? []; + // Next release of Payum will have this field + if (property_exists($request, 'headers')) { + $request->headers = $httpRequest['headers'] ?? []; + } } public function supports($request): bool diff --git a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Action/SyliusRenderTemplateAction.php similarity index 89% rename from src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Action/SyliusRenderTemplateAction.php index ea522256c4..d656ae99ed 100644 --- a/src/Sylius/Bundle/PayumBundle/Action/PaymentRequest/SyliusRenderTemplateAction.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Action/SyliusRenderTemplateAction.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Action\PaymentRequest; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Action; use Payum\Core\Action\ActionInterface; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Core\Request\RenderTemplate; -use Sylius\Bundle\PayumBundle\PaymentRequest\PaymentRequestContextInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\PaymentRequestContextInterface; use Webmozart\Assert\Assert; final class SyliusRenderTemplateAction implements ActionInterface diff --git a/src/Sylius/Bundle/PayumBundle/Command/AuthorizePaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php similarity index 79% rename from src/Sylius/Bundle/PayumBundle/Command/AuthorizePaymentRequest.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php index 2d822ac594..efd762eb09 100644 --- a/src/Sylius/Bundle/PayumBundle/Command/AuthorizePaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\Command; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command; -use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; class AuthorizePaymentRequest implements PaymentRequestHashAwareInterface { diff --git a/src/Sylius/Bundle/PaymentBundle/Command/Offline/CapturePaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php similarity index 79% rename from src/Sylius/Bundle/PaymentBundle/Command/Offline/CapturePaymentRequest.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php index 215cad448c..02d46df93c 100644 --- a/src/Sylius/Bundle/PaymentBundle/Command/Offline/CapturePaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Command\Offline; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command; -use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; class CapturePaymentRequest implements PaymentRequestHashAwareInterface { diff --git a/src/Sylius/Bundle/PaymentBundle/Command/Offline/StatusPaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php similarity index 78% rename from src/Sylius/Bundle/PaymentBundle/Command/Offline/StatusPaymentRequest.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php index b63267e30e..00797f6150 100644 --- a/src/Sylius/Bundle/PaymentBundle/Command/Offline/StatusPaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Command\Offline; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command; -use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; class StatusPaymentRequest implements PaymentRequestHashAwareInterface { diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/ModelPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php similarity index 82% rename from src/Sylius/Bundle/PayumBundle/CommandHandler/ModelPaymentRequestHandler.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php index 980eec3a1e..bbf1f3d17b 100644 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/ModelPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\CommandHandler; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandHandler; -use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor\RequestProcessorInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider\PaymentRequestProviderInterface; use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; diff --git a/src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php similarity index 74% rename from src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php index e57d4e55fe..81df149ca1 100644 --- a/src/Sylius/Bundle/PayumBundle/CommandHandler/TokenPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php @@ -11,14 +11,14 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\CommandHandler; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandHandler; -use Sylius\Bundle\PaymentBundle\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Factory\PayumTokenFactoryInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor\AfterTokenRequestProcessorInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor\RequestProcessorInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider\PaymentRequestProviderInterface; use Sylius\Bundle\PayumBundle\Factory\TokenAggregateRequestFactoryInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Factory\PayumTokenFactoryInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\AfterTokenRequestProcessorInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Processor\RequestProcessorInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactory.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactory.php similarity index 97% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactory.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactory.php index 5aa05e5322..a4f20030ca 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactory.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactory.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Factory; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Factory; use Payum\Core\Payum; use Payum\Core\Security\TokenInterface; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactoryInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactoryInterface.php similarity index 87% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactoryInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactoryInterface.php index 16a21c8761..010fd1765c 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Factory/PayumTokenFactoryInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactoryInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Factory; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Factory; use Payum\Core\Security\TokenInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContext.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/PaymentRequestContext.php similarity index 93% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContext.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/PaymentRequestContext.php index 4c8640c2c0..5aa7a14329 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContext.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/PaymentRequestContext.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContextInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/PaymentRequestContextInterface.php similarity index 90% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContextInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/PaymentRequestContextInterface.php index 871cb2f83d..43359c9a7b 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/PaymentRequestContextInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/PaymentRequestContextInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessor.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessor.php similarity index 88% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessor.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessor.php index 50b4dd16af..72c6951fe5 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessor.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor; use Payum\Core\Security\TokenInterface; -use Sylius\Bundle\PaymentBundle\CommandDispatcher\PaymentRequestCommandDispatcherInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandDispatcher\PaymentRequestCommandDispatcherInterface; use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessorInterface.php similarity index 88% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessorInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessorInterface.php index a16770dfcc..7efa21cc57 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/AfterTokenRequestProcessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessorInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor; use Payum\Core\Security\TokenInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessor.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessor.php similarity index 90% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessor.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessor.php index 816e4013a8..f7b284e3f2 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessor.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor; use Payum\Core\Payum; use Payum\Core\Security\TokenAggregateInterface; -use Sylius\Bundle\PayumBundle\PaymentRequest\PaymentRequestContextInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\PaymentRequestContextInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class RequestProcessor implements RequestProcessorInterface diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessorInterface.php similarity index 87% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessorInterface.php index 9791a51e15..9240c8f35c 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Processor/RequestProcessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessorInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/AuthorizeCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/AuthorizeCommandProvider.php similarity index 75% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/AuthorizeCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/AuthorizeCommandProvider.php index ace097ba64..e5f44cbc16 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/AuthorizeCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/AuthorizeCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider; -use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; -use Sylius\Bundle\PayumBundle\Command\AuthorizePaymentRequest; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command\AuthorizePaymentRequest; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class AuthorizeCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/CaptureCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/CaptureCommandProvider.php similarity index 75% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/CaptureCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/CaptureCommandProvider.php index 6b21461e75..6073558ead 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/CaptureCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/CaptureCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider; -use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; -use Sylius\Bundle\PayumBundle\Command\CapturePaymentRequest; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command\CapturePaymentRequest; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class CaptureCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/PaymentRequestProvider.php similarity index 95% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/PaymentRequestProvider.php index 7f9ca523c1..3be2cde94d 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/PaymentRequestProvider.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\Proxy; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/PaymentRequestProviderInterface.php similarity index 86% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProviderInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/PaymentRequestProviderInterface.php index 43aa4de281..ed9b7dee32 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/PaymentRequestProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/PaymentRequestProviderInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/StatusCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/StatusCommandProvider.php similarity index 75% rename from src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/StatusCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/StatusCommandProvider.php index 1ec733406c..cf202363bc 100644 --- a/src/Sylius/Bundle/PayumBundle/PaymentRequest/Provider/StatusCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/StatusCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\PayumBundle\PaymentRequest\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider; -use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; -use Sylius\Bundle\PayumBundle\Command\StatusPaymentRequest; +use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command\StatusPaymentRequest; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class StatusCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessor.php similarity index 96% rename from src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessor.php index 988c7e6753..4c8d4ba58c 100644 --- a/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessor.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor; use SM\Factory\FactoryInterface as StateMachineFactoryInterface; use Sylius\Abstraction\StateMachine\StateMachineInterface; diff --git a/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessorInterface.php similarity index 87% rename from src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessorInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessorInterface.php index 22af327d5a..6fb6fc0ecb 100644 --- a/src/Sylius/Bundle/PaymentBundle/Processor/AfterOfflineCaptureProcessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessorInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessor.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessor.php similarity index 94% rename from src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessor.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessor.php index 2c4e4d75ea..7a43444829 100644 --- a/src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessor.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor; use Sylius\Component\Payment\Model\PaymentInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessorInterface.php similarity index 87% rename from src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessorInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessorInterface.php index 48d24006b6..c5fadd9a28 100644 --- a/src/Sylius/Bundle/PaymentBundle/Processor/OfflineCaptureProcessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessorInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PaymentBundle/Provider/Offline/CapturePaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/CapturePaymentRequestCommandProvider.php similarity index 75% rename from src/Sylius/Bundle/PaymentBundle/Provider/Offline/CapturePaymentRequestCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/CapturePaymentRequestCommandProvider.php index 2445f6d253..996ddb80a1 100644 --- a/src/Sylius/Bundle/PaymentBundle/Provider/Offline/CapturePaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/CapturePaymentRequestCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Provider\Offline; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider\Offline; -use Sylius\Bundle\PaymentBundle\Command\Offline\CapturePaymentRequest; -use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline\CapturePaymentRequest; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class CapturePaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/PaymentBundle/Provider/Offline/StatusPaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/StatusPaymentRequestCommandProvider.php similarity index 75% rename from src/Sylius/Bundle/PaymentBundle/Provider/Offline/StatusPaymentRequestCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/StatusPaymentRequestCommandProvider.php index 51b1e01b26..9fbcb6e302 100644 --- a/src/Sylius/Bundle/PaymentBundle/Provider/Offline/StatusPaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/StatusPaymentRequestCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Provider\Offline; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider\Offline; -use Sylius\Bundle\PaymentBundle\Command\Offline\StatusPaymentRequest; -use Sylius\Bundle\PaymentBundle\Provider\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline\StatusPaymentRequest; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class StatusPaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProvider.php similarity index 92% rename from src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProvider.php index cf95d2731c..3216056806 100644 --- a/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProvider.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; -use Sylius\Bundle\PaymentBundle\Checker\PaymentRequestDuplicationCheckerInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Checker\PaymentRequestDuplicationCheckerInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Contracts\Service\ServiceProviderInterface; diff --git a/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProviderInterface.php similarity index 89% rename from src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProviderInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProviderInterface.php index 7bef0d5af9..bfde835869 100644 --- a/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestCommandProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProviderInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestTypeCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestTypeCommandProvider.php similarity index 94% rename from src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestTypeCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestTypeCommandProvider.php index 587dbaf6de..fba8f6d579 100644 --- a/src/Sylius/Bundle/PaymentBundle/Provider/PaymentRequestTypeCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestTypeCommandProvider.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\PaymentBundle\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Contracts\Service\ServiceProviderInterface; diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/offline.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml similarity index 79% rename from src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/offline.xml rename to src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml index 3a437de539..c19b3b6ff6 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/offline.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml @@ -18,16 +18,16 @@ - + - + - + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/paypal_express_checkout.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml similarity index 74% rename from src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/paypal_express_checkout.xml rename to src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml index 167e282ec3..c66b2a89a6 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/paypal_express_checkout.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml @@ -18,20 +18,20 @@ - + - + - + - + diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/stripe.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml similarity index 76% rename from src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/stripe.xml rename to src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml index 2ec2316e93..91a5a52b57 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/stripe.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml @@ -18,20 +18,20 @@ - + - + - + - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request.xml new file mode 100644 index 0000000000..88c557ee3d --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/checker.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/checker.xml similarity index 76% rename from src/Sylius/Bundle/PaymentBundle/Resources/config/services/checker.xml rename to src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/checker.xml index 66c47db6cb..2891bd9c47 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/checker.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/checker.xml @@ -18,7 +18,7 @@ - + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/command_dispatcher.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_dispatcher.xml similarity index 67% rename from src/Sylius/Bundle/PaymentBundle/Resources/config/services/command_dispatcher.xml rename to src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_dispatcher.xml index c21b39ee50..50fda42a8d 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/command_dispatcher.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_dispatcher.xml @@ -18,9 +18,9 @@ - + - + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml similarity index 60% rename from src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml rename to src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml index 94d08b44b2..75ec387865 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/offline.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml @@ -18,30 +18,30 @@ - + - + - + - + - - + + - + - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/actions.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/actions.xml new file mode 100644 index 0000000000..481e2199e2 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/actions.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml new file mode 100644 index 0000000000..4d9b255b2f --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/factory.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/factory.xml new file mode 100644 index 0000000000..1325861659 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/factory.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/processors.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/processors.xml new file mode 100644 index 0000000000..d06abf84ae --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/processors.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/providers.xml new file mode 100644 index 0000000000..beef4bd035 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/providers.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/provider.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml similarity index 67% rename from src/Sylius/Bundle/PaymentBundle/Resources/config/services/provider.xml rename to src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml index 8c5c5c48d5..1ba56942f4 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/services/provider.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml @@ -18,8 +18,8 @@ - - + + diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml index c4b179aaf9..dfc0ec5120 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml @@ -25,13 +25,3 @@ sylius_payum: stripe_checkout: - 'sylius' - 'sylius_stripe_checkout' - -framework: - messenger: - buses: - sylius.event_bus: - default_middleware: allow_no_handlers - sylius.command_bus: - middleware: - - 'validation' - - 'doctrine_transaction' diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml index 7a2c489c45..a8a5f3cbeb 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/services.xml @@ -13,11 +13,7 @@ - - - - diff --git a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php index 551bfa876f..6ec8ebce9d 100644 --- a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php +++ b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php @@ -88,20 +88,5 @@ final class SyliusPayumExtension extends AbstractResourceExtension implements Pr } $container->prependExtensionConfig('sylius_payment', ['gateways' => $gateways]); - - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/integrations/sylius_payment')); - $loader->load('services.xml'); - - if (class_exists(OfflineGatewayFactory::class)) { - $loader->load('offline.xml'); - } - - if (class_exists(PaypalExpressCheckoutGatewayFactory::class)) { - $loader->load('paypal_express_checkout.xml'); - } - - if (class_exists(StripeCheckoutGatewayFactory::class)) { - $loader->load('stripe.xml'); - } } } diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/services.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/services.xml deleted file mode 100644 index 160ea0255f..0000000000 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/sylius_payment/services.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/PayumBundle/composer.json b/src/Sylius/Bundle/PayumBundle/composer.json index 141a96db12..792d1993a0 100644 --- a/src/Sylius/Bundle/PayumBundle/composer.json +++ b/src/Sylius/Bundle/PayumBundle/composer.json @@ -1,7 +1,7 @@ { "name": "sylius/payum-bundle", "type": "symfony-bundle", - "description": "CommandHandler integration for Symfony e-commerce applications.", + "description": "Payum integration for Symfony e-commerce applications.", "keywords": [ "payments", "payment", From 7e9a9ae00538c05f5386a547f0a193e567d9f469 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 7 Feb 2024 14:59:55 +0100 Subject: [PATCH 031/200] Move folder Provider to CommandProvider to better reflect it's a messenger command --- .../PaymentRequestCommandDispatcher.php | 2 +- .../CapturePaymentRequestCommandProvider.php | 4 ++-- .../StatusPaymentRequestCommandProvider.php | 4 ++-- .../PaymentRequestCommandProvider.php | 2 +- .../PaymentRequestCommandProviderInterface.php | 2 +- .../PaymentRequestTypeCommandProvider.php | 2 +- .../AuthorizeCommandProvider.php | 4 ++-- .../CaptureCommandProvider.php | 4 ++-- .../StatusCommandProvider.php | 4 ++-- .../services/integrations/payum/offline.xml | 12 ++++++------ .../payum/paypal_express_checkout.xml | 16 ++++++++-------- .../services/integrations/payum/stripe.xml | 16 ++++++++-------- .../payment_request/command_dispatcher.xml | 2 +- .../config/services/payment_request/offline.xml | 6 +++--- .../config/services/payment_request/provider.xml | 2 +- 15 files changed, 41 insertions(+), 41 deletions(-) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Provider => CommandProvider}/Offline/CapturePaymentRequestCommandProvider.php (82%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Provider => CommandProvider}/Offline/StatusPaymentRequestCommandProvider.php (82%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Provider => CommandProvider}/PaymentRequestCommandProvider.php (96%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Provider => CommandProvider}/PaymentRequestCommandProviderInterface.php (88%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Provider => CommandProvider}/PaymentRequestTypeCommandProvider.php (94%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/{Provider => CommandProvider}/AuthorizeCommandProvider.php (82%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/{Provider => CommandProvider}/CaptureCommandProvider.php (82%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/{Provider => CommandProvider}/StatusCommandProvider.php (82%) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcher.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcher.php index 4332579230..68e08b13d2 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcher.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandDispatcher/PaymentRequestCommandDispatcher.php @@ -13,7 +13,7 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandDispatcher; -use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\PaymentBundle\Exception\PaymentRequestNotSupportedException; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/CapturePaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/CapturePaymentRequestCommandProvider.php similarity index 82% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/CapturePaymentRequestCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/CapturePaymentRequestCommandProvider.php index 996ddb80a1..55a4fb78ee 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/CapturePaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/CapturePaymentRequestCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider\Offline; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\Offline; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline\CapturePaymentRequest; -use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class CapturePaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/StatusPaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php similarity index 82% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/StatusPaymentRequestCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php index 9fbcb6e302..cda3b2ab56 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/Offline/StatusPaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider\Offline; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\Offline; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline\StatusPaymentRequest; -use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class StatusPaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php similarity index 96% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php index 3216056806..55b1a212d7 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider; use Sylius\Bundle\CoreBundle\PaymentRequest\Checker\PaymentRequestDuplicationCheckerInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProviderInterface.php similarity index 88% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProviderInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProviderInterface.php index bfde835869..4aa7d60632 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestCommandProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProviderInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestTypeCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php similarity index 94% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestTypeCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php index fba8f6d579..a0dbc1804b 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/PaymentRequestTypeCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Contracts\Service\ServiceProviderInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/AuthorizeCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php similarity index 82% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/AuthorizeCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php index e5f44cbc16..236ebf8cd8 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/AuthorizeCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandProvider; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command\AuthorizePaymentRequest; -use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class AuthorizeCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/CaptureCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php similarity index 82% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/CaptureCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php index 6073558ead..98e03104fc 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/CaptureCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandProvider; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command\CapturePaymentRequest; -use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class CaptureCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/StatusCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php similarity index 82% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/StatusCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php index cf202363bc..3f0065d397 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Provider/StatusCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandProvider; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command\StatusPaymentRequest; -use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class StatusCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml index c19b3b6ff6..699e402815 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml @@ -18,17 +18,17 @@ - - + + - - + + - - + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml index c66b2a89a6..d631286bb5 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml @@ -18,21 +18,21 @@ - - + + - - + + - - + + - - + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml index 91a5a52b57..7ca3dac0f3 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml @@ -18,21 +18,21 @@ - - + + - - + + - - + + - - + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_dispatcher.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_dispatcher.xml index 50fda42a8d..81604384f2 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_dispatcher.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_dispatcher.xml @@ -20,7 +20,7 @@ - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml index 75ec387865..68902ecbdf 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml @@ -18,16 +18,16 @@ - + - + - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml index 1ba56942f4..6f7b7aae29 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml @@ -18,7 +18,7 @@ - + From b5d9ca230269224fe8133ade4b09c9a7f989224c Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 7 Feb 2024 15:02:40 +0100 Subject: [PATCH 032/200] Switch to new Sylius prefix --- .../config/api_resources/PaymentRequest.xml | 12 ++-- .../Commands/Payment/AddPaymentRequest.xml | 8 +-- .../Commands/Payment/UpdatePaymentRequest.xml | 2 +- .../config/serialization/PaymentRequest.xml | 72 +++++++++---------- 4 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml index d9a548c385..8203b85c8d 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/PaymentRequest.xml @@ -30,7 +30,7 @@ sylius.api.search_payment_request_filter - admin:payment_request:show + sylius:admin:payment_request:show @@ -40,10 +40,10 @@ input Sylius\Bundle\ApiBundle\Command\Payment\AddPaymentRequest - shop:payment_request:create + sylius:shop:payment_request:create - shop:payment_request:show + sylius:shop:payment_request:show @@ -53,7 +53,7 @@ GET /shop/payment-requests/{hash} - shop:payment_request:show + sylius:shop:payment_request:show @@ -63,11 +63,11 @@ input Sylius\Bundle\ApiBundle\Command\Payment\UpdatePaymentRequest - shop:payment_request:update + sylius:shop:payment_request:update - shop:payment_request:show + sylius:shop:payment_request:show diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml index 62ce8a8c04..a0e768f6fd 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml @@ -17,16 +17,16 @@ > - shop:payment_request:create + sylius:shop:payment_request:create - shop:payment_request:create + sylius:shop:payment_request:create - shop:payment_request:create + sylius:shop:payment_request:create - shop:payment_request:create + sylius:shop:payment_request:create diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/UpdatePaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/UpdatePaymentRequest.xml index 65bd2e1abc..141a328f66 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/UpdatePaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/UpdatePaymentRequest.xml @@ -17,7 +17,7 @@ > - shop:payment_request:update + sylius:shop:payment_request:update diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml index 009c851f2f..fc41ca9a2e 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml @@ -17,58 +17,58 @@ > - admin:payment_request:show - admin:payment_request:index - shop:payment_request:show - shop:payment_request:index + sylius:admin:payment_request:show + sylius:admin:payment_request:index + sylius:shop:payment_request:show + sylius:shop:payment_request:index - admin:payment_request:show - admin:payment_request:index - shop:payment_request:show - shop:payment_request:index + sylius:admin:payment_request:show + sylius:admin:payment_request:index + sylius:shop:payment_request:show + sylius:shop:payment_request:index - admin:payment_request:show - admin:payment_request:index - shop:payment_request:show - shop:payment_request:index + sylius:admin:payment_request:show + sylius:admin:payment_request:index + sylius:shop:payment_request:show + sylius:shop:payment_request:index - admin:payment_request:show - admin:payment_request:index - shop:payment_request:show - shop:payment_request:index + sylius:admin:payment_request:show + sylius:admin:payment_request:index + sylius:shop:payment_request:show + sylius:shop:payment_request:index - admin:payment_request:show - admin:payment_request:index - shop:payment_request:show - shop:payment_request:index + sylius:admin:payment_request:show + sylius:admin:payment_request:index + sylius:shop:payment_request:show + sylius:shop:payment_request:index - admin:payment_request:show - admin:payment_request:index - shop:payment_request:show - shop:payment_request:index + sylius:admin:payment_request:show + sylius:admin:payment_request:index + sylius:shop:payment_request:show + sylius:shop:payment_request:index - admin:payment_request:show - admin:payment_request:index - shop:payment_request:show - shop:payment_request:index + sylius:admin:payment_request:show + sylius:admin:payment_request:index + sylius:shop:payment_request:show + sylius:shop:payment_request:index - admin:payment_request:show - admin:payment_request:index - shop:payment_request:show - shop:payment_request:index + sylius:admin:payment_request:show + sylius:admin:payment_request:index + sylius:shop:payment_request:show + sylius:shop:payment_request:index - admin:payment_request:show - admin:payment_request:index - shop:payment_request:show - shop:payment_request:index + sylius:admin:payment_request:show + sylius:admin:payment_request:index + sylius:shop:payment_request:show + sylius:shop:payment_request:index From cf4acde282699404776134a5541c7848675cbbfe Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 21 Feb 2024 17:16:24 +0100 Subject: [PATCH 033/200] Remove no more needed method --- .../Applicator/PaymentStateMachineTransitionApplicator.php | 7 ------- .../PaymentStateMachineTransitionApplicatorInterface.php | 2 -- 2 files changed, 9 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicator.php b/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicator.php index b40c357097..ccbe66f3f9 100644 --- a/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicator.php +++ b/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicator.php @@ -44,13 +44,6 @@ final class PaymentStateMachineTransitionApplicator implements PaymentStateMachi return $data; } - public function process(PaymentInterface $data): PaymentInterface - { - $this->applyTransition($data, PaymentTransitions::TRANSITION_PROCESS); - - return $data; - } - private function applyTransition(PaymentInterface $payment, string $transition): void { $stateMachine = $this->getStateMachine(); diff --git a/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicatorInterface.php b/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicatorInterface.php index aa794e7fc7..4193a7f7f4 100644 --- a/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicatorInterface.php +++ b/src/Sylius/Bundle/ApiBundle/Applicator/PaymentStateMachineTransitionApplicatorInterface.php @@ -18,6 +18,4 @@ use Sylius\Component\Payment\Model\PaymentInterface; interface PaymentStateMachineTransitionApplicatorInterface { public function complete(PaymentInterface $data): PaymentInterface; - - public function process(PaymentInterface $data): PaymentInterface; } From ad3d6db21c664c4c9b4732f2c18e9f06a76a9516 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 21 Feb 2024 18:42:03 +0100 Subject: [PATCH 034/200] Remove messenger changes --- .../CoreBundle/Migrations/Version20240203222417.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/Migrations/Version20240203222417.php b/src/Sylius/Bundle/CoreBundle/Migrations/Version20240203222417.php index 6f4b946d5a..3f860852ec 100644 --- a/src/Sylius/Bundle/CoreBundle/Migrations/Version20240203222417.php +++ b/src/Sylius/Bundle/CoreBundle/Migrations/Version20240203222417.php @@ -32,12 +32,6 @@ final class Version20240203222417 extends AbstractPostgreSQLMigration $this->addSql('COMMENT ON COLUMN sylius_payment_request.request_payload IS \'(DC2Type:object)\''); $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B19883967 FOREIGN KEY (method_id) REFERENCES sylius_payment_method (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B4C3A3BB FOREIGN KEY (payment_id) REFERENCES sylius_payment (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE messenger_messages ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); - $this->addSql('ALTER TABLE messenger_messages ALTER available_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); - $this->addSql('ALTER TABLE messenger_messages ALTER delivered_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); - $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'(DC2Type:datetime_immutable)\''); - $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'(DC2Type:datetime_immutable)\''); - $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'(DC2Type:datetime_immutable)\''); } public function down(Schema $schema): void @@ -45,11 +39,5 @@ final class Version20240203222417 extends AbstractPostgreSQLMigration $this->addSql('ALTER TABLE sylius_payment_request DROP CONSTRAINT FK_86D904B19883967'); $this->addSql('ALTER TABLE sylius_payment_request DROP CONSTRAINT FK_86D904B4C3A3BB'); $this->addSql('DROP TABLE sylius_payment_request'); - $this->addSql('ALTER TABLE messenger_messages ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); - $this->addSql('ALTER TABLE messenger_messages ALTER available_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); - $this->addSql('ALTER TABLE messenger_messages ALTER delivered_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); - $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS NULL'); - $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS NULL'); - $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS NULL'); } } From 6f4101ded3811ca9a2e86f2cd4da0b3e3ccc0379 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 18:22:28 +0100 Subject: [PATCH 035/200] Wrong factory name --- .../services/integrations/payum/stripe.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml index 7ca3dac0f3..88adaa9e5c 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml @@ -18,21 +18,21 @@ - - - + + + - - + + - - + + - - + + From 475250ca158b7acba3d2919d6ed8935c8f4a3b34 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 18:28:31 +0100 Subject: [PATCH 036/200] Switch to Symfony uid --- composer.json | 3 +-- config/packages/uid.yaml | 4 ++++ .../Migrations/Version20231106190918.php | 2 +- .../Resources/config/app/config.yml | 8 ------- .../doctrine/model/PaymentRequest.orm.xml | 2 +- src/Sylius/Bundle/PaymentBundle/composer.json | 4 +--- .../Payment/Model/PaymentRequest.php | 7 +++--- .../Payment/Model/PaymentRequestInterface.php | 3 ++- src/Sylius/Component/Payment/composer.json | 3 ++- symfony.lock | 24 +++++++++---------- 10 files changed, 28 insertions(+), 32 deletions(-) create mode 100644 config/packages/uid.yaml diff --git a/composer.json b/composer.json index 473e9dff0c..bb1e4bdd96 100644 --- a/composer.json +++ b/composer.json @@ -70,8 +70,6 @@ "psr/http-client": "^1.0", "psr/http-message": "^1.0", "psr/log": "^2.0", - "ramsey/uuid": "^4.0", - "ramsey/uuid-doctrine": "^2.0", "sonata-project/block-bundle": "^4.2 || ^5.0", "stof/doctrine-extensions-bundle": "^1.4", "sylius-labs/association-hydrator": "^1.1 || ^1.2", @@ -133,6 +131,7 @@ "symfony/translation": "^6.4.0", "symfony/translation-contracts": "^2.5.2", "symfony/twig-bundle": "^6.4.0", + "symfony/uid": "^6.4.0", "symfony/ux-autocomplete": "^2.17", "symfony/ux-live-component": "^2.17", "symfony/ux-twig-component": "^2.17", diff --git a/config/packages/uid.yaml b/config/packages/uid.yaml new file mode 100644 index 0000000000..01520944f5 --- /dev/null +++ b/config/packages/uid.yaml @@ -0,0 +1,4 @@ +framework: + uid: + default_uuid_version: 7 + time_based_uuid_version: 7 diff --git a/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php b/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php index ee601d69b5..2a5e1ae996 100644 --- a/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php +++ b/src/Sylius/Bundle/CoreBundle/Migrations/Version20231106190918.php @@ -25,7 +25,7 @@ final class Version20231106190918 extends AbstractMigration public function up(Schema $schema): void { - $this->addSql('CREATE TABLE sylius_payment_request (hash CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, request_payload LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\', response_data JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_86D904B19883967 (method_id), INDEX IDX_86D904B4C3A3BB (payment_id), PRIMARY KEY(hash)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE sylius_payment_request (hash BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, request_payload LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\', response_data JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_86D904B19883967 (method_id), INDEX IDX_86D904B4C3A3BB (payment_id), PRIMARY KEY(hash)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B19883967 FOREIGN KEY (method_id) REFERENCES sylius_payment_method (id)'); $this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B4C3A3BB FOREIGN KEY (payment_id) REFERENCES sylius_payment (id)'); } diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml index dfc0ec5120..3615048869 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/app/config.yml @@ -1,14 +1,6 @@ # This file is part of the Sylius package. # (c) Sylius Sp. z o.o. -parameters: - sylius.uuid_type: Ramsey\Uuid\Doctrine\UuidType - -doctrine: - dbal: - types: - uuid: "%sylius.uuid_type%" - jms_serializer: metadata: directories: diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml index 7617b94729..7fbb85b2c4 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml @@ -17,7 +17,7 @@ - + diff --git a/src/Sylius/Bundle/PaymentBundle/composer.json b/src/Sylius/Bundle/PaymentBundle/composer.json index c2a03d9159..dce6337dad 100644 --- a/src/Sylius/Bundle/PaymentBundle/composer.json +++ b/src/Sylius/Bundle/PaymentBundle/composer.json @@ -29,9 +29,7 @@ "php": "^8.2", "sylius/payment": "^2.0", "sylius/resource-bundle": "^1.10", - "symfony/framework-bundle": "^6.4.1", - "symfony/messenger": "^6.4.0", - "ramsey/uuid-doctrine": "^2.0" + "symfony/framework-bundle": "^6.4.1" }, "conflict": { "doctrine/orm": "2.15.2" diff --git a/src/Sylius/Component/Payment/Model/PaymentRequest.php b/src/Sylius/Component/Payment/Model/PaymentRequest.php index 2880153b3f..b0da94ce9e 100644 --- a/src/Sylius/Component/Payment/Model/PaymentRequest.php +++ b/src/Sylius/Component/Payment/Model/PaymentRequest.php @@ -14,12 +14,13 @@ declare(strict_types=1); namespace Sylius\Component\Payment\Model; use Sylius\Component\Resource\Model\TimestampableTrait; +use Symfony\Component\Uid\Uuid; class PaymentRequest implements PaymentRequestInterface { use TimestampableTrait; - protected ?string $hash = null; + protected ?Uuid $hash = null; protected ?PaymentMethodInterface $method = null; @@ -40,10 +41,10 @@ class PaymentRequest implements PaymentRequestInterface public function getId(): ?string { - return $this->getHash(); + return $this->getHash()?->toBinary(); } - public function getHash(): ?string + public function getHash(): ?Uuid { return $this->hash; } diff --git a/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php index 554d488f94..d9e35cb3f9 100644 --- a/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php +++ b/src/Sylius/Component/Payment/Model/PaymentRequestInterface.php @@ -15,6 +15,7 @@ namespace Sylius\Component\Payment\Model; use Sylius\Component\Resource\Model\ResourceInterface; use Sylius\Component\Resource\Model\TimestampableInterface; +use Symfony\Component\Uid\Uuid; interface PaymentRequestInterface extends TimestampableInterface, ResourceInterface { @@ -40,7 +41,7 @@ interface PaymentRequestInterface extends TimestampableInterface, ResourceInterf public const DATA_TYPE_PAYOUT = 'payout'; - public function getHash(): ?string; + public function getHash(): ?Uuid; public function getMethod(): ?PaymentMethodInterface; diff --git a/src/Sylius/Component/Payment/composer.json b/src/Sylius/Component/Payment/composer.json index 2c6b5fae15..0ee205ff8e 100644 --- a/src/Sylius/Component/Payment/composer.json +++ b/src/Sylius/Component/Payment/composer.json @@ -28,7 +28,8 @@ "require": { "php": "^8.2", "sylius/registry": "^1.6", - "sylius/resource": "^1.10" + "sylius/resource": "^1.10", + "symfony/uid": "^5.4.21 || ^6.4" }, "require-dev": { "phpspec/phpspec": "^7.2" diff --git a/symfony.lock b/symfony.lock index 2755d00962..a9dc54b277 100644 --- a/symfony.lock +++ b/symfony.lock @@ -466,18 +466,6 @@ "ralouphie/getallheaders": { "version": "3.0.3" }, - "ramsey/uuid": { - "version": "3.8.0" - }, - "ramsey/uuid-doctrine": { - "version": "2.0", - "recipe": { - "repo": "github.com/symfony/recipes-contrib", - "branch": "main", - "version": "1.3", - "ref": "471aed0fbf5620b8d7f92b7a5ebbbf6c0945c27a" - } - }, "rector/rector": { "version": "0.11.52" }, @@ -879,6 +867,18 @@ "templates/base.html.twig" ] }, + "symfony/uid": { + "version": "6.4", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "6.2", + "ref": "d294ad4add3e15d7eb1bae0221588ca89b38e558" + }, + "files": [ + "config/packages/uid.yaml" + ] + }, "symfony/ux-autocomplete": { "version": "2.9999999", "recipe": { From 30d3af2d13e825629e826c265a2408c1ade4f53c Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 18:31:05 +0100 Subject: [PATCH 037/200] Add a trait to avoid code duplicates --- .../Command/Offline/CapturePaymentRequest.php | 15 +++------- .../Command/Offline/StatusPaymentRequest.php | 15 +++------- .../PaymentRequestHashAwareInterface.php | 4 +-- .../Command/PaymentRequestHashAwareTrait.php | 29 +++++++++++++++++++ .../Payum/Command/AuthorizePaymentRequest.php | 15 +++------- .../Payum/Command/CapturePaymentRequest.php | 15 +++------- .../Payum/Command/StatusPaymentRequest.php | 15 +++------- 7 files changed, 51 insertions(+), 57 deletions(-) create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareTrait.php diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/CapturePaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/CapturePaymentRequest.php index 1921179890..cac95cccc7 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/CapturePaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/CapturePaymentRequest.php @@ -14,21 +14,14 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareTrait; class CapturePaymentRequest implements PaymentRequestHashAwareInterface { + use PaymentRequestHashAwareTrait; + public function __construct( - protected string $hash, + protected ?string $hash, ) { } - - public function getHash(): string - { - return $this->hash; - } - - public function setHash(string $hash): void - { - $this->hash = $hash; - } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/StatusPaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/StatusPaymentRequest.php index ef2b56900c..b934dca71b 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/StatusPaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Offline/StatusPaymentRequest.php @@ -14,21 +14,14 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareTrait; class StatusPaymentRequest implements PaymentRequestHashAwareInterface { + use PaymentRequestHashAwareTrait; + public function __construct( - protected string $hash, + protected ?string $hash, ) { } - - public function getHash(): string - { - return $this->hash; - } - - public function setHash(string $hash): void - { - $this->hash = $hash; - } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareInterface.php index e821b42819..1d91518491 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareInterface.php @@ -16,7 +16,7 @@ namespace Sylius\Bundle\CoreBundle\PaymentRequest\Command; /** @experimental */ interface PaymentRequestHashAwareInterface { - public function getHash(): string; + public function getHash(): ?string; - public function setHash(string $hash): void; + public function setHash(?string $hash): void; } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareTrait.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareTrait.php new file mode 100644 index 0000000000..b80bc98654 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/PaymentRequestHashAwareTrait.php @@ -0,0 +1,29 @@ +hash; + } + + public function setHash(?string $hash): void + { + $this->hash = $hash; + } +} diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php index efd762eb09..e7d7d955ac 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php @@ -14,21 +14,14 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareTrait; class AuthorizePaymentRequest implements PaymentRequestHashAwareInterface { + use PaymentRequestHashAwareTrait; + public function __construct( - protected string $hash, + protected ?string $hash, ) { } - - public function getHash(): string - { - return $this->hash; - } - - public function setHash(string $hash): void - { - $this->hash = $hash; - } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php index 02d46df93c..b6dc938a55 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php @@ -14,21 +14,14 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareTrait; class CapturePaymentRequest implements PaymentRequestHashAwareInterface { + use PaymentRequestHashAwareTrait; + public function __construct( - protected string $hash, + protected ?string $hash, ) { } - - public function getHash(): string - { - return $this->hash; - } - - public function setHash(string $hash): void - { - $this->hash = $hash; - } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php index 00797f6150..c22d7e11cf 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php @@ -14,21 +14,14 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareTrait; class StatusPaymentRequest implements PaymentRequestHashAwareInterface { + use PaymentRequestHashAwareTrait; + public function __construct( - protected string $hash, + protected ?string $hash, ) { } - - public function getHash(): string - { - return $this->hash; - } - - public function setHash(string $hash): void - { - $this->hash = $hash; - } } From fe5ad0827601045bb6f89b6fc8c4ea0528dc97f1 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 18:31:40 +0100 Subject: [PATCH 038/200] Required changes to use Symfony uid component --- ...entRequestHashAwareInputCommandDataTransformer.php | 7 ++++++- .../Offline/CapturePaymentRequestHandler.php | 5 ++++- .../Offline/CapturePaymentRequestCommandProvider.php | 2 +- .../Offline/StatusPaymentRequestCommandProvider.php | 2 +- .../CommandProvider/PaymentRequestCommandProvider.php | 6 ++---- .../PaymentRequestTypeCommandProvider.php | 11 +++-------- .../CommandHandler/ModelPaymentRequestHandler.php | 5 ++++- .../CommandHandler/TokenPaymentRequestHandler.php | 5 ++++- .../CommandProvider/AuthorizeCommandProvider.php | 2 +- .../Payum/CommandProvider/CaptureCommandProvider.php | 2 +- .../Payum/CommandProvider/StatusCommandProvider.php | 2 +- .../Doctrine/ORM/PaymentRequestRepository.php | 3 ++- 12 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/DataTransformer/PaymentRequestHashAwareInputCommandDataTransformer.php b/src/Sylius/Bundle/ApiBundle/DataTransformer/PaymentRequestHashAwareInputCommandDataTransformer.php index 2b2591abc4..4ebeecf733 100644 --- a/src/Sylius/Bundle/ApiBundle/DataTransformer/PaymentRequestHashAwareInputCommandDataTransformer.php +++ b/src/Sylius/Bundle/ApiBundle/DataTransformer/PaymentRequestHashAwareInputCommandDataTransformer.php @@ -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; } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php index 26750e90e4..e8505855fc 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php @@ -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 */ diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/CapturePaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/CapturePaymentRequestCommandProvider.php index 55a4fb78ee..36169787a9 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/CapturePaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/CapturePaymentRequestCommandProvider.php @@ -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()); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php index cda3b2ab56..39fbce1ca1 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php @@ -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()); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php index 55b1a212d7..4ccf6cba73 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php @@ -23,6 +23,7 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid { public function __construct( private PaymentRequestDuplicationCheckerInterface $paymentRequestDuplicationChecker, + /** @var ServiceProviderInterface */ 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); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php index a0dbc1804b..c0b548f70d 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php @@ -19,23 +19,18 @@ use Symfony\Contracts\Service\ServiceProviderInterface; final class PaymentRequestTypeCommandProvider implements PaymentRequestCommandProviderInterface { public function __construct( + /** @var ServiceProviderInterface */ 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); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php index bbf1f3d17b..2339b15dc2 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php @@ -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(); diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php index 81df149ca1..cbc794333f 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php @@ -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); diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php index 236ebf8cd8..44ebfb6a6b 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php @@ -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()); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php index 98e03104fc..81876eaf4f 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php @@ -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()); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php index 3f0065d397..16d3c7fd8b 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php @@ -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()); } } diff --git a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php index af750bf70f..71aad1bca2 100644 --- a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php +++ b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php @@ -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()) From de668e900a715c5ed85381013017915d288e39aa Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 18:47:08 +0100 Subject: [PATCH 039/200] Symfony style error message --- .../CommandHandler/Payment/AddPaymentRequestHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index 3800b698b7..249988e148 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -51,14 +51,14 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface 'code' => $addPaymentRequest->getPaymentMethodCode(), ]); Assert::notNull($paymentMethod, sprintf( - 'Payment method code "%s", can not be found!', + 'Payment method (code "%s") not found.', $addPaymentRequest->getPaymentMethodCode(), )); /** @var PaymentInterface|null $payment */ $payment = $this->paymentRepository->find($addPaymentRequest->getPaymentId()); Assert::notNull( $payment, - sprintf('Payment ID "%s" can not be found!', $addPaymentRequest->getPaymentId()), + sprintf('Payment (id "%s") not found.', $addPaymentRequest->getPaymentId()), ); $paymentRequest = $this->paymentRequestFactory->createWithPaymentAndPaymentMethod($payment, $paymentMethod); From a6586bb25ed212df68bb1ee5050f7175f28ef2bb Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 19:19:24 +0100 Subject: [PATCH 040/200] Add clear assert message --- .../Payment/UpdatePaymentRequestHandler.php | 4 ++-- .../Offline/CapturePaymentRequestHandler.php | 8 ++++---- .../CommandHandler/ModelPaymentRequestHandler.php | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php index 8d9f5129b2..28f59f4a47 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php @@ -32,10 +32,10 @@ final class UpdatePaymentRequestHandler implements MessageHandlerInterface public function __invoke(UpdatePaymentRequest $updatePaymentRequest): PaymentRequestInterface { $hash = $updatePaymentRequest->getHash(); - Assert::notNull($hash); + Assert::notNull($hash, 'Payment request hash cannot be null.'); $paymentRequest = $this->paymentRequestRepository->findOneByHash($hash); - Assert::notNull($paymentRequest); + Assert::notNull($paymentRequest, sprintf('Payment request (hash "%s") not found.', $hash)); $paymentRequest->setRequestPayload($updatePaymentRequest->getRequestPayload()); diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php index e8505855fc..78d9da3436 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php @@ -36,17 +36,17 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface public function __invoke(CapturePaymentRequest $capturePaymentRequest): void { $hash = $capturePaymentRequest->getHash(); - Assert::notNull($hash, 'The payment request hash cannot be null.'); + Assert::notNull($hash, 'Payment request hash cannot be null.'); $paymentRequest = $this->paymentRequestRepository->findOneByHash($hash); - Assert::notNull($paymentRequest); + Assert::notNull($paymentRequest, sprintf('Payment request (hash "%s") not found.', $hash)); /** @var PaymentMethodInterface|null $paymentMethod */ $paymentMethod = $paymentRequest->getMethod(); - Assert::notNull($paymentMethod); + Assert::notNull($paymentMethod, 'Payment cannot be null.'); $gatewayConfig = $paymentMethod->getGatewayConfig(); - Assert::notNull($gatewayConfig); + Assert::notNull($gatewayConfig, 'Payment method cannot be null.'); $factoryName = $gatewayConfig->getConfig()['factory'] ?? $gatewayConfig->getFactoryName(); Assert::eq($factoryName, self::FACTORY_NAME, 'Expected a factory name equal to %2$s. Got: %s'); diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php index 2339b15dc2..78f4707dee 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php @@ -33,22 +33,22 @@ final class ModelPaymentRequestHandler implements MessageHandlerInterface public function __invoke(PaymentRequestHashAwareInterface $command): void { $hash = $command->getHash(); - Assert::notNull($hash, 'The payment request hash cannot be null.'); + Assert::notNull($hash, 'Payment request hash cannot be null.'); $paymentRequest = $this->paymentRequestProvider->provideFromHash($hash); - Assert::notNull($paymentRequest); + Assert::notNull($paymentRequest, sprintf('Payment request (hash "%s") not found.', $hash)); $payment = $paymentRequest->getPayment(); - Assert::notNull($payment); + Assert::notNull($payment, 'Payment cannot be null.'); $request = $this->factory->createNewWithModel($payment); /** @var PaymentMethodInterface|null $paymentMethod */ $paymentMethod = $paymentRequest->getMethod(); - Assert::notNull($paymentMethod); + Assert::notNull($paymentMethod, 'Payment method cannot be null.'); $gatewayConfig = $paymentMethod->getGatewayConfig(); - Assert::notNull($gatewayConfig); + Assert::notNull($gatewayConfig, 'Gateway config cannot be null.'); $gatewayName = $gatewayConfig->getGatewayName(); From b56cc9474f659fbc421eaeadd6c3605fa07b01ee Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 20:00:02 +0100 Subject: [PATCH 041/200] Move Payum Command* to the upper level --- .../Payum}/AuthorizePaymentRequest.php | 2 +- .../Payum}/CapturePaymentRequest.php | 2 +- .../Payum}/StatusPaymentRequest.php | 2 +- .../Payum}/ModelPaymentRequestHandler.php | 2 +- .../Payum}/TokenPaymentRequestHandler.php | 2 +- .../Payum}/AuthorizeCommandProvider.php | 4 ++-- .../Payum}/CaptureCommandProvider.php | 4 ++-- .../Payum}/StatusCommandProvider.php | 4 ++-- .../services/integrations/payum/offline.xml | 14 ++++++------- .../payum/paypal_express_checkout.xml | 10 +++++----- .../services/integrations/payum/stripe.xml | 18 ++++++++--------- .../services/payment_request/offline.xml | 2 +- .../payment_request/payum/comman_handlers.xml | 20 +++++++++---------- .../services/payment_request/provider.xml | 2 +- 14 files changed, 44 insertions(+), 44 deletions(-) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/Command => Command/Payum}/AuthorizePaymentRequest.php (90%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/Command => Command/Payum}/CapturePaymentRequest.php (90%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/Command => Command/Payum}/StatusPaymentRequest.php (90%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/CommandHandler => CommandHandler/Payum}/ModelPaymentRequestHandler.php (96%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/CommandHandler => CommandHandler/Payum}/TokenPaymentRequestHandler.php (96%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/CommandProvider => CommandProvider/Payum}/AuthorizeCommandProvider.php (86%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/CommandProvider => CommandProvider/Payum}/CaptureCommandProvider.php (86%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/CommandProvider => CommandProvider/Payum}/StatusCommandProvider.php (86%) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Payum/AuthorizePaymentRequest.php similarity index 90% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Payum/AuthorizePaymentRequest.php index e7d7d955ac..b9cddab3b7 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/AuthorizePaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Payum/AuthorizePaymentRequest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Command\Payum; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareTrait; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Payum/CapturePaymentRequest.php similarity index 90% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Payum/CapturePaymentRequest.php index b6dc938a55..4148a5c29c 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/CapturePaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Payum/CapturePaymentRequest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Command\Payum; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareTrait; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Payum/StatusPaymentRequest.php similarity index 90% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Payum/StatusPaymentRequest.php index c22d7e11cf..2293332dbe 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Command/StatusPaymentRequest.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Command/Payum/StatusPaymentRequest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Command\Payum; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareTrait; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php similarity index 96% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php index 78f4707dee..62ba179f49 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/ModelPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandHandler; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandHandler\Payum; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor\RequestProcessorInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php similarity index 96% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php index cbc794333f..2e3a604530 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandHandler/TokenPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandHandler; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandHandler\Payum; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Factory\PayumTokenFactoryInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Payum/AuthorizeCommandProvider.php similarity index 86% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Payum/AuthorizeCommandProvider.php index 44ebfb6a6b..6433d1f218 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/AuthorizeCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Payum/AuthorizeCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandProvider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\Payum; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Payum\AuthorizePaymentRequest; use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; -use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command\AuthorizePaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class AuthorizeCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Payum/CaptureCommandProvider.php similarity index 86% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Payum/CaptureCommandProvider.php index 81876eaf4f..72c77e200a 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/CaptureCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Payum/CaptureCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandProvider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\Payum; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Payum\CapturePaymentRequest; use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; -use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command\CapturePaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class CaptureCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Payum/StatusCommandProvider.php similarity index 86% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Payum/StatusCommandProvider.php index 16d3c7fd8b..3ec97d1d80 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/CommandProvider/StatusCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Payum/StatusCommandProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\CommandProvider; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\Payum; +use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Payum\StatusPaymentRequest; use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; -use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Command\StatusPaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class StatusCommandProvider implements PaymentRequestCommandProviderInterface diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml index 699e402815..d2f4b8db15 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml @@ -18,17 +18,17 @@ - - - + + + - - + + - - + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml index d631286bb5..ccdacd325b 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml @@ -19,20 +19,20 @@ - - + + - + - + - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml index 88adaa9e5c..0e565a19af 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml @@ -18,21 +18,21 @@ - - - + + + - - + + - - + + - - + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml index 68902ecbdf..d9e6255a39 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml @@ -20,7 +20,7 @@ - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml index 4d9b255b2f..5f98c40e37 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml @@ -18,34 +18,34 @@ - + - + - - + + - + - - + + - + - - + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml index 6f7b7aae29..3a2d64158c 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/provider.xml @@ -20,7 +20,7 @@ - + From 76e3689fdc4025883ee453485e04f77e8acd5770 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 20:01:32 +0100 Subject: [PATCH 042/200] Fix wrong type --- .../Offline/StatusPaymentRequestCommandProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php index 39fbce1ca1..d1dcc7c8c3 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/Offline/StatusPaymentRequestCommandProvider.php @@ -21,7 +21,7 @@ final class StatusPaymentRequestCommandProvider implements PaymentRequestCommand { public function supports(PaymentRequestInterface $paymentRequest): bool { - return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_CAPTURE; + return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_STATUS; } public function provide(PaymentRequestInterface $paymentRequest): object From 873b4f3c423a292eec1549a765fdc3674935f66d Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 20:05:01 +0100 Subject: [PATCH 043/200] Lower down default uuid version to 6 for Sf 5.4 --- config/packages/uid.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/packages/uid.yaml b/config/packages/uid.yaml index 01520944f5..31926f02ff 100644 --- a/config/packages/uid.yaml +++ b/config/packages/uid.yaml @@ -1,4 +1,4 @@ framework: uid: - default_uuid_version: 7 - time_based_uuid_version: 7 + default_uuid_version: 6 + time_based_uuid_version: 6 From f8d2ee9f087ef537fae2166bf25df038d8404836 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 20:35:20 +0100 Subject: [PATCH 044/200] Remaning classes to move around --- .../Offline/CapturePaymentRequestHandler.php | 8 ++--- .../Payum/ModelPaymentRequestHandler.php | 2 +- .../Payum/TokenPaymentRequestHandler.php | 4 +-- .../AfterCaptureProcessor.php} | 4 +-- .../AfterCaptureProcessorInterface.php} | 4 +-- .../CaptureProcessor.php} | 4 +-- .../CaptureProcessorInterface.php} | 4 +-- .../Payum}/AfterTokenRequestProcessor.php | 2 +- .../AfterTokenRequestProcessorInterface.php | 2 +- .../Payum}/RequestProcessor.php | 2 +- .../Payum}/RequestProcessorInterface.php | 2 +- .../config/services/payment_request.xml | 1 + .../offline/command_handlers.xml | 30 +++++++++++++++++++ .../command_providers.xml} | 14 --------- .../payment_request/offline/processors.xml | 28 +++++++++++++++++ ...mman_handlers.xml => command_handlers.xml} | 8 ++--- .../payment_request/payum/factory.xml | 5 ---- .../payment_request/payum/processors.xml | 7 ++++- 18 files changed, 88 insertions(+), 43 deletions(-) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/{AfterOfflineCaptureProcessor.php => Offline/AfterCaptureProcessor.php} (91%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/{AfterOfflineCaptureProcessorInterface.php => Offline/AfterCaptureProcessorInterface.php} (77%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/{OfflineCaptureProcessor.php => Offline/CaptureProcessor.php} (86%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/{OfflineCaptureProcessorInterface.php => Offline/CaptureProcessorInterface.php} (78%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/Processor => Processor/Payum}/AfterTokenRequestProcessor.php (95%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/Processor => Processor/Payum}/AfterTokenRequestProcessorInterface.php (88%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/Processor => Processor/Payum}/RequestProcessor.php (95%) rename src/Sylius/Bundle/CoreBundle/PaymentRequest/{Payum/Processor => Processor/Payum}/RequestProcessorInterface.php (87%) create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml rename src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/{offline.xml => offline/command_providers.xml} (57%) create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/processors.xml rename src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/{comman_handlers.xml => command_handlers.xml} (92%) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php index 78d9da3436..80a4a95771 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandHandler\Offline; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline\CapturePaymentRequest; -use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\AfterOfflineCaptureProcessorInterface; -use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\OfflineCaptureProcessorInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Offline\AfterCaptureProcessorInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Offline\CaptureProcessorInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; @@ -28,8 +28,8 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface public function __construct( private PaymentRequestRepositoryInterface $paymentRequestRepository, - private OfflineCaptureProcessorInterface $offlineCaptureProcessor, - private AfterOfflineCaptureProcessorInterface $afterOfflineCaptureProcessor, + private CaptureProcessorInterface $offlineCaptureProcessor, + private AfterCaptureProcessorInterface $afterOfflineCaptureProcessor, ) { } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php index 62ba179f49..6b47d0057a 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandHandler\Payum; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; -use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor\RequestProcessorInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider\PaymentRequestProviderInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Payum\RequestProcessorInterface; use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php index 2e3a604530..c4bcd1c813 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php @@ -15,9 +15,9 @@ namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandHandler\Payum; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\PaymentRequestHashAwareInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Factory\PayumTokenFactoryInterface; -use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor\AfterTokenRequestProcessorInterface; -use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor\RequestProcessorInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Provider\PaymentRequestProviderInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Payum\AfterTokenRequestProcessorInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Payum\RequestProcessorInterface; use Sylius\Bundle\PayumBundle\Factory\TokenAggregateRequestFactoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessor.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/AfterCaptureProcessor.php similarity index 91% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessor.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/AfterCaptureProcessor.php index 4c8d4ba58c..2ab5a7bfb4 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/AfterCaptureProcessor.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Offline; use SM\Factory\FactoryInterface as StateMachineFactoryInterface; use Sylius\Abstraction\StateMachine\StateMachineInterface; @@ -19,7 +19,7 @@ use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\PaymentTransitions; use Webmozart\Assert\Assert; -final class AfterOfflineCaptureProcessor implements AfterOfflineCaptureProcessorInterface +final class AfterCaptureProcessor implements AfterCaptureProcessorInterface { public function __construct( private StateMachineFactoryInterface|StateMachineInterface $stateMachineFactory, diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/AfterCaptureProcessorInterface.php similarity index 77% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessorInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/AfterCaptureProcessorInterface.php index 6fb6fc0ecb..9314b59b88 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/AfterOfflineCaptureProcessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/AfterCaptureProcessorInterface.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Offline; use Sylius\Component\Payment\Model\PaymentRequestInterface; -interface AfterOfflineCaptureProcessorInterface +interface AfterCaptureProcessorInterface { public function process(PaymentRequestInterface $paymentRequest): void; } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessor.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessor.php similarity index 86% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessor.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessor.php index 7a43444829..000705d13b 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessor.php @@ -11,13 +11,13 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Offline; use Sylius\Component\Payment\Model\PaymentInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Webmozart\Assert\Assert; -final class OfflineCaptureProcessor implements OfflineCaptureProcessorInterface +final class CaptureProcessor implements CaptureProcessorInterface { public function process(PaymentRequestInterface $paymentRequest): void { diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessorInterface.php similarity index 78% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessorInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessorInterface.php index c5fadd9a28..e645bb7892 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/OfflineCaptureProcessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessorInterface.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Offline; use Sylius\Component\Payment\Model\PaymentRequestInterface; -interface OfflineCaptureProcessorInterface +interface CaptureProcessorInterface { public function process(PaymentRequestInterface $paymentRequest): void; } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessor.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/AfterTokenRequestProcessor.php similarity index 95% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessor.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/AfterTokenRequestProcessor.php index 72c6951fe5..946554ef30 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/AfterTokenRequestProcessor.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Payum; use Payum\Core\Security\TokenInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\CommandDispatcher\PaymentRequestCommandDispatcherInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/AfterTokenRequestProcessorInterface.php similarity index 88% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessorInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/AfterTokenRequestProcessorInterface.php index 7efa21cc57..8a37ea1ec7 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/AfterTokenRequestProcessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/AfterTokenRequestProcessorInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Payum; use Payum\Core\Security\TokenInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessor.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/RequestProcessor.php similarity index 95% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessor.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/RequestProcessor.php index f7b284e3f2..2a222b024d 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/RequestProcessor.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Payum; use Payum\Core\Payum; use Payum\Core\Security\TokenAggregateInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/RequestProcessorInterface.php similarity index 87% rename from src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessorInterface.php rename to src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/RequestProcessorInterface.php index 9240c8f35c..d45dcd64cc 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Processor/RequestProcessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Payum/RequestProcessorInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\CoreBundle\PaymentRequest\Payum\Processor; +namespace Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Payum; use Sylius\Component\Payment\Model\PaymentRequestInterface; diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request.xml index 88c557ee3d..0c3206a7ab 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request.xml @@ -15,6 +15,7 @@ + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml new file mode 100644 index 0000000000..90ffc8d14f --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml similarity index 57% rename from src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml rename to src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml index d9e6255a39..841aa332f5 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml @@ -31,19 +31,5 @@ - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/processors.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/processors.xml new file mode 100644 index 0000000000..d02b55a96a --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/processors.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/command_handlers.xml similarity index 92% rename from src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml rename to src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/command_handlers.xml index 5f98c40e37..41f4acb861 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/comman_handlers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/command_handlers.xml @@ -21,8 +21,8 @@ - - + + @@ -39,10 +39,10 @@ - + - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/factory.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/factory.xml index 1325861659..d437b72e59 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/factory.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/factory.xml @@ -18,11 +18,6 @@ - - - - - diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/processors.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/processors.xml index d06abf84ae..aa775ce196 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/processors.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/processors.xml @@ -18,7 +18,12 @@ - + + + + + + From c021f6e757ac7fc9faa5cb7e28605cedb1d371c2 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 21:52:01 +0100 Subject: [PATCH 045/200] Missing service renaming --- .../services/integrations/payum/paypal_express_checkout.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml index ccdacd325b..dc6bcb18f9 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml @@ -23,15 +23,15 @@ - + - + - + From 3e9c3cba9ef22417d0ea43abd9fcefe9a363c947 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 22:11:04 +0100 Subject: [PATCH 046/200] Fix PHPStan error on Sf 5.4 --- .../CommandProvider/PaymentRequestCommandProvider.php | 1 - .../CommandProvider/PaymentRequestTypeCommandProvider.php | 1 - .../PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php | 5 +++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php index 4ccf6cba73..a58e0156f4 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestCommandProvider.php @@ -23,7 +23,6 @@ final class PaymentRequestCommandProvider implements PaymentRequestCommandProvid { public function __construct( private PaymentRequestDuplicationCheckerInterface $paymentRequestDuplicationChecker, - /** @var ServiceProviderInterface */ private ServiceProviderInterface $locator, ) { } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php index c0b548f70d..218bb5d588 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/PaymentRequestTypeCommandProvider.php @@ -19,7 +19,6 @@ use Symfony\Contracts\Service\ServiceProviderInterface; final class PaymentRequestTypeCommandProvider implements PaymentRequestCommandProviderInterface { public function __construct( - /** @var ServiceProviderInterface */ private ServiceProviderInterface $locator, ) { } diff --git a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php index 71aad1bca2..66e1e9acbf 100644 --- a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php +++ b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php @@ -16,7 +16,6 @@ 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 @@ -34,7 +33,9 @@ class PaymentRequestRepository extends EntityRepository implements PaymentReques ->andWhere('o.type = :type') ->andWhere('o.payment = :payment') ->andWhere('o.method = :method') - ->setParameter('paymentRequest', $paymentRequest->getHash(), UuidType::NAME) + // Symfony\Bridge\Doctrine\Types\UuidType has signature changes between sf 5.4 and 6.4 + // We are forced to use type: "uuid" to use both Sf versions + ->setParameter('paymentRequest', $paymentRequest->getHash(), 'uuid') ->setParameter('type', $paymentRequest->getType()) ->setParameter('method', $paymentRequest->getMethod()) ->setParameter('payment', $paymentRequest->getPayment()) From eba9688871760b648d6196165d57381cfca7c8ff Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 22:50:32 +0100 Subject: [PATCH 047/200] Remove not required suggestion --- src/Sylius/Bundle/PayumBundle/composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/PayumBundle/composer.json b/src/Sylius/Bundle/PayumBundle/composer.json index 792d1993a0..9f3b61ef4a 100644 --- a/src/Sylius/Bundle/PayumBundle/composer.json +++ b/src/Sylius/Bundle/PayumBundle/composer.json @@ -44,8 +44,7 @@ }, "suggest": { "payum/paypal-express-checkout-nvp": "To use PayPal Express Chekout NVP", - "payum/stripe": "To use Stripe Checkout", - "sylius/api-bundle": "To use Payum with the Sylius API Bundle" + "payum/stripe": "To use Stripe Checkout" }, "config": { "allow-plugins": { From 3a6ad1dafde04ccdbc97df8b7b3d446ee8797190 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 23:04:39 +0100 Subject: [PATCH 048/200] Readd ramsey uuid needed for AttributeBundle --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index bb1e4bdd96..822710b3ca 100644 --- a/composer.json +++ b/composer.json @@ -70,6 +70,7 @@ "psr/http-client": "^1.0", "psr/http-message": "^1.0", "psr/log": "^2.0", + "ramsey/uuid": "^4.0", "sonata-project/block-bundle": "^4.2 || ^5.0", "stof/doctrine-extensions-bundle": "^1.4", "sylius-labs/association-hydrator": "^1.1 || ^1.2", From 531a0c68ff9e4880d8848d05c50b81159e14bf1b Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 22 Feb 2024 23:10:11 +0100 Subject: [PATCH 049/200] Rename type to action --- src/Sylius/Behat/Context/Api/PaypalContext.php | 6 +++--- .../Command/Payment/AddPaymentRequest.php | 8 ++++---- .../Payment/AddPaymentRequestHandler.php | 2 +- .../Commands/Payment/AddPaymentRequest.xml | 2 +- .../config/serialization/PaymentRequest.xml | 2 +- .../config/validation/AddPaymentRequest.xml | 2 +- .../Migrations/Version20231106190918.php | 2 +- .../Migrations/Version20240203222417.php | 2 +- .../CapturePaymentRequestCommandProvider.php | 2 +- .../StatusPaymentRequestCommandProvider.php | 2 +- .../PaymentRequestTypeCommandProvider.php | 4 ++-- .../Payum/AuthorizeCommandProvider.php | 2 +- .../Payum/CaptureCommandProvider.php | 2 +- .../Payum/StatusCommandProvider.php | 2 +- .../Payum/AfterTokenRequestProcessor.php | 2 +- .../Doctrine/ORM/PaymentRequestRepository.php | 4 ++-- .../config/doctrine/model/PaymentRequest.orm.xml | 2 +- .../Component/Payment/Model/PaymentRequest.php | 10 +++++----- .../Payment/Model/PaymentRequestInterface.php | 16 ++++++++-------- .../Payment/spec/Model/PaymentRequestSpec.php | 10 +++++----- 20 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/Sylius/Behat/Context/Api/PaypalContext.php b/src/Sylius/Behat/Context/Api/PaypalContext.php index fb14fb641d..f77234f36d 100644 --- a/src/Sylius/Behat/Context/Api/PaypalContext.php +++ b/src/Sylius/Behat/Context/Api/PaypalContext.php @@ -167,9 +167,9 @@ final class PaypalContext implements Context $request->setContent([ 'paymentId' => $payment['@id'], 'paymentMethodCode' => $payment['method'], - 'type' => $authorize - ? PaymentRequestInterface::DATA_TYPE_AUTHORIZE - : PaymentRequestInterface::DATA_TYPE_CAPTURE, + 'action' => $authorize + ? PaymentRequestInterface::ACTION_AUTHORIZE + : PaymentRequestInterface::ACTION_CAPTURE, 'requestPayload' => [ 'target_path' => 'https://myshop.tld/target-path', 'after_path' => 'https://myshop.tld/after-path', diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php index 0acf1e7922..1a0da80776 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php @@ -21,8 +21,8 @@ class AddPaymentRequest implements IriToIdentifierConversionAwareInterface public function __construct( private string $paymentId, private string $paymentMethodCode, - private string $type, - private mixed $requestPayload = null, + private string $action, + private mixed $requestPayload = null, ) { } @@ -36,9 +36,9 @@ class AddPaymentRequest implements IriToIdentifierConversionAwareInterface return $this->paymentMethodCode; } - public function getType(): string + public function getAction(): string { - return $this->type; + return $this->action; } public function getRequestPayload(): mixed diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index 249988e148..2221ffc99c 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -62,7 +62,7 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface ); $paymentRequest = $this->paymentRequestFactory->createWithPaymentAndPaymentMethod($payment, $paymentMethod); - $paymentRequest->setType($addPaymentRequest->getType()); + $paymentRequest->setAction($addPaymentRequest->getAction()); $paymentRequest->setRequestPayload($addPaymentRequest->getRequestPayload()); return $paymentRequest; diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml index a0e768f6fd..50ef1971bd 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Payment/AddPaymentRequest.xml @@ -22,7 +22,7 @@ sylius:shop:payment_request:create - + sylius:shop:payment_request:create diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml index fc41ca9a2e..59b364667b 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/PaymentRequest.xml @@ -34,7 +34,7 @@ sylius:shop:payment_request:show sylius:shop:payment_request:index - + sylius:admin:payment_request:show sylius:admin:payment_request:index sylius:shop:payment_request:show diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml index 0010c3cc42..c55d75edac 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml @@ -27,7 +27,7 @@ - + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml index c55d75edac..0d3b8a2a18 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml @@ -13,6 +13,11 @@ + + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml index b3ec867ac1..fcc16fd90e 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml @@ -54,5 +54,18 @@ + + + + + + + sylius.order + + + + + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml new file mode 100644 index 0000000000..06053cac32 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + From 30b87592dab924f204474cc2474efb9589f24b52 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 28 Aug 2024 22:46:25 +0200 Subject: [PATCH 127/200] Replace else by a return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Góralski --- .../Provider/PayumPayResponseProvider.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php index 0eec1bf3c4..1bb03d3ea8 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php @@ -87,14 +87,7 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface $tokenFactory = $this->payum->getTokenFactory(); if (isset($config['use_authorize']) && true === (bool) $config['use_authorize']) { - $token = $tokenFactory->createAuthorizeToken( - $gatewayConfig->getGatewayName(), - $payment, - $redirectOptions['route'] ?? null, - $redirectOptions['parameters'] ?? [], - ); - } else { - $token = $tokenFactory->createCaptureToken( + return $tokenFactory->createAuthorizeToken( $gatewayConfig->getGatewayName(), $payment, $redirectOptions['route'] ?? null, @@ -102,7 +95,12 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface ); } - return $token; + return $tokenFactory->createCaptureToken( + $gatewayConfig->getGatewayName(), + $payment, + $redirectOptions['route'] ?? null, + $redirectOptions['parameters'] ?? [], + ); } private function getPaymentFromOrder(OrderInterface $order): ?PaymentInterface From 55c8043dcce6d6058ffb57ce17825b98ce8b8dca Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 28 Aug 2024 22:47:01 +0200 Subject: [PATCH 128/200] Format new line Co-authored-by: Dmitri Perunov --- .../Bundle/ShopBundle/Provider/DefaultPayResponseProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/DefaultPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/DefaultPayResponseProvider.php index d4b875441a..66b8b8f5ab 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/DefaultPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/DefaultPayResponseProvider.php @@ -34,6 +34,7 @@ final class DefaultPayResponseProvider implements PayResponseProviderInterface return new RedirectResponse($url); } + public function supports( RequestConfiguration $requestConfiguration, OrderInterface $order From 46e7bcc3ca0d175beeeb55295010b0dd8841c3b0 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 28 Aug 2024 22:47:23 +0200 Subject: [PATCH 129/200] Explicit assert Co-authored-by: Dmitri Perunov --- .../Bundle/ShopBundle/Provider/PayumPayResponseProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php index 1bb03d3ea8..d21f731f37 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php @@ -37,7 +37,7 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface OrderInterface $order ): Response { $payment = $this->getPaymentFromOrder($order); - Assert::notNull($payment, 'An existing payment with state "new" must exist.'); + Assert::notNull($payment, sprintf('Order (id %s) must have last payment in state "new".', $order->getId()); $redirectOptions = $requestConfiguration->getParameters()->get('redirect'); if (is_string($redirectOptions)) { From f204d119b536a0f9cd490b32b8815861552e8813 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 28 Aug 2024 22:47:41 +0200 Subject: [PATCH 130/200] Format new line Co-authored-by: Dmitri Perunov --- .../ShopBundle/Provider/PaymentRequestPayResponseProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php index 13c0bf9145..2cb94e7060 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php @@ -25,6 +25,7 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte ): Response { return new Response('', Response::HTTP_NO_CONTENT); } + public function supports( RequestConfiguration $requestConfiguration, OrderInterface $order From 6b2177b507c9f2e38d458976aa20967c5d4852af Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 28 Aug 2024 22:51:21 +0200 Subject: [PATCH 131/200] Simplify gateway check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Góralski --- .../ShopBundle/Provider/PayumPayResponseProvider.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php index d21f731f37..6cdee5cbf8 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php @@ -66,13 +66,7 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface $gatewayName = $gatewayConfig->getGatewayName() ?? ''; - try { - $this->payum->getGateway($gatewayName); - } catch (InvalidArgumentException) { - return false; - } - - return true; + return isset($this->payum->getGateways()[$gatewayName]); } /** From ab16307e7f6917d0dd3685a3bc57df917b6bd17f Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 29 Aug 2024 00:06:14 +0300 Subject: [PATCH 132/200] Remove default response provider and introduce LogicException instead --- .../Bundle/ShopBundle/Controller/OrderPayController.php | 4 ++-- ...onseProvider.php => NoPaymentPayResponseProvider.php} | 9 ++++++--- .../ShopBundle/Resources/config/services/controller.xml | 1 - .../ShopBundle/Resources/config/services/providers.xml | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) rename src/Sylius/Bundle/ShopBundle/Provider/{DefaultPayResponseProvider.php => NoPaymentPayResponseProvider.php} (81%) diff --git a/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php b/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php index d158b3ba77..3e634f1ff2 100644 --- a/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php +++ b/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php @@ -13,6 +13,7 @@ declare(strict_types=1); namespace Sylius\Bundle\ShopBundle\Controller; +use LogicException; use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface; use Sylius\Bundle\ShopBundle\Provider\PayResponseProviderInterface; use Sylius\Component\Core\Model\OrderInterface; @@ -33,7 +34,6 @@ final class OrderPayController private MetadataInterface $orderMetadata, private RequestConfigurationFactoryInterface $requestConfigurationFactory, private iterable $payResponseProviders, - private PayResponseProviderInterface $defaultPayResponseProvider, ) { } @@ -56,6 +56,6 @@ final class OrderPayController } } - return $this->defaultPayResponseProvider->getResponse($configuration, $order); + throw new LogicException(sprintf('No "pay response provider" available for order (id %s).', $order->getId())); } } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/DefaultPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php similarity index 81% rename from src/Sylius/Bundle/ShopBundle/Provider/DefaultPayResponseProvider.php rename to src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php index 66b8b8f5ab..bd449ad542 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/DefaultPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php @@ -15,11 +15,12 @@ namespace Sylius\Bundle\ShopBundle\Provider; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Payment\Model\PaymentInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; -final class DefaultPayResponseProvider implements PayResponseProviderInterface +final class NoPaymentPayResponseProvider implements PayResponseProviderInterface { public function __construct( private RouterInterface $router, @@ -34,11 +35,13 @@ final class DefaultPayResponseProvider implements PayResponseProviderInterface return new RedirectResponse($url); } - + public function supports( RequestConfiguration $requestConfiguration, OrderInterface $order ): bool { - return true; + $payment = $order->getLastPayment(PaymentInterface::STATE_NEW); + + return null === $payment; } } diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml index fcc16fd90e..d7af5faa31 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml @@ -65,7 +65,6 @@ - diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml index 06053cac32..af442e3572 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml @@ -17,7 +17,7 @@ > - + From 597cd9be5578bf9f32425a68cf4d0ded4f935e08 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 29 Aug 2024 00:06:48 +0300 Subject: [PATCH 133/200] Fix typo and shorten return --- .../ShopBundle/Provider/PayumPayResponseProvider.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php index 6cdee5cbf8..ae726cfef6 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php @@ -13,7 +13,6 @@ declare(strict_types=1); namespace Sylius\Bundle\ShopBundle\Provider; -use Payum\Core\Exception\InvalidArgumentException; use Payum\Core\Payum; use Payum\Core\Security\TokenInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; @@ -37,7 +36,7 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface OrderInterface $order ): Response { $payment = $this->getPaymentFromOrder($order); - Assert::notNull($payment, sprintf('Order (id %s) must have last payment in state "new".', $order->getId()); + Assert::notNull($payment, sprintf('Order (id %s) must have last payment in state "new".', $order->getId())); $redirectOptions = $requestConfiguration->getParameters()->get('redirect'); if (is_string($redirectOptions)) { @@ -110,10 +109,6 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface } $gatewayConfig = $paymentMethod->getGatewayConfig(); - if (null === $gatewayConfig) { - return null; - } - - return $gatewayConfig; + return $gatewayConfig ?? null; } } From dae0ae907226fa067c144d7f2dc775531abe93d1 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 2 Sep 2024 20:10:59 +0300 Subject: [PATCH 134/200] Refactor and enhance thrown message --- .../CommandProvider/ActionsCommandProvider.php | 11 ++++++++--- .../CommandProvider/GatewayFactoryCommandProvider.php | 9 +++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php index 96ff0b3ef2..6413ea6ec4 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php @@ -26,7 +26,8 @@ final class ActionsCommandProvider implements ServiceProviderAwareCommandProvide public function supports(PaymentRequestInterface $paymentRequest): bool { - $commandProvider = $this->locator->get($paymentRequest->getAction()); + $action = $paymentRequest->getAction(); + $commandProvider = $this->getCommandProvider($action); if (null === $commandProvider) { return false; } @@ -36,9 +37,13 @@ final class ActionsCommandProvider implements ServiceProviderAwareCommandProvide public function provide(PaymentRequestInterface $paymentRequest): object { - $commandProvider = $this->locator->get($paymentRequest->getAction()); + $action = $paymentRequest->getAction(); + $commandProvider = $this->locator->get($action); if (null === $commandProvider) { - throw new PaymentRequestNotSupportedException(); + throw new PaymentRequestNotSupportedException(sprintf( + 'No payment request command provider supported for this action "%s".', + $action + )); } return $commandProvider->provide($paymentRequest); diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/GatewayFactoryCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/GatewayFactoryCommandProvider.php index 575a8c2693..1229a8237e 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/GatewayFactoryCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/GatewayFactoryCommandProvider.php @@ -51,7 +51,10 @@ final class GatewayFactoryCommandProvider implements ServiceProviderAwareCommand $factoryName = $this->getFactoryName($paymentRequest); $commandProvider = $this->getCommandProvider($factoryName); if (null === $commandProvider) { - throw new PaymentRequestNotSupportedException(); + throw new PaymentRequestNotSupportedException(sprintf( + 'No payment request command provider supported for for the payment method factory name "%s".', + $factoryName + )); } return $commandProvider->provide($paymentRequest); @@ -72,8 +75,6 @@ final class GatewayFactoryCommandProvider implements ServiceProviderAwareCommand /** @var PaymentMethodInterface $paymentMethod */ $paymentMethod = $paymentRequest->getMethod(); - $factoryName = $this->gatewayFactoryNameProvider->provide($paymentMethod); - - return $factoryName; + return $this->gatewayFactoryNameProvider->provide($paymentMethod); } } From bcc8155a726124d68b0a5604fd0799586be29259 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 2 Sep 2024 20:17:06 +0300 Subject: [PATCH 135/200] Add PaymentRequest HttpResponseProviders --- .../Provider/ActionsHttpResponseProvider.php | 66 ++++++++++++++++ .../GatewayFactoryHttpResponseProvider.php | 79 +++++++++++++++++++ .../HttpResponseProviderInterface.php | 33 ++++++++ .../ServiceProviderAwareProviderInterface.php | 24 ++++++ .../services/payment_request/providers.xml | 5 ++ 5 files changed, 207 insertions(+) create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ServiceProviderAwareProviderInterface.php diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php new file mode 100644 index 0000000000..667c820b0f --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php @@ -0,0 +1,66 @@ +getAction(); + $httpResponseProvider = $this->getHttpResponseProvider($action); + if (null === $httpResponseProvider) { + throw new PaymentRequestNotSupportedException(sprintf( + 'No payment request HTTP Response provider supported for this action "%s".', + $action + )); + } + + return $httpResponseProvider->getResponse($requestConfiguration, $paymentRequest); + } + + public function supports( + RequestConfiguration $requestConfiguration, + PaymentRequestInterface $paymentRequest, + ): bool { + $action = $paymentRequest->getAction(); + $httpResponseProvider = $this->getHttpResponseProvider($action); + if (null === $httpResponseProvider) { + return false; + } + + return $httpResponseProvider->supports($requestConfiguration, $paymentRequest); + } + + public function getProviderIndex(): array { + return $this->locator->getProvidedServices(); + } + + public function getHttpResponseProvider(string $index): ?HttpResponseProviderInterface + { + return $this->locator->get($index); + } +} diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php new file mode 100644 index 0000000000..e1ff5582bb --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php @@ -0,0 +1,79 @@ +getFactoryName($paymentRequest); + + $httpResponseProvider = $this->getHttpResponseProvider($factoryName); + + if (null === $httpResponseProvider) { + throw new PaymentRequestNotSupportedException(sprintf( + 'No payment request HTTP Response provider supported for the payment method factory name "%s".', + $factoryName + )); + } + + return $httpResponseProvider->getResponse($requestConfiguration, $paymentRequest); + } + + public function supports( + RequestConfiguration $requestConfiguration, + PaymentRequestInterface $paymentRequest, + ): bool { + $factoryName = $this->getFactoryName($paymentRequest); + $httpResponseProvider = $this->getHttpResponseProvider($factoryName); + + if (null === $httpResponseProvider) { + return false; + } + + return $httpResponseProvider->supports($requestConfiguration, $paymentRequest); + } + + public function getHttpResponseProvider(string $index): ?HttpResponseProviderInterface + { + return $this->locator->get($index); + } + + public function getProviderIndex(): array { + return $this->locator->getProvidedServices(); + } + + private function getFactoryName(PaymentRequestInterface $paymentRequest): string + { + /** @var PaymentMethodInterface $paymentMethod */ + $paymentMethod = $paymentRequest->getMethod(); + + return $this->gatewayFactoryNameProvider->provide($paymentMethod); + } +} diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php new file mode 100644 index 0000000000..8d83556654 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php @@ -0,0 +1,33 @@ + + + + + + From 416021d1bb6031764bc1dad411a3b307fa7ea15f Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 2 Sep 2024 20:17:42 +0300 Subject: [PATCH 136/200] Add PaymentToPayResolver to get the last payment via a service --- .../Resolver/PaymentToPayResolver.php | 29 +++++++++++++++++++ .../PaymentToPayResolverInterface.php | 24 +++++++++++++++ .../Resources/config/services/resolvers.xml | 25 ++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolver.php create mode 100644 src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolverInterface.php create mode 100644 src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml diff --git a/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolver.php b/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolver.php new file mode 100644 index 0000000000..2e928ef973 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolver.php @@ -0,0 +1,29 @@ +getLastPayment($this->state); + } +} diff --git a/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolverInterface.php b/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolverInterface.php new file mode 100644 index 0000000000..f9b69289e0 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolverInterface.php @@ -0,0 +1,24 @@ + + + + + + + + + Sylius\Component\Payment\Model\PaymentInterface::STATE_NEW + + + + From 72529811772219d8dc052292a3b841029da0a881 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 3 Sep 2024 10:20:54 +0300 Subject: [PATCH 137/200] Add payment request http response provider --- .../Provider/NoPaymentPayResponseProvider.php | 6 +-- .../PaymentRequestPayResponseProvider.php | 40 ++++++++++++++++++- .../Provider/PayumPayResponseProvider.php | 12 ++---- .../ShopBundle/Resources/config/services.xml | 1 + .../Resources/config/services/providers.xml | 17 +++++--- 5 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php index bd449ad542..228642132e 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace Sylius\Bundle\ShopBundle\Provider; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; +use Sylius\Bundle\ShopBundle\Resolver\PaymentToPayResolverInterface; use Sylius\Component\Core\Model\OrderInterface; -use Sylius\Component\Payment\Model\PaymentInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; @@ -23,6 +23,7 @@ use Symfony\Component\Routing\RouterInterface; final class NoPaymentPayResponseProvider implements PayResponseProviderInterface { public function __construct( + private PaymentToPayResolverInterface $paymentToPayResolver, private RouterInterface $router, ) { } @@ -40,8 +41,7 @@ final class NoPaymentPayResponseProvider implements PayResponseProviderInterface RequestConfiguration $requestConfiguration, OrderInterface $order ): bool { - $payment = $order->getLastPayment(PaymentInterface::STATE_NEW); - + $payment = $this->paymentToPayResolver->getLastPayment($order); return null === $payment; } } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php index 2cb94e7060..4188e4848b 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php @@ -13,19 +13,55 @@ declare(strict_types=1); namespace Sylius\Bundle\ShopBundle\Provider; +use Sylius\Bundle\CoreBundle\PaymentRequest\Announcer\PaymentRequestAnnouncerInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\ServiceProviderAwareProviderInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; +use Sylius\Bundle\ShopBundle\Resolver\PaymentToPayResolverInterface; use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\RouterInterface; +use Webmozart\Assert\Assert; + +use function sprintf; final class PaymentRequestPayResponseProvider implements PayResponseProviderInterface { + public function __construct( + private PaymentToPayResolverInterface $paymentToPayResolver, + private PaymentRequestFactoryInterface $paymentRequestFactory, + private PaymentRequestAnnouncerInterface $paymentRequestAnnouncer, + private ServiceProviderAwareProviderInterface $httpResponseProvider, + private RouterInterface $router, + ) { + } + public function getResponse( RequestConfiguration $requestConfiguration, OrderInterface $order ): Response { - return new Response('', Response::HTTP_NO_CONTENT); + $payment = $this->paymentToPayResolver->getLastPayment($order); + Assert::notNull($payment, sprintf('Order (id %s) must have last payment in state "new".', $order->getId())); + + $paymentMethod = $payment->getMethod(); + Assert::notNull($paymentMethod, sprintf('Payment (id %s) must have payment method.', $payment->getId())); + + $paymentRequest = $this->paymentRequestFactory->create($payment, $paymentMethod); + + $this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($paymentRequest); + + if ($this->httpResponseProvider->supports($requestConfiguration, $paymentRequest)) { + return $this->httpResponseProvider->getResponse($requestConfiguration, $paymentRequest); + } + + $url = $this->router->generate('sylius_shop_order_after_pay', [ + 'tokenValue' => $order->getTokenValue(), + ]); + + return new RedirectResponse($url); } - + public function supports( RequestConfiguration $requestConfiguration, OrderInterface $order diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php index ae726cfef6..0c674f657a 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php @@ -16,10 +16,10 @@ namespace Sylius\Bundle\ShopBundle\Provider; use Payum\Core\Payum; use Payum\Core\Security\TokenInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; +use Sylius\Bundle\ShopBundle\Resolver\PaymentToPayResolverInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Payment\Model\GatewayConfigInterface; -use Sylius\Component\Payment\Model\PaymentInterface as BasePaymentInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Webmozart\Assert\Assert; @@ -28,6 +28,7 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface { public function __construct( private Payum $payum, + private PaymentToPayResolverInterface $paymentToPayResolver, ) { } @@ -35,7 +36,7 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface RequestConfiguration $requestConfiguration, OrderInterface $order ): Response { - $payment = $this->getPaymentFromOrder($order); + $payment = $this->paymentToPayResolver->getLastPayment($order); Assert::notNull($payment, sprintf('Order (id %s) must have last payment in state "new".', $order->getId())); $redirectOptions = $requestConfiguration->getParameters()->get('redirect'); @@ -53,7 +54,7 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface OrderInterface $order ): bool { - $payment = $this->getPaymentFromOrder($order); + $payment = $this->paymentToPayResolver->getLastPayment($order); if (null === $payment) { return false; } @@ -96,11 +97,6 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface ); } - private function getPaymentFromOrder(OrderInterface $order): ?PaymentInterface - { - return $order->getLastPayment(BasePaymentInterface::STATE_NEW); - } - private function getGatewayConfigFromPayment(PaymentInterface $payment): ?GatewayConfigInterface { $paymentMethod = $payment->getMethod(); diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services.xml index 4f29076dd3..6b42ea205f 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services.xml @@ -18,6 +18,7 @@ + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml index af442e3572..024d4640d4 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml @@ -17,17 +17,24 @@ > - - + + + - - + + + + + + - + + + From 7d081266d1ad3cc531c054c33a12b0f5ec67769d Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 3 Sep 2024 10:21:58 +0300 Subject: [PATCH 138/200] Add order tokenValue to the after pay route --- src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml index 0bb19bef57..bbdfdd4c45 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml @@ -19,7 +19,7 @@ sylius_shop_order_pay: route: sylius_shop_order_after_pay sylius_shop_order_after_pay: - path: /after-pay + path: /{tokenValue?}/after-pay methods: [GET, POST] defaults: _controller: sylius.controller.payum::afterCaptureAction From 3cd5265ff0de75198fc79b2730a4513ea567bfa4 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 12:53:33 +0300 Subject: [PATCH 139/200] Specify type --- .../PaymentRequest/Provider/ActionsHttpResponseProvider.php | 3 +++ .../Provider/GatewayFactoryHttpResponseProvider.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php index 667c820b0f..26e9d0b677 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php @@ -21,6 +21,9 @@ use Symfony\Contracts\Service\ServiceProviderInterface; final class ActionsHttpResponseProvider implements ServiceProviderAwareProviderInterface { + /** + * @param ServiceProviderInterface $locator + */ public function __construct( private ServiceProviderInterface $locator, ) { diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php index e1ff5582bb..73d977fae0 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php @@ -22,6 +22,9 @@ use Symfony\Contracts\Service\ServiceProviderInterface; final class GatewayFactoryHttpResponseProvider implements ServiceProviderAwareProviderInterface { + /** + * @param ServiceProviderInterface $locator + */ public function __construct( private GatewayFactoryNameProviderInterface $gatewayFactoryNameProvider, private ServiceProviderInterface $locator, From f790c3adb65eb7663794ba07bed3c38348799169 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 12:55:20 +0300 Subject: [PATCH 140/200] Move payum controller body to a dedicated service --- .../Resources/config/services/controller.xml | 16 --------- .../Handler/PaymentStatusFlashHandler.php | 31 ++++++++++++++++ .../PaymentStatusFlashHandlerInterface.php | 23 ++++++++++++ .../AfterPayResponseProviderInterface.php | 25 +++++++++++++ .../PayumAfterPayResponseProvider.php} | 36 +++++++++++-------- 5 files changed, 101 insertions(+), 30 deletions(-) delete mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/services/controller.xml create mode 100644 src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandler.php create mode 100644 src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandlerInterface.php create mode 100644 src/Sylius/Bundle/ShopBundle/Provider/AfterPayResponseProviderInterface.php rename src/Sylius/Bundle/{PayumBundle/Controller/PayumController.php => ShopBundle/Provider/PayumAfterPayResponseProvider.php} (59%) diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/services/controller.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/services/controller.xml deleted file mode 100644 index 9ead44adac..0000000000 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/services/controller.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandler.php b/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandler.php new file mode 100644 index 0000000000..7d9b72f4ff --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandler.php @@ -0,0 +1,31 @@ +getRequest(); + if (PaymentInterface::STATE_NEW !== $status) { + /** @var FlashBagInterface $flashBag */ + $flashBag = $request->getSession()->getBag('flashes'); + $flashBag->add('info', sprintf('sylius.payment.%s', $status)); + } + } +} diff --git a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandlerInterface.php b/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandlerInterface.php new file mode 100644 index 0000000000..a43e3ed427 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandlerInterface.php @@ -0,0 +1,23 @@ +getHttpRequestVerifier()->verify($request); + $token = $this->getHttpRequestVerifier()->verify($requestConfiguration->getRequest()); - /** @var Generic&GetStatusInterface $status */ + /** @var GetStatusInterface&Generic $status */ $status = $this->getStatusRequestFactory->createNewWithModel($token); $this->payum->getGateway($token->getGatewayName())->execute($status); $resolveNextRoute = $this->resolveNextRouteRequestFactory->createNewWithModel($status->getFirstModel()); $this->payum->getGateway($token->getGatewayName())->execute($resolveNextRoute); + $this->paymentStatusFlashHandler->handle($requestConfiguration, (string) $status->getValue()); + + $url = $this->router->generate( + $resolveNextRoute->getRouteName(), + $resolveNextRoute->getRouteParameters() + ); + $this->getHttpRequestVerifier()->invalidate($token); - if (PaymentInterface::STATE_NEW !== $status->getValue()) { - /** @var FlashBagInterface $flashBag */ - $flashBag = $request->getSession()->getBag('flashes'); - $flashBag->add('info', sprintf('sylius.payment.%s', $status->getValue())); - } + return new RedirectResponse($url); + } + public function supports(RequestConfiguration $requestConfiguration): bool + { + $request = $requestConfiguration->getRequest(); + $hash = $request->attributes->get('payum_token', $request->get('payum_token', false)); - return new RedirectResponse($this->router->generate($resolveNextRoute->getRouteName(), $resolveNextRoute->getRouteParameters())); + return false !== $hash; } private function getHttpRequestVerifier(): HttpRequestVerifierInterface From e01567955ac019c2761a9bccde98b30f1053499d Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 12:56:12 +0300 Subject: [PATCH 141/200] Create new controller action to replace the payum after capture one --- .../Controller/OrderPayController.php | 23 ++++++++++++++++++- .../Resources/config/routing/order.yml | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php b/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php index 3e634f1ff2..b960c32297 100644 --- a/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php +++ b/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php @@ -14,26 +14,34 @@ declare(strict_types=1); namespace Sylius\Bundle\ShopBundle\Controller; use LogicException; +use Payum\Core\Request\Generic; +use Payum\Core\Request\GetStatusInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface; +use Sylius\Bundle\ShopBundle\Provider\AfterPayResponseProviderInterface; use Sylius\Bundle\ShopBundle\Provider\PayResponseProviderInterface; use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Order\Repository\OrderRepositoryInterface; use Sylius\Component\Resource\Metadata\MetadataInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; final class OrderPayController { /** - * @param iterable $payResponseProviders * @param OrderRepositoryInterface $orderRepository + * @param iterable $payResponseProviders + * @param iterable $afterPayResponseProviders */ public function __construct( private OrderRepositoryInterface $orderRepository, private MetadataInterface $orderMetadata, private RequestConfigurationFactoryInterface $requestConfigurationFactory, private iterable $payResponseProviders, + private iterable $afterPayResponseProviders, ) { } @@ -58,4 +66,17 @@ final class OrderPayController throw new LogicException(sprintf('No "pay response provider" available for order (id %s).', $order->getId())); } + + public function afterPayAction(Request $request): Response + { + $configuration = $this->requestConfigurationFactory->create($this->orderMetadata, $request); + + foreach ($this->afterPayResponseProviders as $provider) { + if ($provider->supports($configuration)) { + return $provider->getResponse($configuration); + } + } + + throw new LogicException(sprintf('No "after pay response provider" available.')); + } } diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml index bbdfdd4c45..b6b2b466b7 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml @@ -19,10 +19,10 @@ sylius_shop_order_pay: route: sylius_shop_order_after_pay sylius_shop_order_after_pay: - path: /{tokenValue?}/after-pay + path: /{hash?}/after-pay methods: [GET, POST] defaults: - _controller: sylius.controller.payum::afterCaptureAction + _controller: sylius.controller.shop.order_pay::afterPayAction sylius_shop_order_show: path: /{tokenValue} From e7e162b7564544e1d8306e887a99b27bce9b0e41 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 12:57:11 +0300 Subject: [PATCH 142/200] Change tokenValue to payment request hash --- .../Provider/PaymentRequestPayResponseProvider.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php index 4188e4848b..da02c7ad30 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php @@ -19,6 +19,7 @@ use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Bundle\ShopBundle\Resolver\PaymentToPayResolverInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; +use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; @@ -28,6 +29,9 @@ use function sprintf; final class PaymentRequestPayResponseProvider implements PayResponseProviderInterface { + /** + * @param PaymentRequestFactoryInterface $paymentRequestFactory + */ public function __construct( private PaymentToPayResolverInterface $paymentToPayResolver, private PaymentRequestFactoryInterface $paymentRequestFactory, @@ -56,7 +60,7 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte } $url = $this->router->generate('sylius_shop_order_after_pay', [ - 'tokenValue' => $order->getTokenValue(), + 'hash' => $paymentRequest->getId(), ]); return new RedirectResponse($url); From 1b4679ef8b0b610c54fd9865b553e624dfe384d4 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 13:02:39 +0300 Subject: [PATCH 143/200] Introduce PaymentRequest after pay --- ...ndler.php => PaymentStateFlashHandler.php} | 8 +- ... => PaymentStateFlashHandlerInterface.php} | 4 +- ...PaymentRequestAfterPayResponseProvider.php | 81 +++++++++++++++++++ .../PayumAfterPayResponseProvider.php | 4 +- .../Resolver/AfterPayNextResponseResolver.php | 54 +++++++++++++ .../AfterPayNextResponseResolverInterface.php | 28 +++++++ .../ShopBundle/Resources/config/services.xml | 1 + .../Resources/config/services/controller.xml | 1 + .../Resources/config/services/handlers.xml | 23 ++++++ .../Resources/config/services/providers.xml | 19 +++++ .../Resources/config/services/resolvers.xml | 4 + 11 files changed, 219 insertions(+), 8 deletions(-) rename src/Sylius/Bundle/ShopBundle/Handler/{PaymentStatusFlashHandler.php => PaymentStateFlashHandler.php} (81%) rename src/Sylius/Bundle/ShopBundle/Handler/{PaymentStatusFlashHandlerInterface.php => PaymentStateFlashHandlerInterface.php} (87%) create mode 100644 src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php create mode 100644 src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolver.php create mode 100644 src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolverInterface.php create mode 100644 src/Sylius/Bundle/ShopBundle/Resources/config/services/handlers.xml diff --git a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandler.php b/src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandler.php similarity index 81% rename from src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandler.php rename to src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandler.php index 7d9b72f4ff..e695956533 100644 --- a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandler.php +++ b/src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandler.php @@ -17,15 +17,15 @@ use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Payment\Model\PaymentInterface; use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; -final class PaymentStatusFlashHandler implements PaymentStatusFlashHandlerInterface +final class PaymentStateFlashHandler implements PaymentStateFlashHandlerInterface { - public function handle(RequestConfiguration $requestConfiguration, string $status): void + public function handle(RequestConfiguration $requestConfiguration, string $state): void { $request = $requestConfiguration->getRequest(); - if (PaymentInterface::STATE_NEW !== $status) { + if (PaymentInterface::STATE_NEW !== $state) { /** @var FlashBagInterface $flashBag */ $flashBag = $request->getSession()->getBag('flashes'); - $flashBag->add('info', sprintf('sylius.payment.%s', $status)); + $flashBag->add('info', sprintf('sylius.payment.%s', $state)); } } } diff --git a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandlerInterface.php b/src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandlerInterface.php similarity index 87% rename from src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandlerInterface.php rename to src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandlerInterface.php index a43e3ed427..c835a492a2 100644 --- a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStatusFlashHandlerInterface.php +++ b/src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandlerInterface.php @@ -17,7 +17,7 @@ use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Core\Model\OrderInterface; use Symfony\Component\HttpFoundation\Response; -interface PaymentStatusFlashHandlerInterface +interface PaymentStateFlashHandlerInterface { - public function handle(RequestConfiguration $requestConfiguration, string $status): void; + public function handle(RequestConfiguration $requestConfiguration, string $state): void; } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php new file mode 100644 index 0000000000..028877a217 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php @@ -0,0 +1,81 @@ + $paymentRequestFactory + * @param PaymentRequestRepositoryInterface $paymentRequestRepository + */ + public function __construct( + private PaymentRequestFactoryInterface $paymentRequestFactory, + private PaymentRequestAnnouncerInterface $paymentRequestAnnouncer, + private ServiceProviderAwareProviderInterface $httpResponseProvider, + private PaymentRequestRepositoryInterface $paymentRequestRepository, + private PaymentStateFlashHandlerInterface $paymentStateFlashHandler, + private AfterPayNextResponseResolverInterface $afterPayNextResponseResolver, + ) { + } + + public function getResponse(RequestConfiguration $requestConfiguration): Response + { + $hash = $this->getPaymentRequestHash($requestConfiguration); + Assert::notNull($hash, 'A request attribute "hash" is required to retrieve the related order.'); + + $paymentRequest = $this->paymentRequestRepository->find($hash); + if (null === $paymentRequest) { + throw new NotFoundHttpException(sprintf('The Payment Request with hash "%s" does not exist.', $hash)); + } + + $statusPaymentRequest = $this->paymentRequestFactory->createFromPaymentRequest($paymentRequest); + $statusPaymentRequest->setAction(PaymentRequestInterface::ACTION_STATUS); + + $this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($statusPaymentRequest); + + if ($this->httpResponseProvider->supports($requestConfiguration, $statusPaymentRequest)) { + return $this->httpResponseProvider->getResponse($requestConfiguration, $statusPaymentRequest); + } + + $this->paymentStateFlashHandler->handle($requestConfiguration, $paymentRequest->getPayment()->getState()); + + return $this->afterPayNextResponseResolver->getResponse($requestConfiguration, $statusPaymentRequest); + } + + public function supports(RequestConfiguration $requestConfiguration): bool + { + $hash = $this->getPaymentRequestHash($requestConfiguration); + + return null !== $hash; + } + + private function getPaymentRequestHash(RequestConfiguration $requestConfiguration): mixed + { + return $requestConfiguration->getRequest()->attributes->get('hash'); + } +} diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayumAfterPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PayumAfterPayResponseProvider.php index 023fcc40cd..23adbb8af2 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayumAfterPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PayumAfterPayResponseProvider.php @@ -20,7 +20,7 @@ use Payum\Core\Security\HttpRequestVerifierInterface; use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; use Sylius\Bundle\PayumBundle\Factory\ResolveNextRouteFactoryInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; -use Sylius\Bundle\ShopBundle\Handler\PaymentStatusFlashHandlerInterface; +use Sylius\Bundle\ShopBundle\Handler\PaymentStateFlashHandlerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; @@ -32,7 +32,7 @@ final class PayumAfterPayResponseProvider implements AfterPayResponseProviderInt private RouterInterface $router, private GetStatusFactoryInterface $getStatusRequestFactory, private ResolveNextRouteFactoryInterface $resolveNextRouteRequestFactory, - private PaymentStatusFlashHandlerInterface $paymentStatusFlashHandler, + private PaymentStateFlashHandlerInterface $paymentStatusFlashHandler, ) { } diff --git a/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolver.php b/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolver.php new file mode 100644 index 0000000000..b47adbd761 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolver.php @@ -0,0 +1,54 @@ +getPayment(); + $order = $payment->getOrder(); + Assert::notNull($order, 'An order is required at this point.'); + + $route = 'sylius_shop_order_show'; + $params = ['tokenValue' => $order->getTokenValue()]; + + if ( + $payment->getState() === BasePaymentInterface::STATE_COMPLETED || + $payment->getState() === BasePaymentInterface::STATE_AUTHORIZED + ) { + $route = 'sylius_shop_order_thank_you'; + } + + $url = $this->router->generate($route, $params); + + return new RedirectResponse($url); + } +} diff --git a/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolverInterface.php b/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolverInterface.php new file mode 100644 index 0000000000..bd0165dec7 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolverInterface.php @@ -0,0 +1,28 @@ + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml index d7af5faa31..ab0b900838 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml @@ -65,6 +65,7 @@ + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/handlers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/handlers.xml new file mode 100644 index 0000000000..c3121f2950 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/handlers.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml index 024d4640d4..1e4d811af9 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml @@ -38,5 +38,24 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml index 17ebc847c4..5a042852f5 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml @@ -21,5 +21,9 @@ Sylius\Component\Payment\Model\PaymentInterface::STATE_NEW + + + + From cd44afc591030f395b1ca879ee7fe8207c875ad2 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 14:00:33 +0300 Subject: [PATCH 144/200] Rename service --- .../Bundle/ShopBundle/Resources/config/services/providers.xml | 2 +- .../Bundle/ShopBundle/Resources/config/services/resolvers.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml index 1e4d811af9..a8ad905d96 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml @@ -53,7 +53,7 @@ - + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml index 5a042852f5..d5906d5b71 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml @@ -21,7 +21,7 @@ Sylius\Component\Payment\Model\PaymentInterface::STATE_NEW - + From adf81c538e91df562f2be90cb49881da0fef937a Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 17:07:59 +0200 Subject: [PATCH 145/200] Missing refactoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Góralski --- .../PaymentRequest/CommandProvider/ActionsCommandProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php index 6413ea6ec4..6b157f4d15 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php @@ -38,7 +38,7 @@ final class ActionsCommandProvider implements ServiceProviderAwareCommandProvide public function provide(PaymentRequestInterface $paymentRequest): object { $action = $paymentRequest->getAction(); - $commandProvider = $this->locator->get($action); + $commandProvider = $this->getCommandProvider($action); if (null === $commandProvider) { throw new PaymentRequestNotSupportedException(sprintf( 'No payment request command provider supported for this action "%s".', From a10d6abc68b3ceaa18f2780e2cbd9081f190af95 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 18:16:15 +0300 Subject: [PATCH 146/200] Replace file header --- .../Provider/HttpResponseProviderInterface.php | 12 +++++------- .../ServiceProviderAwareProviderInterface.php | 12 +++++------- .../AfterPayNextResponseResolverInterface.php | 12 +++++------- .../Resolver/PaymentToPayResolverInterface.php | 12 +++++------- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php index 8d83556654..bf9049cc6f 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php @@ -1,14 +1,12 @@ Date: Wed, 4 Sep 2024 17:17:18 +0200 Subject: [PATCH 147/200] Remove function import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Góralski --- .../Provider/PaymentRequestAfterPayResponseProvider.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php index 028877a217..10fb555c2f 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php @@ -25,8 +25,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Webmozart\Assert\Assert; -use function sprintf; - final class PaymentRequestAfterPayResponseProvider implements AfterPayResponseProviderInterface { /** From a312315c852ad51965361b67da147e9375d9b7c0 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 18:24:37 +0300 Subject: [PATCH 148/200] Remove global function use --- .../ShopBundle/Provider/PaymentRequestPayResponseProvider.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php index da02c7ad30..e00dd62567 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php @@ -25,8 +25,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; use Webmozart\Assert\Assert; -use function sprintf; - final class PaymentRequestPayResponseProvider implements PayResponseProviderInterface { /** From 6e8673b08b83b8a4830ec02364d8c0598bc6c0f9 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 17:28:00 +0200 Subject: [PATCH 149/200] Refactor via quick syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Góralski --- .../ShopBundle/Provider/PayumPayResponseProvider.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php index 0c674f657a..8316b6dbe5 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php @@ -99,12 +99,6 @@ final class PayumPayResponseProvider implements PayResponseProviderInterface private function getGatewayConfigFromPayment(PaymentInterface $payment): ?GatewayConfigInterface { - $paymentMethod = $payment->getMethod(); - if (null === $paymentMethod) { - return null; - } - - $gatewayConfig = $paymentMethod->getGatewayConfig(); - return $gatewayConfig ?? null; + return $payment->getMethod()?->getGatewayConfig(); } } From f07ed55ce9ad157bceb964187b4a2f1fe54be736 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 17:42:39 +0200 Subject: [PATCH 150/200] Line return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Góralski --- .../PaymentRequest/Provider/ActionsHttpResponseProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php index 26e9d0b677..0ca75399f0 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php @@ -58,7 +58,8 @@ final class ActionsHttpResponseProvider implements ServiceProviderAwareProviderI return $httpResponseProvider->supports($requestConfiguration, $paymentRequest); } - public function getProviderIndex(): array { + public function getProviderIndex(): array + { return $this->locator->getProvidedServices(); } From 6eb63158b4628341e4346bd5f608323c624d479b Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 19:58:31 +0300 Subject: [PATCH 151/200] Avoid publicly displaying available actions --- .../ApiBundle/Resources/translations/validators.en.yaml | 2 +- .../Constraints/ChosenPaymentRequestActionEligibility.php | 2 -- .../ChosenPaymentRequestActionEligibilityValidator.php | 4 +--- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/Resources/translations/validators.en.yaml b/src/Sylius/Bundle/ApiBundle/Resources/translations/validators.en.yaml index 66b4cc5870..5ae40d7bac 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/translations/validators.en.yaml +++ b/src/Sylius/Bundle/ApiBundle/Resources/translations/validators.en.yaml @@ -28,7 +28,7 @@ sylius: not_exist: 'The payment method with %code% code does not exist.' payment_request: action_not_available: 'The payment request (method code "%code%" and payment id "%id%") has no handler. Please choose another payment method.' - not_available: 'The payment request is not supporting this action (actions available are: %actions%).' + not_available: 'The payment request is not supporting this action.' product: not_exist: 'The product %productName% does not exist.' product_variant: diff --git a/src/Sylius/Bundle/ApiBundle/Validator/Constraints/ChosenPaymentRequestActionEligibility.php b/src/Sylius/Bundle/ApiBundle/Validator/Constraints/ChosenPaymentRequestActionEligibility.php index 262340bab3..35822af532 100644 --- a/src/Sylius/Bundle/ApiBundle/Validator/Constraints/ChosenPaymentRequestActionEligibility.php +++ b/src/Sylius/Bundle/ApiBundle/Validator/Constraints/ChosenPaymentRequestActionEligibility.php @@ -19,8 +19,6 @@ final class ChosenPaymentRequestActionEligibility extends Constraint { public string $notAvailable = 'sylius.payment_request.action_not_available'; - public string $notExist = 'sylius.payment_method.not_exist'; - public function validatedBy(): string { return 'sylius_api_chosen_payment_request_action_eligibility'; diff --git a/src/Sylius/Bundle/ApiBundle/Validator/Constraints/ChosenPaymentRequestActionEligibilityValidator.php b/src/Sylius/Bundle/ApiBundle/Validator/Constraints/ChosenPaymentRequestActionEligibilityValidator.php index f22e496b73..fe988756fc 100644 --- a/src/Sylius/Bundle/ApiBundle/Validator/Constraints/ChosenPaymentRequestActionEligibilityValidator.php +++ b/src/Sylius/Bundle/ApiBundle/Validator/Constraints/ChosenPaymentRequestActionEligibilityValidator.php @@ -57,9 +57,7 @@ final class ChosenPaymentRequestActionEligibilityValidator extends ConstraintVal return; } - $availableActions = $gatewayFactoryCommandProvider->getCommandProviderIndex(); - - $this->context->addViolation($constraint->notAvailable, ['%actions%' => implode(', ', $availableActions)]); + $this->context->addViolation($constraint->notAvailable); } private function getCommandProvider(AddPaymentRequest $addPaymentRequest): ?PaymentRequestCommandProviderInterface From 2dba6210db4017976595485165f4c847c330dc70 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 19:59:15 +0300 Subject: [PATCH 152/200] Refactor to abstract class to avoid duplicating code --- .../AbstractServiceCommandProvider.php | 62 +++++++++++++++++ .../ActionsCommandProvider.php | 43 ++---------- .../GatewayFactoryCommandProvider.php | 47 +++---------- ...eProviderAwareCommandProviderInterface.php | 2 +- .../Provider/AbstractServiceProvider.php | 68 +++++++++++++++++++ .../Provider/ActionsHttpResponseProvider.php | 46 ++----------- .../GatewayFactoryHttpResponseProvider.php | 57 ++-------------- .../Provider/GatewayFactoryNameProvider.php | 10 +++ .../GatewayFactoryNameProviderInterface.php | 3 + .../HttpResponseProviderInterface.php | 10 +-- .../ServiceProviderAwareProviderInterface.php | 2 +- 11 files changed, 173 insertions(+), 177 deletions(-) create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php new file mode 100644 index 0000000000..ffe896cd0a --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php @@ -0,0 +1,62 @@ + */ + protected ServiceProviderInterface $locator; + + public function supports(PaymentRequestInterface $paymentRequest): bool + { + $index = $this->getCommandProviderIndex($paymentRequest); + $httpResponseProvider = $this->getCommandProvider($index); + if (null === $httpResponseProvider) { + return false; + } + + return $httpResponseProvider->supports($paymentRequest); + } + + public function provide(PaymentRequestInterface $paymentRequest): object + { + $index = $this->getCommandProviderIndex($paymentRequest); + $commandProvider = $this->getCommandProvider($index); + if (null === $commandProvider) { + throw new PaymentRequestNotSupportedException(sprintf( + 'No payment request command provider supported for "%s" (command providers available are: %s).', + $index, + implode(', ', $this->getCommandProviderIndexes()), + )); + } + + return $commandProvider->provide($paymentRequest); + } + + public function getCommandProvider(string $index): ?PaymentRequestCommandProviderInterface + { + return $this->locator->get($index); + } + + public function getCommandProviderIndexes(): array + { + return $this->locator->getProvidedServices(); + } + + abstract protected function getCommandProviderIndex(PaymentRequestInterface $paymentRequest): string; +} diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php index 6b157f4d15..8c38fe21d4 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ActionsCommandProvider.php @@ -13,49 +13,20 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider; -use Sylius\Bundle\PaymentBundle\Exception\PaymentRequestNotSupportedException; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Contracts\Service\ServiceProviderInterface; -final class ActionsCommandProvider implements ServiceProviderAwareCommandProviderInterface +final class ActionsCommandProvider extends AbstractServiceCommandProvider { + /** + * @param ServiceProviderInterface $locator + */ public function __construct( - private ServiceProviderInterface $locator, + protected ServiceProviderInterface $locator, ) { } - public function supports(PaymentRequestInterface $paymentRequest): bool - { - $action = $paymentRequest->getAction(); - $commandProvider = $this->getCommandProvider($action); - if (null === $commandProvider) { - return false; - } - - return $commandProvider->supports($paymentRequest); - } - - public function provide(PaymentRequestInterface $paymentRequest): object - { - $action = $paymentRequest->getAction(); - $commandProvider = $this->getCommandProvider($action); - if (null === $commandProvider) { - throw new PaymentRequestNotSupportedException(sprintf( - 'No payment request command provider supported for this action "%s".', - $action - )); - } - - return $commandProvider->provide($paymentRequest); - } - - public function getCommandProvider(string $index): ?PaymentRequestCommandProviderInterface - { - return $this->locator->get($index); - } - - public function getCommandProviderIndex(): array - { - return $this->locator->getProvidedServices(); + protected function getCommandProviderIndex(PaymentRequestInterface $paymentRequest): string { + return $paymentRequest->getAction(); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/GatewayFactoryCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/GatewayFactoryCommandProvider.php index 1229a8237e..e216c80110 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/GatewayFactoryCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/GatewayFactoryCommandProvider.php @@ -20,12 +20,15 @@ use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Contracts\Service\ServiceProviderInterface; -final class GatewayFactoryCommandProvider implements ServiceProviderAwareCommandProviderInterface +final class GatewayFactoryCommandProvider extends AbstractServiceCommandProvider { + /** + * @param ServiceProviderInterface $locator + */ public function __construct( private PaymentRequestDuplicationCheckerInterface $paymentRequestDuplicationChecker, private GatewayFactoryNameProviderInterface $gatewayFactoryNameProvider, - private ServiceProviderInterface $locator, + protected ServiceProviderInterface $locator, ) { } @@ -37,44 +40,10 @@ final class GatewayFactoryCommandProvider implements ServiceProviderAwareCommand return false; } - $factoryName = $this->getFactoryName($paymentRequest); - $commandProvider = $this->getCommandProvider($factoryName); - if (null === $commandProvider) { - return false; - } - - return $commandProvider->supports($paymentRequest); + return parent::supports($paymentRequest); } - public function provide(PaymentRequestInterface $paymentRequest): object - { - $factoryName = $this->getFactoryName($paymentRequest); - $commandProvider = $this->getCommandProvider($factoryName); - if (null === $commandProvider) { - throw new PaymentRequestNotSupportedException(sprintf( - 'No payment request command provider supported for for the payment method factory name "%s".', - $factoryName - )); - } - - return $commandProvider->provide($paymentRequest); - } - - public function getCommandProvider(string $index): ?PaymentRequestCommandProviderInterface - { - return $this->locator->get($index); - } - - public function getCommandProviderIndex(): array - { - return $this->locator->getProvidedServices(); - } - - private function getFactoryName(PaymentRequestInterface $paymentRequest): string - { - /** @var PaymentMethodInterface $paymentMethod */ - $paymentMethod = $paymentRequest->getMethod(); - - return $this->gatewayFactoryNameProvider->provide($paymentMethod); + protected function getCommandProviderIndex(PaymentRequestInterface $paymentRequest): string { + return $this->gatewayFactoryNameProvider->provideFromPaymentRequest($paymentRequest); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ServiceProviderAwareCommandProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ServiceProviderAwareCommandProviderInterface.php index 3c0412c52e..b71d2dc5af 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ServiceProviderAwareCommandProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/ServiceProviderAwareCommandProviderInterface.php @@ -18,5 +18,5 @@ interface ServiceProviderAwareCommandProviderInterface extends PaymentRequestCom public function getCommandProvider(string $index): ?PaymentRequestCommandProviderInterface; /** @return string[] */ - public function getCommandProviderIndex(): array; + public function getCommandProviderIndexes(): array; } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php new file mode 100644 index 0000000000..fbb215042c --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php @@ -0,0 +1,68 @@ + */ + protected ServiceProviderInterface $locator; + + public function supports( + RequestConfiguration $requestConfiguration, + PaymentRequestInterface $paymentRequest, + ): bool { + $index = $this->getHttpResponseProviderIndex($paymentRequest); + $httpResponseProvider = $this->getHttpResponseProvider($index); + if (null === $httpResponseProvider) { + return false; + } + + return $httpResponseProvider->supports($requestConfiguration, $paymentRequest); + } + + public function getResponse( + RequestConfiguration $requestConfiguration, + PaymentRequestInterface $paymentRequest, + ): Response { + $index = $this->getHttpResponseProviderIndex($paymentRequest); + $httpResponseProvider = $this->getHttpResponseProvider($index); + if (null === $httpResponseProvider) { + throw new PaymentRequestNotSupportedException(sprintf( + 'No PaymentRequest HTTP Response provider supported for "%s" (providers available are: %s).', + $index, + implode(', ', $this->getProviderIndexes()), + )); + } + + return $httpResponseProvider->getResponse($requestConfiguration, $paymentRequest); + } + + public function getProviderIndexes(): array + { + return $this->locator->getProvidedServices(); + } + + public function getHttpResponseProvider(string $index): ?HttpResponseProviderInterface + { + return $this->locator->get($index); + } + + abstract protected function getHttpResponseProviderIndex(PaymentRequestInterface $paymentRequest): string; +} diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php index 0ca75399f0..dd1324f2d3 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ActionsHttpResponseProvider.php @@ -13,58 +13,20 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; -use Sylius\Bundle\PaymentBundle\Exception\PaymentRequestNotSupportedException; -use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Payment\Model\PaymentRequestInterface; -use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Service\ServiceProviderInterface; -final class ActionsHttpResponseProvider implements ServiceProviderAwareProviderInterface +final class ActionsHttpResponseProvider extends AbstractServiceProvider { /** * @param ServiceProviderInterface $locator */ public function __construct( - private ServiceProviderInterface $locator, + protected ServiceProviderInterface $locator, ) { } - public function getResponse( - RequestConfiguration $requestConfiguration, - PaymentRequestInterface $paymentRequest, - ): Response { - $action = $paymentRequest->getAction(); - $httpResponseProvider = $this->getHttpResponseProvider($action); - if (null === $httpResponseProvider) { - throw new PaymentRequestNotSupportedException(sprintf( - 'No payment request HTTP Response provider supported for this action "%s".', - $action - )); - } - - return $httpResponseProvider->getResponse($requestConfiguration, $paymentRequest); - } - - public function supports( - RequestConfiguration $requestConfiguration, - PaymentRequestInterface $paymentRequest, - ): bool { - $action = $paymentRequest->getAction(); - $httpResponseProvider = $this->getHttpResponseProvider($action); - if (null === $httpResponseProvider) { - return false; - } - - return $httpResponseProvider->supports($requestConfiguration, $paymentRequest); - } - - public function getProviderIndex(): array - { - return $this->locator->getProvidedServices(); - } - - public function getHttpResponseProvider(string $index): ?HttpResponseProviderInterface - { - return $this->locator->get($index); + protected function getHttpResponseProviderIndex(PaymentRequestInterface $paymentRequest): string { + return $paymentRequest->getAction(); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php index 73d977fae0..3c88f3929c 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryHttpResponseProvider.php @@ -13,70 +13,21 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; -use Sylius\Bundle\PaymentBundle\Exception\PaymentRequestNotSupportedException; -use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; -use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Service\ServiceProviderInterface; -final class GatewayFactoryHttpResponseProvider implements ServiceProviderAwareProviderInterface +final class GatewayFactoryHttpResponseProvider extends AbstractServiceProvider { /** * @param ServiceProviderInterface $locator */ public function __construct( private GatewayFactoryNameProviderInterface $gatewayFactoryNameProvider, - private ServiceProviderInterface $locator, + protected ServiceProviderInterface $locator, ) { } - public function getResponse( - RequestConfiguration $requestConfiguration, - PaymentRequestInterface $paymentRequest, - ): Response { - $factoryName = $this->getFactoryName($paymentRequest); - - $httpResponseProvider = $this->getHttpResponseProvider($factoryName); - - if (null === $httpResponseProvider) { - throw new PaymentRequestNotSupportedException(sprintf( - 'No payment request HTTP Response provider supported for the payment method factory name "%s".', - $factoryName - )); - } - - return $httpResponseProvider->getResponse($requestConfiguration, $paymentRequest); - } - - public function supports( - RequestConfiguration $requestConfiguration, - PaymentRequestInterface $paymentRequest, - ): bool { - $factoryName = $this->getFactoryName($paymentRequest); - $httpResponseProvider = $this->getHttpResponseProvider($factoryName); - - if (null === $httpResponseProvider) { - return false; - } - - return $httpResponseProvider->supports($requestConfiguration, $paymentRequest); - } - - public function getHttpResponseProvider(string $index): ?HttpResponseProviderInterface - { - return $this->locator->get($index); - } - - public function getProviderIndex(): array { - return $this->locator->getProvidedServices(); - } - - private function getFactoryName(PaymentRequestInterface $paymentRequest): string - { - /** @var PaymentMethodInterface $paymentMethod */ - $paymentMethod = $paymentRequest->getMethod(); - - return $this->gatewayFactoryNameProvider->provide($paymentMethod); + protected function getHttpResponseProviderIndex(PaymentRequestInterface $paymentRequest): string { + return $this->gatewayFactoryNameProvider->provideFromPaymentRequest($paymentRequest); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryNameProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryNameProvider.php index b713e3cde1..888df46bc5 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryNameProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryNameProvider.php @@ -14,13 +14,23 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; use Sylius\Component\Core\Model\PaymentMethodInterface; +use Sylius\Component\Payment\Model\GatewayConfigInterface; +use Sylius\Component\Payment\Model\PaymentRequestInterface; final class GatewayFactoryNameProvider implements GatewayFactoryNameProviderInterface { public function provide(PaymentMethodInterface $paymentMethod): string { + /** @var GatewayConfigInterface $gatewayConfig */ $gatewayConfig = $paymentMethod->getGatewayConfig(); return $gatewayConfig->getConfig()['factory'] ?? $gatewayConfig->getFactoryName(); } + + public function provideFromPaymentRequest(PaymentRequestInterface $paymentRequest): string { + /** @var PaymentMethodInterface $paymentMethod */ + $paymentMethod = $paymentRequest->getMethod(); + + return $this->provide($paymentMethod); + } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryNameProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryNameProviderInterface.php index 14b0565fbe..9c282b1a6d 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryNameProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/GatewayFactoryNameProviderInterface.php @@ -14,8 +14,11 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Provider; use Sylius\Component\Core\Model\PaymentMethodInterface; +use Sylius\Component\Payment\Model\PaymentRequestInterface; interface GatewayFactoryNameProviderInterface { public function provide(PaymentMethodInterface $paymentMethod): string; + + public function provideFromPaymentRequest(PaymentRequestInterface $paymentRequest): string; } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php index bf9049cc6f..5286aadf4e 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/HttpResponseProviderInterface.php @@ -19,13 +19,13 @@ use Symfony\Component\HttpFoundation\Response; interface HttpResponseProviderInterface { - public function getResponse( - RequestConfiguration $requestConfiguration, - PaymentRequestInterface $paymentRequest, - ): Response; - public function supports( RequestConfiguration $requestConfiguration, PaymentRequestInterface $paymentRequest, ): bool; + + public function getResponse( + RequestConfiguration $requestConfiguration, + PaymentRequestInterface $paymentRequest, + ): Response; } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ServiceProviderAwareProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ServiceProviderAwareProviderInterface.php index d3092c0473..c80e4adfc3 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ServiceProviderAwareProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/ServiceProviderAwareProviderInterface.php @@ -18,5 +18,5 @@ interface ServiceProviderAwareProviderInterface extends HttpResponseProviderInte public function getHttpResponseProvider(string $index): ?HttpResponseProviderInterface; /** @return string[] */ - public function getProviderIndex(): array; + public function getProviderIndexes(): array; } From ae4de164661a6c0daac979fd6fa6a8bd6156783e Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 22:14:08 +0300 Subject: [PATCH 153/200] Fix indexed by action not type --- .../config/services/integrations/payum/offline.xml | 6 +++--- .../integrations/payum/paypal_express_checkout.xml | 8 ++++---- .../config/services/integrations/payum/stripe.xml | 8 ++++---- .../payment_request/offline/command_providers.xml | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml index b4e7df5fa8..d6454020af 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml @@ -19,16 +19,16 @@ - + - + - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml index 6e2c38e481..379645a71e 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml @@ -19,20 +19,20 @@ - + - + - + - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml index d1695fd786..5e741b35d0 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml @@ -19,20 +19,20 @@ - + - + - + - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml index 3b54b48e12..512b7b513b 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml @@ -17,12 +17,12 @@ > - + - + From f8dc3bd0e4186d3af7ec37bbd60ac9fed0c10676 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 4 Sep 2024 22:16:39 +0300 Subject: [PATCH 154/200] Introduce parameterized url for the thank you page url --- .../Controller/OrderPayController.php | 2 +- .../DependencyInjection/Configuration.php | 11 ++++ .../SyliusShopExtension.php | 10 ++++ .../Provider/NoPaymentPayResponseProvider.php | 5 +- .../Offline/StatusHttpResponseProvider.php | 50 +++++++++++++++++ .../Provider/OrderPayFinalUrlProvider.php | 53 ++++++++++++++++++ .../OrderPayFinalUrlProviderInterface.php | 21 ++++++++ ...PaymentRequestAfterPayResponseProvider.php | 13 +++-- .../Resolver/AfterPayNextResponseResolver.php | 54 ------------------- .../AfterPayNextResponseResolverInterface.php | 26 --------- .../Resources/config/services/providers.xml | 21 +++++++- .../Resources/config/services/resolvers.xml | 4 -- 12 files changed, 176 insertions(+), 94 deletions(-) create mode 100644 src/Sylius/Bundle/ShopBundle/Provider/Offline/StatusHttpResponseProvider.php create mode 100644 src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProvider.php create mode 100644 src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProviderInterface.php delete mode 100644 src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolver.php delete mode 100644 src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolverInterface.php diff --git a/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php b/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php index b960c32297..69b871da1d 100644 --- a/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php +++ b/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php @@ -77,6 +77,6 @@ final class OrderPayController } } - throw new LogicException(sprintf('No "after pay response provider" available.')); + throw new LogicException('No "after pay response provider" available.'); } } diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php index 6348e5fd4d..3c8bdc9bc6 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php @@ -66,6 +66,17 @@ final class Configuration implements ConfigurationInterface ->end() ->end() ->end() + ->arrayNode('order_pay') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('final_route') + ->defaultValue('sylius_shop_order_thank_you') + ->end() + ->arrayNode('final_route_parameters') + ->addDefaultsIfNotSet() + ->end() + ->end() + ->end() ->end() ; diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php index 7d779d2cd3..aa4a1e1290 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php @@ -41,6 +41,16 @@ final class SyliusShopExtension extends Extension 'sylius_shop.product_grid.include_all_descendants', $config['product_grid']['include_all_descendants'], ); + + $container->setParameter( + 'sylius_shop.order_pay.final_route', + $config['order_pay']['final_route'], + ); + $container->setParameter( + 'sylius_shop.order_pay.final_route_parameters', + $config['order_pay']['final_route_parameters'], + ); + $this->configureCheckoutResolverIfNeeded($config['checkout_resolver'], $container); } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php index 228642132e..0236bb984f 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php +++ b/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php @@ -18,13 +18,12 @@ use Sylius\Bundle\ShopBundle\Resolver\PaymentToPayResolverInterface; use Sylius\Component\Core\Model\OrderInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\RouterInterface; final class NoPaymentPayResponseProvider implements PayResponseProviderInterface { public function __construct( private PaymentToPayResolverInterface $paymentToPayResolver, - private RouterInterface $router, + private OrderPayFinalUrlProviderInterface $orderPayFinalUrlProvider, ) { } @@ -32,7 +31,7 @@ final class NoPaymentPayResponseProvider implements PayResponseProviderInterface RequestConfiguration $requestConfiguration, OrderInterface $order ): Response { - $url = $this->router->generate('sylius_shop_order_thank_you'); + $url = $this->orderPayFinalUrlProvider->getUrl(null); return new RedirectResponse($url); } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/Offline/StatusHttpResponseProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/Offline/StatusHttpResponseProvider.php new file mode 100644 index 0000000000..33ceb2f631 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Provider/Offline/StatusHttpResponseProvider.php @@ -0,0 +1,50 @@ + $finalRouteParameters + */ + public function __construct( + private RouterInterface $router, + private string $finalRoute, + private array $finalRouteParameters, + ) { + } + + public function supports( + RequestConfiguration $requestConfiguration, + PaymentRequestInterface $paymentRequest, + ): bool { + return $paymentRequest->getAction() === PaymentRequestInterface::ACTION_STATUS; + } + + public function getResponse( + RequestConfiguration $requestConfiguration, + PaymentRequestInterface $paymentRequest, + ): Response { + $finalUrl = $this->router->generate($this->finalRoute, $this->finalRouteParameters); + + return new RedirectResponse($finalUrl); + } +} diff --git a/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProvider.php b/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProvider.php new file mode 100644 index 0000000000..b768cb174f --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProvider.php @@ -0,0 +1,53 @@ + $finalRouteParameters + */ + public function __construct( + private RouterInterface $router, + private string $finalRoute, + private array $finalRouteParameters, + ) { + } + + public function getUrl(?PaymentInterface $payment): string { + $finalUrl = $this->router->generate($this->finalRoute, $this->finalRouteParameters); + if ( + null === $payment || + $payment->getState() === BasePaymentInterface::STATE_COMPLETED || + $payment->getState() === BasePaymentInterface::STATE_AUTHORIZED + ) { + return $finalUrl; + } + + /** @var OrderInterface $order */ + $order = $payment->getOrder(); + + return $this->router->generate( + 'sylius_shop_order_show', + [ + 'tokenValue' => $order->getTokenValue(), + ] + ); + } +} diff --git a/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProviderInterface.php b/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProviderInterface.php new file mode 100644 index 0000000000..f3917f59dd --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProviderInterface.php @@ -0,0 +1,21 @@ +httpResponseProvider->getResponse($requestConfiguration, $statusPaymentRequest); } - $this->paymentStateFlashHandler->handle($requestConfiguration, $paymentRequest->getPayment()->getState()); + /** @var PaymentInterface $payment */ + $payment = $paymentRequest->getPayment(); + $this->paymentStateFlashHandler->handle($requestConfiguration, $payment->getState()); - return $this->afterPayNextResponseResolver->getResponse($requestConfiguration, $statusPaymentRequest); + $url = $this->orderPayFinalUrlProvider->getUrl($payment); + + return new RedirectResponse($url); } public function supports(RequestConfiguration $requestConfiguration): bool diff --git a/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolver.php b/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolver.php deleted file mode 100644 index b47adbd761..0000000000 --- a/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolver.php +++ /dev/null @@ -1,54 +0,0 @@ -getPayment(); - $order = $payment->getOrder(); - Assert::notNull($order, 'An order is required at this point.'); - - $route = 'sylius_shop_order_show'; - $params = ['tokenValue' => $order->getTokenValue()]; - - if ( - $payment->getState() === BasePaymentInterface::STATE_COMPLETED || - $payment->getState() === BasePaymentInterface::STATE_AUTHORIZED - ) { - $route = 'sylius_shop_order_thank_you'; - } - - $url = $this->router->generate($route, $params); - - return new RedirectResponse($url); - } -} diff --git a/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolverInterface.php b/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolverInterface.php deleted file mode 100644 index ae1131f4f5..0000000000 --- a/src/Sylius/Bundle/ShopBundle/Resolver/AfterPayNextResponseResolverInterface.php +++ /dev/null @@ -1,26 +0,0 @@ - + + + %sylius_shop.order_pay.final_route% + %sylius_shop.order_pay.final_route_parameters% + + - + @@ -53,9 +59,20 @@ - + + + + + + + + %sylius_shop.order_pay.final_route% + %sylius_shop.order_pay.final_route_parameters% + + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml index d5906d5b71..17ebc847c4 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml @@ -21,9 +21,5 @@ Sylius\Component\Payment\Model\PaymentInterface::STATE_NEW - - - - From 4172ac5e0a490c776458838afe9f290efa9131fd Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 5 Sep 2024 12:47:49 +0300 Subject: [PATCH 155/200] Move ShopBundle order_pay classes to CoreBundle --- phpstan-baseline.neon | 5 ++ .../Controller/OrderPayController.php | 11 +-- .../Handler/PaymentStateFlashHandler.php | 20 +++-- .../PaymentStateFlashHandlerInterface.php | 4 +- .../Processor/RouteParametersProcessor.php | 39 ++++++++++ .../RouteParametersProcessorInterface.php | 23 ++++++ .../AfterPayResponseProviderInterface.php | 3 +- .../OrderPay/Provider/FinalUrlProvider.php} | 36 +++++---- .../Provider/FinalUrlProviderInterface.php} | 4 +- .../Provider/NoPaymentPayResponseProvider.php | 6 +- .../Offline/StatusHttpResponseProvider.php | 14 ++-- .../Provider/PayResponseProviderInterface.php | 2 +- ...PaymentRequestAfterPayResponseProvider.php | 6 +- .../PaymentRequestPayResponseProvider.php | 6 +- .../PayumAfterPayResponseProvider.php | 4 +- .../Provider/PayumPayResponseProvider.php | 4 +- .../Resolver/PaymentToPayResolver.php | 2 +- .../PaymentToPayResolverInterface.php | 2 +- .../Resources/config/services/order_pay.xml | 19 +++++ .../config/services/order_pay/controllers.xml | 29 +++++++ .../config/services/order_pay/handlers.xml | 23 ++++++ .../services/order_pay/offline/providers.xml | 25 ++++++ .../config/services/order_pay/processors.xml | 25 ++++++ .../config/services/order_pay/providers.xml | 53 +++++++++++++ .../DependencyInjection/Configuration.php | 11 +++ .../SyliusShopExtension.php | 19 +++-- .../Resources/config/routing/order.yml | 4 +- .../ShopBundle/Resources/config/services.xml | 3 - .../Resources/config/services/controller.xml | 13 ---- .../services/integrations/order_pay.xml | 18 +++++ .../integrations/order_pay/controllers.xml | 24 ++++++ .../{ => integrations/order_pay}/handlers.xml | 2 +- .../order_pay/offline/providers.xml | 26 +++++++ .../integrations/order_pay/providers.xml | 63 +++++++++++++++ .../order_pay}/resolvers.xml | 2 +- .../Resources/config/services/providers.xml | 78 ------------------- 36 files changed, 462 insertions(+), 166 deletions(-) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Controller/OrderPayController.php (85%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Handler/PaymentStateFlashHandler.php (58%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Handler/PaymentStateFlashHandlerInterface.php (76%) create mode 100644 src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessor.php create mode 100644 src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessorInterface.php rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Provider/AfterPayResponseProviderInterface.php (86%) rename src/Sylius/Bundle/{ShopBundle/Provider/OrderPayFinalUrlProvider.php => CoreBundle/OrderPay/Provider/FinalUrlProvider.php} (50%) rename src/Sylius/Bundle/{ShopBundle/Provider/OrderPayFinalUrlProviderInterface.php => CoreBundle/OrderPay/Provider/FinalUrlProviderInterface.php} (80%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Provider/NoPaymentPayResponseProvider.php (85%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Provider/Offline/StatusHttpResponseProvider.php (74%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Provider/PayResponseProviderInterface.php (92%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Provider/PaymentRequestAfterPayResponseProvider.php (94%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Provider/PaymentRequestPayResponseProvider.php (95%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Provider/PayumAfterPayResponseProvider.php (95%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Provider/PayumPayResponseProvider.php (96%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Resolver/PaymentToPayResolver.php (92%) rename src/Sylius/Bundle/{ShopBundle => CoreBundle/OrderPay}/Resolver/PaymentToPayResolverInterface.php (89%) create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay.xml create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/controllers.xml create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/handlers.xml create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/offline/providers.xml create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/processors.xml create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml create mode 100644 src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay.xml create mode 100644 src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/controllers.xml rename src/Sylius/Bundle/ShopBundle/Resources/config/services/{ => integrations/order_pay}/handlers.xml (77%) create mode 100644 src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml create mode 100644 src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml rename src/Sylius/Bundle/ShopBundle/Resources/config/services/{ => integrations/order_pay}/resolvers.xml (91%) delete mode 100644 src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e5da9b7dc3..948c1e59f6 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4315,6 +4315,11 @@ parameters: count: 1 path: src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php + - + message: "#^Method Sylius\\\\Bundle\\\\ShopBundle\\\\DependencyInjection\\\\SyliusShopExtension\\:\\:configureOrderPay\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php + - message: "#^Method Sylius\\\\Bundle\\\\ShopBundle\\\\EventListener\\\\UserImpersonatedListener\\:\\:__construct\\(\\) has parameter \\$orderRepository with generic interface Sylius\\\\Component\\\\Core\\\\Repository\\\\OrderRepositoryInterface but does not specify its types\\: T$#" count: 1 diff --git a/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Controller/OrderPayController.php similarity index 85% rename from src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Controller/OrderPayController.php index 69b871da1d..fc7d836cda 100644 --- a/src/Sylius/Bundle/ShopBundle/Controller/OrderPayController.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Controller/OrderPayController.php @@ -11,22 +11,17 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Controller; +namespace Sylius\Bundle\CoreBundle\OrderPay\Controller; use LogicException; -use Payum\Core\Request\Generic; -use Payum\Core\Request\GetStatusInterface; +use Sylius\Bundle\CoreBundle\OrderPay\Provider\AfterPayResponseProviderInterface; +use Sylius\Bundle\CoreBundle\OrderPay\Provider\PayResponseProviderInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface; -use Sylius\Bundle\ShopBundle\Provider\AfterPayResponseProviderInterface; -use Sylius\Bundle\ShopBundle\Provider\PayResponseProviderInterface; use Sylius\Component\Core\Model\OrderInterface; -use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Order\Repository\OrderRepositoryInterface; use Sylius\Component\Resource\Metadata\MetadataInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; final class OrderPayController diff --git a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandler.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Handler/PaymentStateFlashHandler.php similarity index 58% rename from src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandler.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Handler/PaymentStateFlashHandler.php index e695956533..1147c5a445 100644 --- a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandler.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Handler/PaymentStateFlashHandler.php @@ -11,21 +11,31 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Handler; +namespace Sylius\Bundle\CoreBundle\OrderPay\Handler; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Payment\Model\PaymentInterface; -use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; +use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface; final class PaymentStateFlashHandler implements PaymentStateFlashHandlerInterface { + public function __construct( + private string $format = 'sylius.payment.%s', + ) { + } + public function handle(RequestConfiguration $requestConfiguration, string $state): void { $request = $requestConfiguration->getRequest(); + + if (!$request->hasSession()) { + return; + } + + /** @var FlashBagAwareSessionInterface $session */ + $session = $request->getSession(); if (PaymentInterface::STATE_NEW !== $state) { - /** @var FlashBagInterface $flashBag */ - $flashBag = $request->getSession()->getBag('flashes'); - $flashBag->add('info', sprintf('sylius.payment.%s', $state)); + $session->getFlashBag()->add('info', sprintf($this->format, $state)); } } } diff --git a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandlerInterface.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Handler/PaymentStateFlashHandlerInterface.php similarity index 76% rename from src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandlerInterface.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Handler/PaymentStateFlashHandlerInterface.php index c835a492a2..ab574afeb8 100644 --- a/src/Sylius/Bundle/ShopBundle/Handler/PaymentStateFlashHandlerInterface.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Handler/PaymentStateFlashHandlerInterface.php @@ -11,11 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Handler; +namespace Sylius\Bundle\CoreBundle\OrderPay\Handler; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; -use Sylius\Component\Core\Model\OrderInterface; -use Symfony\Component\HttpFoundation\Response; interface PaymentStateFlashHandlerInterface { diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessor.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessor.php new file mode 100644 index 0000000000..c2e7b396fd --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessor.php @@ -0,0 +1,39 @@ + $rawParameter) { + $parameters[$key] = (string) $this->expressionLanguage->evaluate($rawParameter, $context); + } + + return $this->router->generate( + $route, + $parameters, + ); + } +} diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessorInterface.php new file mode 100644 index 0000000000..94b65fe523 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessorInterface.php @@ -0,0 +1,23 @@ + $rawParameters + * @param array $context + */ + public function process(string $route, array $rawParameters, array $context): string; +} diff --git a/src/Sylius/Bundle/ShopBundle/Provider/AfterPayResponseProviderInterface.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayResponseProviderInterface.php similarity index 86% rename from src/Sylius/Bundle/ShopBundle/Provider/AfterPayResponseProviderInterface.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayResponseProviderInterface.php index e37a89cc7f..b1ebdbd321 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/AfterPayResponseProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayResponseProviderInterface.php @@ -11,10 +11,9 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; -use Sylius\Component\Core\Model\OrderInterface; use Symfony\Component\HttpFoundation\Response; interface AfterPayResponseProviderInterface diff --git a/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/FinalUrlProvider.php similarity index 50% rename from src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProvider.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/FinalUrlProvider.php index b768cb174f..5d54312ac2 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/FinalUrlProvider.php @@ -11,43 +11,49 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; -use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Bundle\CoreBundle\OrderPay\Processor\RouteParametersProcessorInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Payment\Model\PaymentInterface as BasePaymentInterface; -use Symfony\Component\Routing\RouterInterface; -final class OrderPayFinalUrlProvider implements OrderPayFinalUrlProviderInterface +final class FinalUrlProvider implements FinalUrlProviderInterface { /** * @param array $finalRouteParameters + * @param array $retryRouteParameters */ public function __construct( - private RouterInterface $router, + private RouteParametersProcessorInterface $routeParametersProcessor, private string $finalRoute, private array $finalRouteParameters, + private string $retryRoute, + private array $retryRouteParameters, ) { } public function getUrl(?PaymentInterface $payment): string { - $finalUrl = $this->router->generate($this->finalRoute, $this->finalRouteParameters); + $context = [ + 'payment' => $payment, + 'order' => $payment?->getOrder(), + ]; + if ( null === $payment || $payment->getState() === BasePaymentInterface::STATE_COMPLETED || $payment->getState() === BasePaymentInterface::STATE_AUTHORIZED ) { - return $finalUrl; + return $this->routeParametersProcessor->process( + $this->finalRoute, + $this->finalRouteParameters, + $context + ); } - /** @var OrderInterface $order */ - $order = $payment->getOrder(); - - return $this->router->generate( - 'sylius_shop_order_show', - [ - 'tokenValue' => $order->getTokenValue(), - ] + return $this->routeParametersProcessor->process( + $this->retryRoute, + $this->retryRouteParameters, + $context ); } } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProviderInterface.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/FinalUrlProviderInterface.php similarity index 80% rename from src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProviderInterface.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/FinalUrlProviderInterface.php index f3917f59dd..852f62ebf1 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/OrderPayFinalUrlProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/FinalUrlProviderInterface.php @@ -11,11 +11,11 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; use Sylius\Component\Core\Model\PaymentInterface; -interface OrderPayFinalUrlProviderInterface +interface FinalUrlProviderInterface { public function getUrl(?PaymentInterface $payment): string; } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/NoPaymentPayResponseProvider.php similarity index 85% rename from src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/NoPaymentPayResponseProvider.php index 0236bb984f..bc2ae6f9d5 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/NoPaymentPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/NoPaymentPayResponseProvider.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; +use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; -use Sylius\Bundle\ShopBundle\Resolver\PaymentToPayResolverInterface; use Sylius\Component\Core\Model\OrderInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; @@ -23,7 +23,7 @@ final class NoPaymentPayResponseProvider implements PayResponseProviderInterface { public function __construct( private PaymentToPayResolverInterface $paymentToPayResolver, - private OrderPayFinalUrlProviderInterface $orderPayFinalUrlProvider, + private FinalUrlProviderInterface $orderPayFinalUrlProvider, ) { } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/Offline/StatusHttpResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/Offline/StatusHttpResponseProvider.php similarity index 74% rename from src/Sylius/Bundle/ShopBundle/Provider/Offline/StatusHttpResponseProvider.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/Offline/StatusHttpResponseProvider.php index 33ceb2f631..16b7b12db1 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/Offline/StatusHttpResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/Offline/StatusHttpResponseProvider.php @@ -11,24 +11,19 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider\Offline; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider\Offline; +use Sylius\Bundle\CoreBundle\OrderPay\Provider\FinalUrlProviderInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\HttpResponseProviderInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\RouterInterface; final class StatusHttpResponseProvider implements HttpResponseProviderInterface { - /** - * @param array $finalRouteParameters - */ public function __construct( - private RouterInterface $router, - private string $finalRoute, - private array $finalRouteParameters, + private FinalUrlProviderInterface $finalUrlProvider, ) { } @@ -43,7 +38,8 @@ final class StatusHttpResponseProvider implements HttpResponseProviderInterface RequestConfiguration $requestConfiguration, PaymentRequestInterface $paymentRequest, ): Response { - $finalUrl = $this->router->generate($this->finalRoute, $this->finalRouteParameters); + // Force null payment to go to the thank you page + $finalUrl = $this->finalUrlProvider->getUrl(null); return new RedirectResponse($finalUrl); } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayResponseProviderInterface.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PayResponseProviderInterface.php similarity index 92% rename from src/Sylius/Bundle/ShopBundle/Provider/PayResponseProviderInterface.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PayResponseProviderInterface.php index ff94bd84f2..4e9122ba2c 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayResponseProviderInterface.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PayResponseProviderInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Core\Model\OrderInterface; diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php similarity index 94% rename from src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php index f8cf8c8a9d..c309ab31a3 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestAfterPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; +use Sylius\Bundle\CoreBundle\OrderPay\Handler\PaymentStateFlashHandlerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Announcer\PaymentRequestAnnouncerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\ServiceProviderAwareProviderInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; -use Sylius\Bundle\ShopBundle\Handler\PaymentStateFlashHandlerInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; @@ -38,7 +38,7 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr private ServiceProviderAwareProviderInterface $httpResponseProvider, private PaymentRequestRepositoryInterface $paymentRequestRepository, private PaymentStateFlashHandlerInterface $paymentStateFlashHandler, - private OrderPayFinalUrlProviderInterface $orderPayFinalUrlProvider, + private FinalUrlProviderInterface $orderPayFinalUrlProvider, ) { } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php similarity index 95% rename from src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php index e00dd62567..2306161e42 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PaymentRequestPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; +use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Announcer\PaymentRequestAnnouncerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\ServiceProviderAwareProviderInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; -use Sylius\Bundle\ShopBundle\Resolver\PaymentToPayResolverInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; @@ -31,11 +31,11 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte * @param PaymentRequestFactoryInterface $paymentRequestFactory */ public function __construct( - private PaymentToPayResolverInterface $paymentToPayResolver, private PaymentRequestFactoryInterface $paymentRequestFactory, private PaymentRequestAnnouncerInterface $paymentRequestAnnouncer, private ServiceProviderAwareProviderInterface $httpResponseProvider, private RouterInterface $router, + private PaymentToPayResolverInterface $paymentToPayResolver, ) { } diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayumAfterPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PayumAfterPayResponseProvider.php similarity index 95% rename from src/Sylius/Bundle/ShopBundle/Provider/PayumAfterPayResponseProvider.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PayumAfterPayResponseProvider.php index 23adbb8af2..1dad19f08c 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayumAfterPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PayumAfterPayResponseProvider.php @@ -11,16 +11,16 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; use Payum\Core\Payum; use Payum\Core\Request\Generic; use Payum\Core\Request\GetStatusInterface; use Payum\Core\Security\HttpRequestVerifierInterface; +use Sylius\Bundle\CoreBundle\OrderPay\Handler\PaymentStateFlashHandlerInterface; use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; use Sylius\Bundle\PayumBundle\Factory\ResolveNextRouteFactoryInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; -use Sylius\Bundle\ShopBundle\Handler\PaymentStateFlashHandlerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; diff --git a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PayumPayResponseProvider.php similarity index 96% rename from src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PayumPayResponseProvider.php index 8316b6dbe5..3c8b1531ae 100644 --- a/src/Sylius/Bundle/ShopBundle/Provider/PayumPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PayumPayResponseProvider.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Provider; +namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; use Payum\Core\Payum; use Payum\Core\Security\TokenInterface; +use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; -use Sylius\Bundle\ShopBundle\Resolver\PaymentToPayResolverInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Payment\Model\GatewayConfigInterface; diff --git a/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolver.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Resolver/PaymentToPayResolver.php similarity index 92% rename from src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolver.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Resolver/PaymentToPayResolver.php index 2e928ef973..1536c8e190 100644 --- a/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolver.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Resolver/PaymentToPayResolver.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Resolver; +namespace Sylius\Bundle\CoreBundle\OrderPay\Resolver; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentInterface; diff --git a/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolverInterface.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Resolver/PaymentToPayResolverInterface.php similarity index 89% rename from src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolverInterface.php rename to src/Sylius/Bundle/CoreBundle/OrderPay/Resolver/PaymentToPayResolverInterface.php index c8e582ba28..f60b23e08d 100644 --- a/src/Sylius/Bundle/ShopBundle/Resolver/PaymentToPayResolverInterface.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Resolver/PaymentToPayResolverInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\ShopBundle\Resolver; +namespace Sylius\Bundle\CoreBundle\OrderPay\Resolver; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentInterface; diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay.xml new file mode 100644 index 0000000000..9799504e9c --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay.xml @@ -0,0 +1,19 @@ + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/controllers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/controllers.xml new file mode 100644 index 0000000000..f7087130d2 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/controllers.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + sylius.order + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/handlers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/handlers.xml new file mode 100644 index 0000000000..c70ab8107d --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/handlers.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/offline/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/offline/providers.xml new file mode 100644 index 0000000000..abee57b423 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/offline/providers.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/processors.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/processors.xml new file mode 100644 index 0000000000..774f59e71d --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/processors.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml new file mode 100644 index 0000000000..502044031a --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php index 3c8bdc9bc6..5e0fbd0965 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php @@ -75,6 +75,17 @@ final class Configuration implements ConfigurationInterface ->arrayNode('final_route_parameters') ->addDefaultsIfNotSet() ->end() + ->scalarNode('retry_route') + ->defaultValue('sylius_shop_order_show') + ->end() + ->arrayNode('retry_route_parameters') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('tokenValue') + ->defaultValue('order.tokenValue') + ->end() + ->end() + ->end() ->end() ->end() ->end() diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php index aa4a1e1290..ea45556132 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php @@ -42,14 +42,8 @@ final class SyliusShopExtension extends Extension $config['product_grid']['include_all_descendants'], ); - $container->setParameter( - 'sylius_shop.order_pay.final_route', - $config['order_pay']['final_route'], - ); - $container->setParameter( - 'sylius_shop.order_pay.final_route_parameters', - $config['order_pay']['final_route_parameters'], - ); + $this->configureOrderPay($config['order_pay'], $container); + $loader->load('services/integrations/order_pay.xml'); $this->configureCheckoutResolverIfNeeded($config['checkout_resolver'], $container); } @@ -109,4 +103,13 @@ final class SyliusShopExtension extends Extension return $checkoutRedirectListener; } + + private function configureOrderPay(array $config, ContainerBuilder $container): void + { + $container->setParameter('sylius_shop.order_pay.final_route', $config['final_route']); + $container->setParameter('sylius_shop.order_pay.final_route_parameters', $config['final_route_parameters']); + $container->setParameter('sylius_shop.order_pay.final_route', $config['retry_route']); + $container->setParameter('sylius_shop.order_pay.final_route_parameters', $config['retry_route_parameters']); + } + } diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml index b6b2b466b7..e9f98eb850 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml @@ -13,7 +13,7 @@ sylius_shop_order_pay: path: /{tokenValue}/pay methods: [GET] defaults: - _controller: sylius.controller.shop.order_pay::payAction + _controller: sylius.shop.controller.order_pay::payAction _sylius: redirect: route: sylius_shop_order_after_pay @@ -22,7 +22,7 @@ sylius_shop_order_after_pay: path: /{hash?}/after-pay methods: [GET, POST] defaults: - _controller: sylius.controller.shop.order_pay::afterPayAction + _controller: sylius.shop.controller.order_pay::afterPayAction sylius_shop_order_show: path: /{tokenValue} diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services.xml index 547f2b719f..7d78b73319 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services.xml @@ -15,11 +15,8 @@ - - - diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml index ab0b900838..b3ec867ac1 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml @@ -54,18 +54,5 @@ - - - - - - - sylius.order - - - - - - diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay.xml new file mode 100644 index 0000000000..a69327eac6 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay.xml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/controllers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/controllers.xml new file mode 100644 index 0000000000..e9657e2ebd --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/controllers.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/handlers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/handlers.xml similarity index 77% rename from src/Sylius/Bundle/ShopBundle/Resources/config/services/handlers.xml rename to src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/handlers.xml index c3121f2950..8b508f2984 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/handlers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/handlers.xml @@ -17,7 +17,7 @@ > - + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml new file mode 100644 index 0000000000..49c8e93cab --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml new file mode 100644 index 0000000000..25d9993748 --- /dev/null +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + %sylius_shop.order_pay.final_route% + %sylius_shop.order_pay.final_route_parameters% + %sylius_shop.order_pay.retry_route% + %sylius_shop.order_pay.retry_route_parameters% + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/resolvers.xml similarity index 91% rename from src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml rename to src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/resolvers.xml index 17ebc847c4..285c40bd67 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/resolvers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/resolvers.xml @@ -17,7 +17,7 @@ > - + Sylius\Component\Payment\Model\PaymentInterface::STATE_NEW diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml deleted file mode 100644 index e2bc162d53..0000000000 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/providers.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - %sylius_shop.order_pay.final_route% - %sylius_shop.order_pay.final_route_parameters% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %sylius_shop.order_pay.final_route% - %sylius_shop.order_pay.final_route_parameters% - - - - - From 43248410bc1a0025ca46bd71cb143b55078f8692 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 5 Sep 2024 17:16:59 +0300 Subject: [PATCH 156/200] set authorize action when using use_authorize => true --- .../OrderPay/Provider/PaymentRequestPayResponseProvider.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php index 2306161e42..d2ef52b8db 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php @@ -51,6 +51,12 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte $paymentRequest = $this->paymentRequestFactory->create($payment, $paymentMethod); + $action = $paymentRequest->getAction(); + if ($paymentMethod->getGatewayConfig()?->getConfig()['use_authorize'] ?? false) { + $action = PaymentRequestInterface::ACTION_AUTHORIZE; + } + $paymentRequest->setAction($action); + $this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($paymentRequest); if ($this->httpResponseProvider->supports($requestConfiguration, $paymentRequest)) { From bb2b00a3b5d6d7db3bcb04180ec0d9ca4bf76d5d Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 5 Sep 2024 18:32:51 +0300 Subject: [PATCH 157/200] Add some specs tests --- .../RouteParametersProcessorSpec.php | 76 ++++++++++++++++ .../Provider/FinalUrlProviderSpec.php | 89 +++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 src/Sylius/Bundle/CoreBundle/spec/OrderPay/Processor/RouteParametersProcessorSpec.php create mode 100644 src/Sylius/Bundle/CoreBundle/spec/OrderPay/Provider/FinalUrlProviderSpec.php diff --git a/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Processor/RouteParametersProcessorSpec.php b/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Processor/RouteParametersProcessorSpec.php new file mode 100644 index 0000000000..5adfdc8cb7 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Processor/RouteParametersProcessorSpec.php @@ -0,0 +1,76 @@ +beConstructedWith( + $expressionLanguage, + $router, + ); + } + + function it_processes_from_a_route( + RouterInterface $router, + ): void { + $router->generate('a_route', [])->willReturn('https://localhost/a_route'); + + $this->process('a_route')->shouldReturn('https://localhost/a_route'); + } + + function it_processes_from_a_route_and_parameters( + RouterInterface $router, + ExpressionLanguage $expressionLanguage, + ): void { + $expressionLanguage->evaluate('value', [])->willReturn('value')->shouldBeCalledOnce(); + + $router->generate( + 'a_route', + ['aParam'=>'value'], + )->willReturn('https://localhost/a_route?aParam=value'); + + $this->process( + 'a_route', + ['aParam' => 'value'], + )->shouldReturn('https://localhost/a_route?aParam=value'); + } + + function it_processes_from_a_route_and_parameters_and_context( + RouterInterface $router, + ExpressionLanguage $expressionLanguage, + ): void { + $expressionLanguage->evaluate('value', [ + 'value' => '1' + ])->willReturn('1')->shouldBeCalledOnce(); + + $router->generate( + 'a_route', + ['aParam'=>'1'], + )->willReturn('https://localhost/a_route?aParam=1'); + + $this->process( + 'a_route', + ['aParam' => 'value'], + ['value' => '1'], + )->shouldReturn('https://localhost/a_route?aParam=1'); + } +} diff --git a/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Provider/FinalUrlProviderSpec.php b/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Provider/FinalUrlProviderSpec.php new file mode 100644 index 0000000000..e174d56a3b --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Provider/FinalUrlProviderSpec.php @@ -0,0 +1,89 @@ +beConstructedWith( + $routeParametersProcessor, + 'final_route', + [], + 'retry_route', + [], + ); + } + function it_provides_a_final_url_from_null_payment( + RouteParametersProcessorInterface $routeParametersProcessor, + ): void { + $routeParametersProcessor->process('final_route', [], [ + 'payment' => null, + 'order' => null, + ])->willReturn('http://localhost/final_route'); + + $this->getUrl(null)->shouldReturn('http://localhost/final_route'); + } + + function it_provides_a_final_url_from_payment_with_state_complete( + PaymentInterface $payment, + RouteParametersProcessorInterface $routeParametersProcessor, + ): void { + $payment->getOrder()->willReturn(null); + $payment->getState()->willReturn(BasePaymentInterface::STATE_COMPLETED); + + $routeParametersProcessor->process('final_route', [], [ + 'payment' => $payment->getWrappedObject(), + 'order' => null, + ])->willReturn('http://localhost/final_route'); + + $this->getUrl($payment)->shouldReturn('http://localhost/final_route'); + } + + function it_provides_a_final_url_from_payment_with_state_authorized( + PaymentInterface $payment, + RouteParametersProcessorInterface $routeParametersProcessor, + ): void { + $payment->getOrder()->willReturn(null); + $payment->getState()->willReturn(BasePaymentInterface::STATE_AUTHORIZED); + + $routeParametersProcessor->process('final_route', [], [ + 'payment' => $payment->getWrappedObject(), + 'order' => null, + ])->willReturn('http://localhost/final_route'); + + $this->getUrl($payment)->shouldReturn('http://localhost/final_route'); + } + + function it_provides_a_retry_url_from_payment_with_state_cancelled( + PaymentInterface $payment, + RouteParametersProcessorInterface $routeParametersProcessor, + ): void { + $payment->getOrder()->willReturn(null); + $payment->getState()->willReturn(BasePaymentInterface::STATE_CANCELLED)->shouldBeCalledTimes(2); + + $routeParametersProcessor->process('retry_route', [], [ + 'payment' => $payment->getWrappedObject(), + 'order' => null, + ])->willReturn('http://localhost/retry_route'); + + $this->getUrl($payment)->shouldReturn('http://localhost/retry_route'); + } +} From 4d0be3269f0db481ff84aad04b675380ca523a3b Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 5 Sep 2024 18:33:11 +0300 Subject: [PATCH 158/200] Allow empty params and context --- .../CoreBundle/OrderPay/Processor/RouteParametersProcessor.php | 2 +- .../OrderPay/Processor/RouteParametersProcessorInterface.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessor.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessor.php index c2e7b396fd..6f9cac4add 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessor.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessor.php @@ -24,7 +24,7 @@ final class RouteParametersProcessor implements RouteParametersProcessorInterfac ) { } - public function process(string $route, array $rawParameters, array $context): string + public function process(string $route, array $rawParameters = [], array $context = []): string { $parameters = []; foreach ($rawParameters as $key => $rawParameter) { diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessorInterface.php index 94b65fe523..a6641710d4 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Processor/RouteParametersProcessorInterface.php @@ -19,5 +19,5 @@ interface RouteParametersProcessorInterface * @param array $rawParameters * @param array $context */ - public function process(string $route, array $rawParameters, array $context): string; + public function process(string $route, array $rawParameters = [], array $context = []): string; } From ec19c8fd1fd82df21ddbc95701655dd11d869fc9 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 5 Sep 2024 18:35:11 +0300 Subject: [PATCH 159/200] Fix public exposition --- .../config/services/integrations/order_pay/controllers.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/controllers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/controllers.xml index e9657e2ebd..f9d3c5354b 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/controllers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/controllers.xml @@ -13,9 +13,8 @@ - - + From 95563f01b6b38537e8f861980511bc1efa01f44d Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 5 Sep 2024 18:35:50 +0300 Subject: [PATCH 160/200] Fix wrong parameter name --- .../ShopBundle/DependencyInjection/SyliusShopExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php index ea45556132..544d9a55bc 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php @@ -108,8 +108,8 @@ final class SyliusShopExtension extends Extension { $container->setParameter('sylius_shop.order_pay.final_route', $config['final_route']); $container->setParameter('sylius_shop.order_pay.final_route_parameters', $config['final_route_parameters']); - $container->setParameter('sylius_shop.order_pay.final_route', $config['retry_route']); - $container->setParameter('sylius_shop.order_pay.final_route_parameters', $config['retry_route_parameters']); + $container->setParameter('sylius_shop.order_pay.retry_route', $config['retry_route']); + $container->setParameter('sylius_shop.order_pay.retry_route_parameters', $config['retry_route_parameters']); } } From acfd3e76334ecb1bddf581d41967d3fce0be8705 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 5 Sep 2024 22:30:50 +0300 Subject: [PATCH 161/200] Fix tag names on services --- .../Resources/config/services/order_pay/offline/providers.xml | 3 ++- .../Resources/config/services/order_pay/providers.xml | 2 ++ .../Resources/config/services/integrations/order_pay.xml | 1 + .../services/integrations/order_pay/offline/providers.xml | 2 +- .../config/services/integrations/order_pay/providers.xml | 3 --- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/offline/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/offline/providers.xml index abee57b423..6c4443aecc 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/offline/providers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/offline/providers.xml @@ -17,8 +17,9 @@ > - + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml index 502044031a..db56a515f8 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml @@ -26,6 +26,7 @@ + @@ -44,6 +45,7 @@ + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay.xml index a69327eac6..293af0c8ca 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay.xml @@ -14,5 +14,6 @@ + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml index 49c8e93cab..ec181ae3c2 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml @@ -18,7 +18,7 @@ - + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml index 25d9993748..8be8a7039c 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml @@ -15,9 +15,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > - - - From f1288fb6e6292e3e7c5e57a0a986c2e158a4ac0b Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 5 Sep 2024 22:31:33 +0300 Subject: [PATCH 162/200] Fix empty locator service list throwing exception on the first ->get call --- .../Provider/PaymentRequestAfterPayResponseProvider.php | 5 +++++ .../OrderPay/Provider/PaymentRequestPayResponseProvider.php | 5 +++++ .../CommandProvider/AbstractServiceCommandProvider.php | 4 ++++ .../PaymentRequest/Provider/AbstractServiceProvider.php | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php index c309ab31a3..7ddd7f3010 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php @@ -13,6 +13,7 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; +use Doctrine\ORM\EntityManagerInterface; use Sylius\Bundle\CoreBundle\OrderPay\Handler\PaymentStateFlashHandlerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Announcer\PaymentRequestAnnouncerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\ServiceProviderAwareProviderInterface; @@ -34,6 +35,7 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr */ public function __construct( private PaymentRequestFactoryInterface $paymentRequestFactory, + private EntityManagerInterface $paymentRequestManager, private PaymentRequestAnnouncerInterface $paymentRequestAnnouncer, private ServiceProviderAwareProviderInterface $httpResponseProvider, private PaymentRequestRepositoryInterface $paymentRequestRepository, @@ -55,6 +57,9 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr $statusPaymentRequest = $this->paymentRequestFactory->createFromPaymentRequest($paymentRequest); $statusPaymentRequest->setAction(PaymentRequestInterface::ACTION_STATUS); + $this->paymentRequestManager->persist($paymentRequest); + $this->paymentRequestManager->flush(); + $this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($statusPaymentRequest); if ($this->httpResponseProvider->supports($requestConfiguration, $statusPaymentRequest)) { diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php index d2ef52b8db..8dcf7c7943 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php @@ -13,6 +13,7 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; +use Doctrine\ORM\EntityManagerInterface; use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Announcer\PaymentRequestAnnouncerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\ServiceProviderAwareProviderInterface; @@ -32,6 +33,7 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte */ public function __construct( private PaymentRequestFactoryInterface $paymentRequestFactory, + private EntityManagerInterface $paymentRequestManager, private PaymentRequestAnnouncerInterface $paymentRequestAnnouncer, private ServiceProviderAwareProviderInterface $httpResponseProvider, private RouterInterface $router, @@ -57,6 +59,9 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte } $paymentRequest->setAction($action); + $this->paymentRequestManager->persist($paymentRequest); + $this->paymentRequestManager->flush(); + $this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($paymentRequest); if ($this->httpResponseProvider->supports($requestConfiguration, $paymentRequest)) { diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php index ffe896cd0a..a41909f579 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php @@ -50,6 +50,10 @@ abstract class AbstractServiceCommandProvider implements ServiceProviderAwareCom public function getCommandProvider(string $index): ?PaymentRequestCommandProviderInterface { + if (false === $this->locator->has($index)) { + return null; + } + return $this->locator->get($index); } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php index fbb215042c..140cd18b5b 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php @@ -61,6 +61,10 @@ abstract class AbstractServiceProvider implements ServiceProviderAwareProviderIn public function getHttpResponseProvider(string $index): ?HttpResponseProviderInterface { + if (false === $this->locator->has($index)) { + return null; + } + return $this->locator->get($index); } From 94053344e0aa00df354a921cd4f39dec49ca1313 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 5 Sep 2024 22:53:31 +0300 Subject: [PATCH 163/200] Add missing afterPayUrl provider and the related ShopBundle config param --- .../OrderPay/Provider/AfterPayUrlProvider.php | 44 +++++++++++++++++++ .../Provider/AfterPayUrlProviderInterface.php | 21 +++++++++ .../PaymentRequestPayResponseProvider.php | 7 +-- .../config/services/order_pay/providers.xml | 4 ++ .../DependencyInjection/Configuration.php | 11 +++++ .../SyliusShopExtension.php | 2 + .../order_pay/offline/providers.xml | 2 +- .../integrations/order_pay/providers.xml | 12 +++-- 8 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayUrlProvider.php create mode 100644 src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayUrlProviderInterface.php diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayUrlProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayUrlProvider.php new file mode 100644 index 0000000000..90c4ab798b --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayUrlProvider.php @@ -0,0 +1,44 @@ + $afterPayRouteParameters + */ + public function __construct( + private RouteParametersProcessorInterface $routeParametersProcessor, + private string $afterPayRoute, + private array $afterPayRouteParameters, + ) { + } + + public function getUrl(PaymentRequestInterface $paymentRequest): string { + $context = [ + 'paymentRequest' => $paymentRequest, + 'payment' => $paymentRequest->getPayment(), + 'method' => $paymentRequest->getMethod(), + ]; + + return $this->routeParametersProcessor->process( + $this->afterPayRoute, + $this->afterPayRouteParameters, + $context + ); + } +} diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayUrlProviderInterface.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayUrlProviderInterface.php new file mode 100644 index 0000000000..072a26867e --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/AfterPayUrlProviderInterface.php @@ -0,0 +1,21 @@ +httpResponseProvider->getResponse($requestConfiguration, $paymentRequest); } - $url = $this->router->generate('sylius_shop_order_after_pay', [ - 'hash' => $paymentRequest->getId(), - ]); - - return new RedirectResponse($url); + return new RedirectResponse($this->afterPayUrlProvider->getUrl($paymentRequest)); } public function supports( diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml index db56a515f8..08ed7c28c8 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml @@ -14,6 +14,10 @@ + + + + diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php index 5e0fbd0965..18a77139a5 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php @@ -69,6 +69,17 @@ final class Configuration implements ConfigurationInterface ->arrayNode('order_pay') ->addDefaultsIfNotSet() ->children() + ->scalarNode('after_pay_route') + ->defaultValue('sylius_shop_order_after_pay') + ->end() + ->arrayNode('after_pay_route_parameters') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('hash') + ->defaultValue('paymentRequest.id') + ->end() + ->end() + ->end() ->scalarNode('final_route') ->defaultValue('sylius_shop_order_thank_you') ->end() diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php index 544d9a55bc..85b0263438 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php @@ -106,6 +106,8 @@ final class SyliusShopExtension extends Extension private function configureOrderPay(array $config, ContainerBuilder $container): void { + $container->setParameter('sylius_shop.order_pay.after_pay_route', $config['after_pay_route']); + $container->setParameter('sylius_shop.order_pay.after_pay_route_parameters', $config['after_pay_route_parameters']); $container->setParameter('sylius_shop.order_pay.final_route', $config['final_route']); $container->setParameter('sylius_shop.order_pay.final_route_parameters', $config['final_route_parameters']); $container->setParameter('sylius_shop.order_pay.retry_route', $config['retry_route']); diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml index ec181ae3c2..7694cb1b2e 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/offline/providers.xml @@ -18,7 +18,7 @@ - + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml index 8be8a7039c..4baa925ce9 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml @@ -18,7 +18,12 @@ - + + %sylius_shop.order_pay.after_pay_route% + %sylius_shop.order_pay.after_pay_route_parameters% + + + %sylius_shop.order_pay.final_route% %sylius_shop.order_pay.final_route_parameters% %sylius_shop.order_pay.retry_route% @@ -34,12 +39,13 @@ + - + @@ -52,7 +58,7 @@ - + From 42ac644cbc4381f032eb00f0d7b5e24aa5d9b774 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 6 Sep 2024 00:02:04 +0300 Subject: [PATCH 164/200] Fix full getter --- .../Bundle/ShopBundle/DependencyInjection/Configuration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php index 18a77139a5..4ba46d144a 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php @@ -76,7 +76,7 @@ final class Configuration implements ConfigurationInterface ->addDefaultsIfNotSet() ->children() ->scalarNode('hash') - ->defaultValue('paymentRequest.id') + ->defaultValue('paymentRequest.getHash()') ->end() ->end() ->end() @@ -93,7 +93,7 @@ final class Configuration implements ConfigurationInterface ->addDefaultsIfNotSet() ->children() ->scalarNode('tokenValue') - ->defaultValue('order.tokenValue') + ->defaultValue('order.getTokenValue()') ->end() ->end() ->end() From d6714a3f62214b280f3db21869e7735229dd5296 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 6 Sep 2024 00:02:25 +0300 Subject: [PATCH 165/200] Use repository instead of manager --- .../PaymentRequestAfterPayResponseProvider.php | 5 +---- .../Provider/PaymentRequestPayResponseProvider.php | 10 ++++------ .../Resources/config/services/order_pay/providers.xml | 4 +--- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php index 7ddd7f3010..ab133fe45b 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php @@ -13,7 +13,6 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; -use Doctrine\ORM\EntityManagerInterface; use Sylius\Bundle\CoreBundle\OrderPay\Handler\PaymentStateFlashHandlerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Announcer\PaymentRequestAnnouncerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\ServiceProviderAwareProviderInterface; @@ -35,7 +34,6 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr */ public function __construct( private PaymentRequestFactoryInterface $paymentRequestFactory, - private EntityManagerInterface $paymentRequestManager, private PaymentRequestAnnouncerInterface $paymentRequestAnnouncer, private ServiceProviderAwareProviderInterface $httpResponseProvider, private PaymentRequestRepositoryInterface $paymentRequestRepository, @@ -57,8 +55,7 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr $statusPaymentRequest = $this->paymentRequestFactory->createFromPaymentRequest($paymentRequest); $statusPaymentRequest->setAction(PaymentRequestInterface::ACTION_STATUS); - $this->paymentRequestManager->persist($paymentRequest); - $this->paymentRequestManager->flush(); + $this->paymentRequestRepository->add($paymentRequest); $this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($statusPaymentRequest); diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php index fc3bfc5d86..b8fd4f4c8a 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php @@ -13,7 +13,6 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; -use Doctrine\ORM\EntityManagerInterface; use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Announcer\PaymentRequestAnnouncerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\ServiceProviderAwareProviderInterface; @@ -21,22 +20,22 @@ use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; +use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\RouterInterface; use Webmozart\Assert\Assert; final class PaymentRequestPayResponseProvider implements PayResponseProviderInterface { /** * @param PaymentRequestFactoryInterface $paymentRequestFactory + * @param PaymentRequestRepositoryInterface $paymentRequestRepository */ public function __construct( private PaymentRequestFactoryInterface $paymentRequestFactory, - private EntityManagerInterface $paymentRequestManager, + private PaymentRequestRepositoryInterface $paymentRequestRepository, private PaymentRequestAnnouncerInterface $paymentRequestAnnouncer, private ServiceProviderAwareProviderInterface $httpResponseProvider, - private RouterInterface $router, private PaymentToPayResolverInterface $paymentToPayResolver, private AfterPayUrlProvider $afterPayUrlProvider, ) { @@ -60,8 +59,7 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte } $paymentRequest->setAction($action); - $this->paymentRequestManager->persist($paymentRequest); - $this->paymentRequestManager->flush(); + $this->paymentRequestRepository->add($paymentRequest); $this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($paymentRequest); diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml index 08ed7c28c8..a9e195203a 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml @@ -30,10 +30,9 @@ - + - @@ -49,7 +48,6 @@ - From 86c496a3dfa2f83ad1e17b5d35078ec1ccf00b76 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 6 Sep 2024 00:36:47 +0300 Subject: [PATCH 166/200] Fix wrong returned indexes --- .../CommandProvider/AbstractServiceCommandProvider.php | 2 +- .../PaymentRequest/Provider/AbstractServiceProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php index a41909f579..90690a7619 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandProvider/AbstractServiceCommandProvider.php @@ -59,7 +59,7 @@ abstract class AbstractServiceCommandProvider implements ServiceProviderAwareCom public function getCommandProviderIndexes(): array { - return $this->locator->getProvidedServices(); + return array_keys($this->locator->getProvidedServices()); } abstract protected function getCommandProviderIndex(PaymentRequestInterface $paymentRequest): string; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php index 140cd18b5b..15c966dd87 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/AbstractServiceProvider.php @@ -56,7 +56,7 @@ abstract class AbstractServiceProvider implements ServiceProviderAwareProviderIn public function getProviderIndexes(): array { - return $this->locator->getProvidedServices(); + return array_keys($this->locator->getProvidedServices()); } public function getHttpResponseProvider(string $index): ?HttpResponseProviderInterface From 250232e532690a16c8d9181f7137e80674799c12 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 6 Sep 2024 00:39:46 +0300 Subject: [PATCH 167/200] Add alias for the default provider --- .../Bundle/ApiBundle/Resources/config/services/validator.xml | 2 +- .../Resources/config/services/order_pay/providers.xml | 5 +++-- .../Resources/config/services/payment_request/announcer.xml | 2 +- .../config/services/payment_request/command_provider.xml | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/validator.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/validator.xml index 2d923af0cf..005fdf5ce6 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/validator.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/validator.xml @@ -195,7 +195,7 @@ - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml index a9e195203a..d6e5c81d14 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay/providers.xml @@ -32,7 +32,7 @@ - + @@ -49,8 +49,9 @@ - + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/announcer.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/announcer.xml index a66e9436a4..a660d2af35 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/announcer.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/announcer.xml @@ -19,7 +19,7 @@ - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_provider.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_provider.xml index d7c85aea13..1b4d531a5b 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_provider.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/command_provider.xml @@ -24,5 +24,7 @@ + + From 32eba20ba564f2aad0b94aedb46fb408869ea981 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 6 Sep 2024 00:40:51 +0300 Subject: [PATCH 168/200] Allow no status command provider --- ...PaymentRequestAfterPayResponseProvider.php | 21 +++++++++++-------- .../Announcer/PaymentRequestAnnouncer.php | 5 ----- .../services/payment_request/providers.xml | 2 ++ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php index ab133fe45b..b9f77ba4ed 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php @@ -15,6 +15,7 @@ namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; use Sylius\Bundle\CoreBundle\OrderPay\Handler\PaymentStateFlashHandlerInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Announcer\PaymentRequestAnnouncerInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\ServiceProviderAwareProviderInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Core\Model\PaymentInterface; @@ -37,6 +38,7 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr private PaymentRequestAnnouncerInterface $paymentRequestAnnouncer, private ServiceProviderAwareProviderInterface $httpResponseProvider, private PaymentRequestRepositoryInterface $paymentRequestRepository, + private PaymentRequestCommandProviderInterface $paymentRequestCommandProvider, private PaymentStateFlashHandlerInterface $paymentStateFlashHandler, private FinalUrlProviderInterface $orderPayFinalUrlProvider, ) { @@ -47,20 +49,21 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr $hash = $this->getPaymentRequestHash($requestConfiguration); Assert::notNull($hash, 'A request attribute "hash" is required to retrieve the related order.'); - $paymentRequest = $this->paymentRequestRepository->find($hash); - if (null === $paymentRequest) { + $capturePaymentRequest = $this->paymentRequestRepository->find($hash); + if (null === $capturePaymentRequest) { throw new NotFoundHttpException(sprintf('The Payment Request with hash "%s" does not exist.', $hash)); } - $statusPaymentRequest = $this->paymentRequestFactory->createFromPaymentRequest($paymentRequest); - $statusPaymentRequest->setAction(PaymentRequestInterface::ACTION_STATUS); + $paymentRequest = $this->paymentRequestFactory->createFromPaymentRequest($capturePaymentRequest); + $paymentRequest->setAction(PaymentRequestInterface::ACTION_STATUS); - $this->paymentRequestRepository->add($paymentRequest); + if ($this->paymentRequestCommandProvider->supports($paymentRequest)) { + $this->paymentRequestRepository->add($paymentRequest); + $this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($paymentRequest); + } - $this->paymentRequestAnnouncer->dispatchPaymentRequestCommand($statusPaymentRequest); - - if ($this->httpResponseProvider->supports($requestConfiguration, $statusPaymentRequest)) { - return $this->httpResponseProvider->getResponse($requestConfiguration, $statusPaymentRequest); + if ($this->httpResponseProvider->supports($requestConfiguration, $paymentRequest)) { + return $this->httpResponseProvider->getResponse($requestConfiguration, $paymentRequest); } /** @var PaymentInterface $payment */ diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php index 87558d0146..a52b60ee8d 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php @@ -14,7 +14,6 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Announcer; use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; -use Sylius\Bundle\PaymentBundle\Exception\PaymentRequestNotSupportedException; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Component\Messenger\MessageBusInterface; @@ -28,10 +27,6 @@ final class PaymentRequestAnnouncer implements PaymentRequestAnnouncerInterface public function dispatchPaymentRequestCommand(PaymentRequestInterface $paymentRequest): void { - if (!$this->paymentRequestCommandProvider->supports($paymentRequest)) { - throw new PaymentRequestNotSupportedException(); - } - $command = $this->paymentRequestCommandProvider->provide($paymentRequest); $this->commandBus->dispatch($command); diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/providers.xml index af297aaca5..25bc4a3567 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/providers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/providers.xml @@ -28,5 +28,7 @@ + + From 3b81554f2a901607f76e0996387188be5881c0f6 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 6 Sep 2024 21:27:45 +0300 Subject: [PATCH 169/200] Missing final keyword on spec class --- .../CoreBundle/spec/OrderPay/Provider/FinalUrlProviderSpec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Provider/FinalUrlProviderSpec.php b/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Provider/FinalUrlProviderSpec.php index e174d56a3b..8e09b9274a 100644 --- a/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Provider/FinalUrlProviderSpec.php +++ b/src/Sylius/Bundle/CoreBundle/spec/OrderPay/Provider/FinalUrlProviderSpec.php @@ -18,7 +18,7 @@ use PhpSpec\ObjectBehavior; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Payment\Model\PaymentInterface as BasePaymentInterface; -class FinalUrlProviderSpec extends ObjectBehavior +final class FinalUrlProviderSpec extends ObjectBehavior { function let( RouteParametersProcessorInterface $routeParametersProcessor, From bcd0c07b955bc05222038b28fff1c69ecb9d6363 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Fri, 6 Sep 2024 21:45:33 +0300 Subject: [PATCH 170/200] Fix phpstan --- .../OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php index b9f77ba4ed..4a616d38ad 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php @@ -49,6 +49,7 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr $hash = $this->getPaymentRequestHash($requestConfiguration); Assert::notNull($hash, 'A request attribute "hash" is required to retrieve the related order.'); + /** @var PaymentRequestInterface|null $capturePaymentRequest */ $capturePaymentRequest = $this->paymentRequestRepository->find($hash); if (null === $capturePaymentRequest) { throw new NotFoundHttpException(sprintf('The Payment Request with hash "%s" does not exist.', $hash)); From 6002b5454c10180fa057682baf36651265f7646f Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 9 Sep 2024 17:18:52 +0200 Subject: [PATCH 171/200] Change route to put optional param at the end of the route --- src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml index e9f98eb850..c13fd02d85 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml @@ -19,7 +19,7 @@ sylius_shop_order_pay: route: sylius_shop_order_after_pay sylius_shop_order_after_pay: - path: /{hash?}/after-pay + path: /after-pay/{hash?} methods: [GET, POST] defaults: _controller: sylius.shop.controller.order_pay::afterPayAction From 91e1c84179e628ef661eb958ff69ac462e8c2db8 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 9 Sep 2024 17:19:20 +0200 Subject: [PATCH 172/200] First check for Payum then check for PaymentRequest --- .../services/integrations/order_pay/providers.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml index 4baa925ce9..1fde0738b4 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml @@ -32,14 +32,14 @@ - - - - - + + + + + From 8c3278936cf732c258268770bb7bdf8cea9e9bcf Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 9 Sep 2024 17:25:48 +0200 Subject: [PATCH 173/200] Switch to the new MetadataInterface namespace --- .../CoreBundle/OrderPay/Controller/OrderPayController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Controller/OrderPayController.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Controller/OrderPayController.php index fc7d836cda..7a223f55ff 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Controller/OrderPayController.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Controller/OrderPayController.php @@ -19,7 +19,7 @@ use Sylius\Bundle\CoreBundle\OrderPay\Provider\PayResponseProviderInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Order\Repository\OrderRepositoryInterface; -use Sylius\Component\Resource\Metadata\MetadataInterface; +use Sylius\Resource\Metadata\MetadataInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; From 133ea7dce9e7507f46c2f10cf2462b3e5f3730ce Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 16 Sep 2024 19:02:27 +0200 Subject: [PATCH 174/200] Refactor to externalize API PaymentRequest from PayPalContext --- .../Behat/Context/Api/PaypalContext.php | 117 ++++-------------- .../Checkout/CheckoutOrderDetailsContext.php | 9 ++ .../Api/Shop/PaymentRequestContext.php | 85 +++++++++++++ .../config/services/contexts/api/shop.xml | 11 +- .../suites/api/checkout/paying_for_order.yml | 1 + 5 files changed, 127 insertions(+), 96 deletions(-) create mode 100644 src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php diff --git a/src/Sylius/Behat/Context/Api/PaypalContext.php b/src/Sylius/Behat/Context/Api/PaypalContext.php index f64e113c9e..c430521815 100644 --- a/src/Sylius/Behat/Context/Api/PaypalContext.php +++ b/src/Sylius/Behat/Context/Api/PaypalContext.php @@ -15,15 +15,11 @@ namespace Sylius\Behat\Context\Api; use Behat\Behat\Context\Context; use Sylius\Behat\Client\ApiClientInterface; -use Sylius\Behat\Client\RequestFactoryInterface; use Sylius\Behat\Client\ResponseCheckerInterface; +use Sylius\Behat\Context\Api\Shop\Checkout\CheckoutCompleteContext; +use Sylius\Behat\Context\Api\Shop\PaymentRequestContext; use Sylius\Behat\Service\Mocker\PaypalApiMocker; use Sylius\Behat\Service\SharedStorageInterface; -use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; -use Sylius\Component\Core\Model\PaymentMethodInterface; -use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; -use Sylius\Component\Payment\Model\PaymentRequestInterface; -use Symfony\Component\HttpFoundation\Request as HTTPRequest; use Webmozart\Assert\Assert; final class PaypalContext implements Context @@ -31,10 +27,9 @@ final class PaypalContext implements Context public function __construct( private ApiClientInterface $client, private ResponseCheckerInterface $responseChecker, - private SharedStorageInterface $sharedStorage, - private RequestFactoryInterface $requestFactory, private PaypalApiMocker $paypalApiMocker, - private PaymentMethodRepositoryInterface $paymentMethodRepository, + private CheckoutCompleteContext $checkoutCompleteContext, + private PaymentRequestContext $paymentRequestContext, ) { } @@ -44,14 +39,13 @@ final class PaypalContext implements Context */ public function iConfirmMyOrderWithPaypalPayment(): void { - $this->completeOrder(); + $this->checkoutCompleteContext->iConfirmMyOrder(); $this->paypalApiMocker->performActionInApiInitializeScope(function () { - $payment = $this->responseChecker->getValue($this->client->getLastResponse(), 'payments')[0]; - $this->postPaymentRequest($payment); - - $uri = $this->responseChecker->getValue($this->client->getLastResponse(), '@id'); - $this->sharedStorage->set('payment_request_uri', $uri); + $this->paymentRequestContext->iTryToPayForMyOrder([ + 'target_path' => 'https://myshop.tld/target-path', + 'after_path' => 'https://myshop.tld/after-path', + ]); }); } @@ -62,15 +56,16 @@ final class PaypalContext implements Context public function iSignInToPaypalAndAuthorizeOrPaySuccessfully(): void { $this->paypalApiMocker->performActionInApiSuccessfulScope(function () { - $this->putPaymentRequest( - $this->sharedStorage->get('payment_request_uri'), - [ + $this->paymentRequestContext->iTryToUpdateMyPaymentRequest([ + 'target_path' => 'https://myshop.tld/target-path', + 'after_path' => 'https://myshop.tld/after-path', + 'http_request' => [ 'query' => [ 'token' => 'EC-2d9EV13959UR209410U', 'PayerID' => 'UX8WBNYWGBVMG', ], ], - ); + ]); }); } @@ -80,15 +75,16 @@ final class PaypalContext implements Context */ public function iCancelMyPaypalPayment(): void { - $this->putPaymentRequest( - $this->sharedStorage->get('payment_request_uri'), - [ + $this->paymentRequestContext->iTryToUpdateMyPaymentRequest([ + 'target_path' => 'https://myshop.tld/target-path', + 'after_path' => 'https://myshop.tld/after-path', + 'http_request' => [ 'query' => [ 'token' => 'EC-2d9EV13959UR209410U', 'cancelled' => 1, ], ], - ); + ]); } /** @@ -96,15 +92,11 @@ final class PaypalContext implements Context */ public function iTryToPayAgain(): void { - $this->client->show(Resources::ORDERS, $this->sharedStorage->get('cart_token')); - $this->paypalApiMocker->performActionInApiInitializeScope(function () { - $payments = $this->responseChecker->getValue($this->client->getLastResponse(), 'payments'); - $payment = end($payments); - $this->postPaymentRequest($payment); - - $uri = $this->responseChecker->getValue($this->client->getLastResponse(), '@id'); - $this->sharedStorage->set('payment_request_uri', $uri); + $this->paymentRequestContext->iTryToPayForMyOrder([ + 'target_path' => 'https://myshop.tld/target-path', + 'after_path' => 'https://myshop.tld/after-path', + ]); }); } @@ -135,67 +127,4 @@ final class PaypalContext implements Context ), ); } - - private function completeOrder(): void - { - $request = $this->requestFactory->customItemAction( - 'shop', - Resources::ORDERS, - $this->sharedStorage->get('cart_token'), - HTTPRequest::METHOD_PATCH, - 'complete', - ); - - $this->client->executeCustomRequest($request); - } - - private function postPaymentRequest(array $payment): void - { - $request = $this->requestFactory->create( - 'shop', - Resources::PAYMENT_REQUESTS, - 'Authorization', - $this->client->getToken(), - ); - - /** @var PaymentMethodInterface $paymentMethod */ - $paymentMethod = $this->paymentMethodRepository->findOneBy([]); - /** @var GatewayConfigInterface $gatewayConfig */ - $gatewayConfig = $paymentMethod->getGatewayConfig(); - $authorize = $gatewayConfig->getConfig()['use_authorize'] ?? false; - - $request->setContent([ - 'paymentId' => $payment['id'], - 'paymentMethodCode' => $payment['method'], - 'action' => $authorize - ? PaymentRequestInterface::ACTION_AUTHORIZE - : PaymentRequestInterface::ACTION_CAPTURE, - 'payload' => [ - 'target_path' => 'https://myshop.tld/target-path', - 'after_path' => 'https://myshop.tld/after-path', - ], - ]); - - $this->client->executeCustomRequest($request); - } - - public function putPaymentRequest(string $paymentRequestUri, array $httpRequest = []): void - { - $request = $this->requestFactory->custom( - $paymentRequestUri, - HttpRequest::METHOD_PUT, - [], - $this->client->getToken(), - ); - - $request->setContent([ - 'payload' => [ - 'target_path' => 'https://myshop.tld/target-path', - 'after_path' => 'https://myshop.tld/after-path', - 'http_request' => $httpRequest, - ], - ]); - - $this->client->executeCustomRequest($request); - } } diff --git a/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php b/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php index 5af02a958d..2c775ab287 100644 --- a/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php @@ -59,6 +59,15 @@ final class CheckoutOrderDetailsContext implements Context Assert::notEq($state, PaymentInterface::STATE_NEW); } + /** + * @When I want to pay for my order + * @When I go to the change payment method page + */ + public function iWantToPayForMyOrder(): void + { + $this->client->show(Resources::ORDERS, $this->sharedStorage->get('cart_token')); + } + private function getLatestPaymentState(): ?string { $response = $this->client->show(Resources::ORDERS, $this->sharedStorage->get('cart_token')); diff --git a/src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php b/src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php new file mode 100644 index 0000000000..2b42fc164e --- /dev/null +++ b/src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php @@ -0,0 +1,85 @@ +client->show(Resources::ORDERS, $this->sharedStorage->get('cart_token')); + + $payments = $this->responseChecker->getValue($this->client->getLastResponse(), 'payments'); + $payment = end($payments); + $this->postPaymentRequest($payment, $payload); + + $uri = $this->responseChecker->getValue($this->client->getLastResponse(), '@id'); + $this->sharedStorage->set('payment_request_uri', $uri); + } + + /** + * @When I try to update my payment request + */ + public function iTryToUpdateMyPaymentRequest(array $payload = []): void + { + $this->putPaymentRequest($this->sharedStorage->get('payment_request_uri'), $payload); + } + + private function postPaymentRequest(array $payment, array $payload): void + { + $request = $this->requestFactory->create( + 'shop', + Resources::PAYMENT_REQUESTS, + 'Authorization', + $this->client->getToken(), + ); + + $request->setContent([ + 'paymentId' => $payment['id'], + 'paymentMethodCode' => $payment['method'], + 'payload' => $payload, + ]); + + $this->client->executeCustomRequest($request); + } + + public function putPaymentRequest(string $paymentRequestUri, array $payload = []): void + { + $request = $this->requestFactory->custom( + $paymentRequestUri, + HttpRequest::METHOD_PUT, + [], + $this->client->getToken(), + ); + + $request->setContent([ + 'payload' => $payload, + ]); + + $this->client->executeCustomRequest($request); + } +} diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml index 4a3d6a98cd..a13f0655ff 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml @@ -163,9 +163,16 @@ - - + + + + + + + + + diff --git a/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml b/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml index 816b8fa9f9..30d491d781 100644 --- a/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml +++ b/src/Sylius/Behat/Resources/config/suites/api/checkout/paying_for_order.yml @@ -47,6 +47,7 @@ default: - sylius.behat.context.api.shop.checkout.complete - sylius.behat.context.api.shop.checkout.order_details - sylius.behat.context.api.shop.order + - sylius.behat.context.api.shop.payment_request - sylius.behat.context.api.shop.response filters: From 4f8eaf1da7ab2f0d991e57953bb2853ed2bee90b Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 16 Sep 2024 19:03:28 +0200 Subject: [PATCH 175/200] Introduce default action & payload providers when no action or payload are given --- .../Command/Payment/AddPaymentRequest.php | 2 +- .../Payment/AddPaymentRequestHandler.php | 9 ++++-- .../config/services/command_handlers.xml | 2 ++ .../config/validation/AddPaymentRequest.xml | 7 ----- .../PaymentRequestPayResponseProvider.php | 11 ++++--- .../Provider/DefaultActionProvider.php | 31 +++++++++++++++++++ .../DefaultActionProviderInterface.php | 21 +++++++++++++ .../Provider/DefaultPayloadProvider.php | 24 ++++++++++++++ .../DefaultPayloadProviderInterface.php | 21 +++++++++++++ .../config/services/order_pay/providers.xml | 2 ++ .../services/payment_request/providers.xml | 6 ++++ 11 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultActionProvider.php create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultActionProviderInterface.php create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultPayloadProvider.php create mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultPayloadProviderInterface.php diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php index 8e42e31da8..dd26d165a4 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php @@ -21,7 +21,7 @@ class AddPaymentRequest implements IriToIdentifierConversionAwareInterface public function __construct( public readonly int|string $paymentId, public readonly string $paymentMethodCode, - public readonly string $action, + public readonly ?string $action = null, public readonly mixed $payload = null, ) { } diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index 5ed88739b1..1498550d1c 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -16,6 +16,8 @@ namespace Sylius\Bundle\ApiBundle\CommandHandler\Payment; use Sylius\Bundle\ApiBundle\Command\Payment\AddPaymentRequest; use Sylius\Bundle\ApiBundle\Exception\PaymentMethodNotFoundException; use Sylius\Bundle\ApiBundle\Exception\PaymentNotFoundException; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\DefaultActionProviderInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\DefaultPayloadProviderInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; @@ -28,6 +30,7 @@ use Symfony\Component\Messenger\Handler\MessageHandlerInterface; /** @experimental */ final class AddPaymentRequestHandler implements MessageHandlerInterface { + /** * @param PaymentMethodRepositoryInterface $paymentMethodRepository * @param PaymentRepositoryInterface $paymentRepository @@ -39,6 +42,8 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface private PaymentRepositoryInterface $paymentRepository, private PaymentRequestFactoryInterface $paymentRequestFactory, private PaymentRequestRepositoryInterface $paymentRequestRepository, + private DefaultActionProviderInterface $defaultActionProvider, + private DefaultPayloadProviderInterface $defaultPayloadProvider, ) { } @@ -70,8 +75,8 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface } $paymentRequest = $this->paymentRequestFactory->create($payment, $paymentMethod); - $paymentRequest->setAction($addPaymentRequest->action); - $paymentRequest->setPayload($addPaymentRequest->payload); + $paymentRequest->setAction($addPaymentRequest->action ?? $this->defaultActionProvider->getAction($paymentRequest)); + $paymentRequest->setPayload($addPaymentRequest->payload ?? $this->defaultPayloadProvider->getPayload($paymentRequest)); return $paymentRequest; } diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml index b2f2b9fb8e..f3dd220f88 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml @@ -217,6 +217,8 @@ + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml index 0d3b8a2a18..9486f588a3 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddPaymentRequest.xml @@ -32,12 +32,5 @@ - - - - - diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php index b8fd4f4c8a..d6d248e980 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestPayResponseProvider.php @@ -15,6 +15,8 @@ namespace Sylius\Bundle\CoreBundle\OrderPay\Provider; use Sylius\Bundle\CoreBundle\OrderPay\Resolver\PaymentToPayResolverInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Announcer\PaymentRequestAnnouncerInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\DefaultActionProviderInterface; +use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\DefaultPayloadProviderInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\ServiceProviderAwareProviderInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Component\Core\Model\OrderInterface; @@ -36,6 +38,8 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte private PaymentRequestRepositoryInterface $paymentRequestRepository, private PaymentRequestAnnouncerInterface $paymentRequestAnnouncer, private ServiceProviderAwareProviderInterface $httpResponseProvider, + private DefaultActionProviderInterface $defaultActionProvider, + private DefaultPayloadProviderInterface $defaultPayloadProvider, private PaymentToPayResolverInterface $paymentToPayResolver, private AfterPayUrlProvider $afterPayUrlProvider, ) { @@ -53,11 +57,8 @@ final class PaymentRequestPayResponseProvider implements PayResponseProviderInte $paymentRequest = $this->paymentRequestFactory->create($payment, $paymentMethod); - $action = $paymentRequest->getAction(); - if ($paymentMethod->getGatewayConfig()?->getConfig()['use_authorize'] ?? false) { - $action = PaymentRequestInterface::ACTION_AUTHORIZE; - } - $paymentRequest->setAction($action); + $paymentRequest->setAction($this->defaultActionProvider->getAction($paymentRequest)); + $paymentRequest->setPayload($this->defaultPayloadProvider->getPayload($paymentRequest)); $this->paymentRequestRepository->add($paymentRequest); diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultActionProvider.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultActionProvider.php new file mode 100644 index 0000000000..8e22a7f756 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultActionProvider.php @@ -0,0 +1,31 @@ +getMethod(); + /** @var GatewayConfigInterface $gatewayConfig */ + $gatewayConfig = $paymentMethod->getGatewayConfig(); + $authorize = $gatewayConfig->getConfig()['use_authorize'] ?? false; + + return $authorize ? PaymentRequestInterface::ACTION_AUTHORIZE : $paymentRequest->getAction(); + + } +} diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultActionProviderInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultActionProviderInterface.php new file mode 100644 index 0000000000..0dce2e1ab4 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Provider/DefaultActionProviderInterface.php @@ -0,0 +1,21 @@ + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/providers.xml index 25bc4a3567..2058af76cc 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/providers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/providers.xml @@ -30,5 +30,11 @@ + + + + + + From 9b3a842094c99887cc77edc3235812a54467a2da Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 16 Sep 2024 19:04:07 +0200 Subject: [PATCH 176/200] re-Enable some scenarios --- ...ffline_payment_method_after_order_confirmation.feature | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature b/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature index 0312aaded3..cc207873f9 100644 --- a/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature +++ b/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature @@ -21,7 +21,7 @@ Feature: Changing the offline payment method after order confirmation And I retry the payment with "Offline" payment method Then I should have chosen "Offline" payment method - @no-api @ui + @api @ui Scenario: Retrying the payment with different Offline payment works correctly together with inventory Given there is 1 unit of product "PHP T-Shirt" available in the inventory And this product is tracked by the inventory @@ -33,7 +33,7 @@ Feature: Changing the offline payment method after order confirmation And I retry the payment with "Offline" payment method Then I should have chosen "Offline" payment method - @no-api @ui + @todo-api @ui Scenario: Being unable to pay for my order if my chosen payment method gets disabled Given I added product "PHP T-Shirt" to the cart When I complete addressing step with email "john@example.com" and "United States" based billing address @@ -44,7 +44,7 @@ Feature: Changing the offline payment method after order confirmation And I try to pay for my order Then I should be notified to choose a payment method - @no-api @ui + @api @ui Scenario: Retrying the payment with different payment method after order confirmation when the original is disabled Given I added product "PHP T-Shirt" to the cart When I complete addressing step with email "john@example.com" and "United States" based billing address @@ -55,7 +55,7 @@ Feature: Changing the offline payment method after order confirmation And I retry the payment with "Offline" payment method Then I should have chosen "Offline" payment method - @no-api @ui + @todo-api @ui Scenario: Being unable to pay for my order if no methods are available Given I added product "PHP T-Shirt" to the cart When I complete addressing step with email "john@example.com" and "United States" based billing address From f9c4ad20a7b5f3898b97b97c4461b5d376dc8bfa Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 16 Sep 2024 20:05:36 +0200 Subject: [PATCH 177/200] Fix too many required arguments --- .../post_payment_request_without_required_data.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Api/Responses/shop/payment_request/post_payment_request_without_required_data.json b/tests/Api/Responses/shop/payment_request/post_payment_request_without_required_data.json index 2375544bfe..40acb75331 100644 --- a/tests/Api/Responses/shop/payment_request/post_payment_request_without_required_data.json +++ b/tests/Api/Responses/shop/payment_request/post_payment_request_without_required_data.json @@ -1,4 +1,4 @@ { "code": 400, - "message": "Request does not have the following required fields specified: paymentId, paymentMethodCode, action." + "message": "Request does not have the following required fields specified: paymentId, paymentMethodCode." } From 2dd6cf5035fc754e373cbf1e84b42e38dacfe29d Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 16 Sep 2024 21:04:07 +0200 Subject: [PATCH 178/200] Fix PHPUnit env test_cached_payum --- config/services_test_cached_payum.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/services_test_cached_payum.yaml b/config/services_test_cached_payum.yaml index 26988e7f44..1a0c660f47 100644 --- a/config/services_test_cached_payum.yaml +++ b/config/services_test_cached_payum.yaml @@ -5,6 +5,6 @@ services: 'sylius.payment_request.command_provider.payum.offline': class: Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\ActionsCommandProvider arguments: - - !tagged_locator { tag: 'sylius.payment_request.command_provider.payum.offline', index_by: 'type' } + - !tagged_locator { tag: 'sylius.payment_request.command_provider.payum.offline', index_by: 'action' } tags: - { name: 'sylius.payment_request.command_provider', gateway-factory: 'offline', priority: -200 } From dbdd2264196e2a700da956c3c578f93e664fd448 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 16 Sep 2024 22:27:17 +0200 Subject: [PATCH 179/200] Prioritize PaymentRequest --- config/services_test_cached_payum.yaml | 20 ++++++++++- .../services/integrations/payum/offline.xml | 2 +- .../offline/command_handlers.xml | 2 ++ .../offline/command_providers.xml | 4 ++- .../integrations/order_pay/providers.xml | 33 ++++++++++--------- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/config/services_test_cached_payum.yaml b/config/services_test_cached_payum.yaml index 1a0c660f47..a4eff75f60 100644 --- a/config/services_test_cached_payum.yaml +++ b/config/services_test_cached_payum.yaml @@ -2,9 +2,27 @@ imports: - { resource: "services_test_cached.yaml" } services: + ## + # Prioritize Payum by tagging services with a higher priority (or lower for tagged_iterator). + ## + 'sylius.payment_request.command_provider.payum.offline': class: Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\ActionsCommandProvider arguments: - !tagged_locator { tag: 'sylius.payment_request.command_provider.payum.offline', index_by: 'action' } tags: - - { name: 'sylius.payment_request.command_provider', gateway-factory: 'offline', priority: -200 } + - { name: 'sylius.payment_request.command_provider', gateway-factory: 'offline', priority: -100 } + + 'sylius.shop.order_pay.provider.pay_response.payum': + parent: Sylius\Bundle\CoreBundle\OrderPay\Provider\PayumPayResponseProvider + arguments: + - '@sylius.shop.resolver.payment_to_pay' + tags: + - { name: 'sylius.shop.order_pay.provider.pay_response', priority: -150 } + + 'sylius.shop.order_pay.provider.after_pay_response.payum': + parent: Sylius\Bundle\CoreBundle\OrderPay\Provider\PayumAfterPayResponseProvider + arguments: + - '@sylius.shop.order_pay.handler.payment_state_flash' + tags: + - { name: 'sylius.shop.order_pay.provider.after_pay_response', priority: -50 } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml index d6454020af..70a31852ca 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/offline.xml @@ -20,7 +20,7 @@ - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml index 6678f28e62..1d449b1255 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml @@ -16,6 +16,8 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml index 512b7b513b..1980809280 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_providers.xml @@ -16,9 +16,11 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > + + - + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml index 1fde0738b4..0189bc86e3 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml @@ -17,6 +17,7 @@ > + %sylius_shop.order_pay.after_pay_route% @@ -32,35 +33,35 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + From 52188d7963b9c31768fade38696ae10e6ef9d686 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 17 Sep 2024 00:34:13 +0200 Subject: [PATCH 180/200] Simplify offline to the strict minimum --- .../Offline/CapturePaymentRequestHandler.php | 4 +- .../Payum/Factory/PayumTokenFactory.php | 4 +- .../Processor/Offline/CaptureProcessor.php | 36 ------------ .../Offline/CaptureProcessorInterface.php | 21 ------- .../offline/command_handlers.xml | 1 - .../payment_request/offline/processors.xml | 23 -------- .../CapturePaymentRequestHandlerSpec.php | 10 ++-- .../Offline/CaptureProcessorSpec.php | 57 ------------------- .../Resources/config/services/factory.xml | 3 - 9 files changed, 9 insertions(+), 150 deletions(-) delete mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessor.php delete mode 100644 src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessorInterface.php delete mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/processors.xml delete mode 100644 src/Sylius/Bundle/CoreBundle/spec/PaymentRequest/Processor/Offline/CaptureProcessorSpec.php diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php index ca928a6715..ff1f0086d9 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php @@ -16,6 +16,7 @@ namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandHandler\Offline; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline\CapturePaymentRequest; use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Offline\CaptureProcessorInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; +use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; /** @experimental */ @@ -23,7 +24,6 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface { public function __construct( private readonly PaymentRequestProviderInterface $paymentRequestProvider, - private readonly CaptureProcessorInterface $offlineCaptureProcessor, ) { } @@ -31,6 +31,6 @@ final class CapturePaymentRequestHandler implements MessageHandlerInterface { $paymentRequest = $this->paymentRequestProvider->provide($capturePaymentRequest); - $this->offlineCaptureProcessor->process($paymentRequest); + $paymentRequest->setState(PaymentRequestInterface::STATE_COMPLETED); } } diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactory.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactory.php index 52f7441d97..3a30a35b58 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactory.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Payum/Factory/PayumTokenFactory.php @@ -18,6 +18,7 @@ use Payum\Core\Security\TokenInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Payment\Exception\InvalidPaymentRequestPayloadException; use Sylius\Component\Payment\Model\PaymentRequestInterface; +use Webmozart\Assert\Assert; final class PayumTokenFactory implements PayumTokenFactoryInterface { @@ -33,6 +34,7 @@ final class PayumTokenFactory implements PayumTokenFactoryInterface $paymentMethod = $paymentRequest->getMethod(); $gatewayConfig = $paymentMethod->getGatewayConfig(); + Assert::notNull($gatewayConfig, sprintf('Gateway config of the payment method (code %s) cannot be null.', $paymentMethod->getCode())); $gatewayName = $gatewayConfig->getGatewayName(); /** @var array{ @@ -44,7 +46,7 @@ final class PayumTokenFactory implements PayumTokenFactoryInterface */ $payload = $paymentRequest->getPayload(); if (null === $payload) { - throw new InvalidPaymentRequestPayloadException('Payload of the payment request cannot be null'); + throw new InvalidPaymentRequestPayloadException('Payload of the payment request cannot be null.'); } $targetPath = $payload['target_path'] ?? null; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessor.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessor.php deleted file mode 100644 index 91269e08ab..0000000000 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessor.php +++ /dev/null @@ -1,36 +0,0 @@ -getPayment(); - - if ($this->stateMachine->can($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_PROCESS)) { - $this->stateMachine->apply($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_PROCESS); - } - - $paymentRequest->setState(PaymentRequestInterface::STATE_COMPLETED); - } -} diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessorInterface.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessorInterface.php deleted file mode 100644 index e645bb7892..0000000000 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Processor/Offline/CaptureProcessorInterface.php +++ /dev/null @@ -1,21 +0,0 @@ - - diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/processors.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/processors.xml deleted file mode 100644 index ac0645be05..0000000000 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/processors.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - diff --git a/src/Sylius/Bundle/CoreBundle/spec/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandlerSpec.php b/src/Sylius/Bundle/CoreBundle/spec/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandlerSpec.php index 7b9d4fc3c6..99ce9c5799 100644 --- a/src/Sylius/Bundle/CoreBundle/spec/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandlerSpec.php +++ b/src/Sylius/Bundle/CoreBundle/spec/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandlerSpec.php @@ -17,27 +17,25 @@ use PhpSpec\ObjectBehavior; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline\CapturePaymentRequest; use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Offline\CaptureProcessorInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; +use Sylius\Component\Payment\Model\PaymentRequest; use Sylius\Component\Payment\Model\PaymentRequestInterface; final class CapturePaymentRequestHandlerSpec extends ObjectBehavior { function let( - PaymentRequestProviderInterface $paymentRequestProvider, - CaptureProcessorInterface $offlineCaptureProcessor + PaymentRequestProviderInterface $paymentRequestProvider ): void { - $this->beConstructedWith($paymentRequestProvider, $offlineCaptureProcessor); + $this->beConstructedWith($paymentRequestProvider); } function it_processes_offline_capture( PaymentRequestProviderInterface $paymentRequestProvider, - CaptureProcessorInterface $offlineCaptureProcessor, PaymentRequestInterface $paymentRequest ): void { $capturePaymentRequest = new CapturePaymentRequest('hash'); $paymentRequestProvider->provide($capturePaymentRequest)->willReturn($paymentRequest); + $paymentRequest->setState(PaymentRequestInterface::STATE_COMPLETED)->shouldBeCalled(); $this->__invoke($capturePaymentRequest); - - $offlineCaptureProcessor->process($paymentRequest)->shouldHaveBeenCalled(); } } diff --git a/src/Sylius/Bundle/CoreBundle/spec/PaymentRequest/Processor/Offline/CaptureProcessorSpec.php b/src/Sylius/Bundle/CoreBundle/spec/PaymentRequest/Processor/Offline/CaptureProcessorSpec.php deleted file mode 100644 index f00210696b..0000000000 --- a/src/Sylius/Bundle/CoreBundle/spec/PaymentRequest/Processor/Offline/CaptureProcessorSpec.php +++ /dev/null @@ -1,57 +0,0 @@ -beConstructedWith($stateMachine); - } - - function it_processes_offline_capture( - StateMachineInterface $stateMachine, - PaymentRequestInterface $paymentRequest, - PaymentInterface $payment - ): void { - $paymentRequest->getPayment()->willReturn($payment); - $stateMachine->can($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_PROCESS)->willReturn(true); - - $this->process($paymentRequest); - - $stateMachine->apply($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_PROCESS)->shouldHaveBeenCalledOnce(); - $paymentRequest->setState(PaymentRequestInterface::STATE_COMPLETED)->shouldHaveBeenCalledOnce(); - } - - function it_processes_offline_capture_if_payment_cannot_be_processed( - StateMachineInterface $stateMachine, - PaymentRequestInterface $paymentRequest, - PaymentInterface $payment - ): void { - $paymentRequest->getPayment()->willReturn($payment); - $stateMachine->can($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_PROCESS)->willReturn(false); - - $this->process($paymentRequest); - - $stateMachine->apply($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_PROCESS)->shouldNotHaveBeenCalled(); - $paymentRequest->setState(PaymentRequestInterface::STATE_COMPLETED)->shouldHaveBeenCalledOnce(); - } -} diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml index 62ee359335..595cb5ecdb 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/services/factory.xml @@ -14,9 +14,6 @@ - - - From 3f387ca80842e06bc297b3897ddc24cda6bd57ef Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 17 Sep 2024 09:47:27 +0200 Subject: [PATCH 181/200] Rename var --- .../Provider/PaymentRequestAfterPayResponseProvider.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php index 4a616d38ad..be91209c1c 100644 --- a/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php +++ b/src/Sylius/Bundle/CoreBundle/OrderPay/Provider/PaymentRequestAfterPayResponseProvider.php @@ -49,13 +49,13 @@ final class PaymentRequestAfterPayResponseProvider implements AfterPayResponsePr $hash = $this->getPaymentRequestHash($requestConfiguration); Assert::notNull($hash, 'A request attribute "hash" is required to retrieve the related order.'); - /** @var PaymentRequestInterface|null $capturePaymentRequest */ - $capturePaymentRequest = $this->paymentRequestRepository->find($hash); - if (null === $capturePaymentRequest) { + /** @var PaymentRequestInterface|null $previousPaymentRequest */ + $previousPaymentRequest = $this->paymentRequestRepository->find($hash); + if (null === $previousPaymentRequest) { throw new NotFoundHttpException(sprintf('The Payment Request with hash "%s" does not exist.', $hash)); } - $paymentRequest = $this->paymentRequestFactory->createFromPaymentRequest($capturePaymentRequest); + $paymentRequest = $this->paymentRequestFactory->createFromPaymentRequest($previousPaymentRequest); $paymentRequest->setAction(PaymentRequestInterface::ACTION_STATUS); if ($this->paymentRequestCommandProvider->supports($paymentRequest)) { From ac94a1912cb1070b8e6d3924e0b94154a65164db Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 17 Sep 2024 09:48:24 +0200 Subject: [PATCH 182/200] Lets Payum first check if it's a Payum gateway for UI --- config/services_test_cached_payum.yaml | 14 -------------- .../services/integrations/order_pay/providers.xml | 6 +++--- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/config/services_test_cached_payum.yaml b/config/services_test_cached_payum.yaml index a4eff75f60..f37f730666 100644 --- a/config/services_test_cached_payum.yaml +++ b/config/services_test_cached_payum.yaml @@ -12,17 +12,3 @@ services: - !tagged_locator { tag: 'sylius.payment_request.command_provider.payum.offline', index_by: 'action' } tags: - { name: 'sylius.payment_request.command_provider', gateway-factory: 'offline', priority: -100 } - - 'sylius.shop.order_pay.provider.pay_response.payum': - parent: Sylius\Bundle\CoreBundle\OrderPay\Provider\PayumPayResponseProvider - arguments: - - '@sylius.shop.resolver.payment_to_pay' - tags: - - { name: 'sylius.shop.order_pay.provider.pay_response', priority: -150 } - - 'sylius.shop.order_pay.provider.after_pay_response.payum': - parent: Sylius\Bundle\CoreBundle\OrderPay\Provider\PayumAfterPayResponseProvider - arguments: - - '@sylius.shop.order_pay.handler.payment_state_flash' - tags: - - { name: 'sylius.shop.order_pay.provider.after_pay_response', priority: -50 } diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml index 0189bc86e3..7c6a181353 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/services/integrations/order_pay/providers.xml @@ -39,14 +39,14 @@ - + - - + + From 100dad472a527ec7e177acf9eb034050f490ed10 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Mon, 23 Sep 2024 13:04:47 +0200 Subject: [PATCH 183/200] One line import Co-authored-by: Karol <33687392+Wojdylak@users.noreply.github.com> --- .../Bundle/CoreBundle/Resources/config/services/order_pay.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay.xml index 9799504e9c..af3d9185e8 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/order_pay.xml @@ -13,7 +13,6 @@ - - + From 206a8e682377bfb26cbb58e670320eb30a4655de Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Tue, 24 Sep 2024 09:37:52 +0200 Subject: [PATCH 184/200] Remove paypal integration --- .../payum/paypal_express_checkout.xml | 39 ------------------- .../config/integrations/payum/paypal.xml | 32 --------------- 2 files changed, 71 deletions(-) delete mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml delete mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/paypal.xml diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml deleted file mode 100644 index 379645a71e..0000000000 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/paypal_express_checkout.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/paypal.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/paypal.xml deleted file mode 100644 index 3bc5725d4a..0000000000 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/paypal.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - From fd0bf81fb5d0392c2856891d6ad9d874b0026da4 Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Tue, 24 Sep 2024 09:38:07 +0200 Subject: [PATCH 185/200] Remove stripe integration --- .../SyliusCoreExtension.php | 10 ----- .../services/integrations/payum/stripe.xml | 39 ------------------- .../SyliusPayumExtension.php | 10 ----- .../Resources/config/app/config.yaml | 9 ----- .../config/integrations/payum/stripe.xml | 27 ------------- 5 files changed, 95 deletions(-) delete mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml delete mode 100644 src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/stripe.xml diff --git a/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php b/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php index c1c499e664..1f2c20b820 100644 --- a/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php +++ b/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php @@ -14,8 +14,6 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\DependencyInjection; use Payum\Offline\OfflineGatewayFactory; -use Payum\Paypal\ExpressCheckout\Nvp\PaypalExpressCheckoutGatewayFactory; -use Payum\Stripe\StripeCheckoutGatewayFactory; use Sylius\Bundle\CoreBundle\Attribute\AsCatalogPromotionApplicatorCriteria; use Sylius\Bundle\CoreBundle\Attribute\AsCatalogPromotionPriceCalculator; use Sylius\Bundle\CoreBundle\Attribute\AsEntityObserver; @@ -195,14 +193,6 @@ final class SyliusCoreExtension extends AbstractResourceExtension implements Pre if (class_exists(OfflineGatewayFactory::class)) { $loader->load('services/integrations/payum/offline.xml'); } - - if (class_exists(PaypalExpressCheckoutGatewayFactory::class)) { - $loader->load('services/integrations/payum/paypal_express_checkout.xml'); - } - - if (class_exists(StripeCheckoutGatewayFactory::class)) { - $loader->load('services/integrations/payum/stripe.xml'); - } } private function registerAutoconfiguration(ContainerBuilder $container): void diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml deleted file mode 100644 index 5e741b35d0..0000000000 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/integrations/payum/stripe.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php index a89871ede9..021fd73f01 100644 --- a/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php +++ b/src/Sylius/Bundle/PayumBundle/DependencyInjection/SyliusPayumExtension.php @@ -13,8 +13,6 @@ declare(strict_types=1); namespace Sylius\Bundle\PayumBundle\DependencyInjection; -use Payum\Paypal\ExpressCheckout\Nvp\PaypalExpressCheckoutGatewayFactory; -use Payum\Stripe\StripeCheckoutGatewayFactory; use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -31,14 +29,6 @@ final class SyliusPayumExtension extends AbstractResourceExtension implements Pr $loader->load('services.xml'); - if (class_exists(PaypalExpressCheckoutGatewayFactory::class)) { - $loader->load('integrations/payum/paypal.xml'); - } - - if (class_exists(StripeCheckoutGatewayFactory::class)) { - $loader->load('integrations/payum/stripe.xml'); - } - $container->setParameter('payum.template.layout', $config['template']['layout']); $container->setParameter('payum.template.obtain_credit_card', $config['template']['obtain_credit_card']); } diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/app/config.yaml b/src/Sylius/Bundle/PayumBundle/Resources/config/app/config.yaml index 3a92582d9b..4805c1af32 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/app/config.yaml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/app/config.yaml @@ -24,12 +24,3 @@ sylius_payment: classes: model: Sylius\Bundle\PayumBundle\Model\GatewayConfig interface: Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface - - gateway_config: - validation_groups: - paypal_express_checkout: - - 'sylius' - - 'sylius_paypal_express_checkout' - stripe_checkout: - - 'sylius' - - 'sylius_stripe_checkout' diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/stripe.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/stripe.xml deleted file mode 100644 index 4cc237ab63..0000000000 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/integrations/payum/stripe.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - From 94930b8d2082281ee9d3ebd7dabad046918d50cb Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 25 Sep 2024 07:44:46 +0200 Subject: [PATCH 186/200] Remove usage of deprecated MessageHandlerInterface --- .../CommandHandler/Cart/RemoveItemFromCartHandler.php | 1 - .../CommandHandler/Payment/AddPaymentRequestHandler.php | 5 +++-- .../CommandHandler/Payment/UpdatePaymentRequestHandler.php | 5 +++-- .../Tests/Application/src/CommandHandler/FooHandler.php | 1 - .../Admin/Account/RequestResetPasswordEmailHandler.php | 1 - .../Admin/Account/SendResetPasswordEmailHandler.php | 1 - .../CommandHandler/Offline/CapturePaymentRequestHandler.php | 6 +++--- .../CommandHandler/Payum/ModelPaymentRequestHandler.php | 5 +++-- .../CommandHandler/Payum/TokenPaymentRequestHandler.php | 5 +++-- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Cart/RemoveItemFromCartHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Cart/RemoveItemFromCartHandler.php index fba955dc49..f81385391b 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Cart/RemoveItemFromCartHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Cart/RemoveItemFromCartHandler.php @@ -19,7 +19,6 @@ use Sylius\Component\Core\Model\OrderItemInterface; use Sylius\Component\Order\Modifier\OrderModifierInterface; use Sylius\Component\Order\Repository\OrderItemRepositoryInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; #[AsMessageHandler] diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index 1498550d1c..b3d5707568 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -25,10 +25,11 @@ use Sylius\Component\Core\Repository\PaymentRepositoryInterface; use Sylius\Component\Payment\Factory\PaymentRequestFactoryInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; +use Symfony\Component\Messenger\Attribute\AsMessageHandler; /** @experimental */ -final class AddPaymentRequestHandler implements MessageHandlerInterface +#[AsMessageHandler] +final class AddPaymentRequestHandler { /** diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php index 554aca864c..26496baa19 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php @@ -17,10 +17,11 @@ use Sylius\Bundle\ApiBundle\Command\Payment\UpdatePaymentRequest; use Sylius\Component\Payment\Exception\PaymentRequestNotFoundException; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; +use Symfony\Component\Messenger\Attribute\AsMessageHandler; /** @experimental */ -final class UpdatePaymentRequestHandler implements MessageHandlerInterface +#[AsMessageHandler] +final class UpdatePaymentRequestHandler { /** * @param PaymentRequestRepositoryInterface $paymentRequestRepository diff --git a/src/Sylius/Bundle/ApiBundle/Tests/Application/src/CommandHandler/FooHandler.php b/src/Sylius/Bundle/ApiBundle/Tests/Application/src/CommandHandler/FooHandler.php index fc7cc37ebd..12a30e0ec7 100644 --- a/src/Sylius/Bundle/ApiBundle/Tests/Application/src/CommandHandler/FooHandler.php +++ b/src/Sylius/Bundle/ApiBundle/Tests/Application/src/CommandHandler/FooHandler.php @@ -15,7 +15,6 @@ namespace Sylius\Bundle\ApiBundle\Application\CommandHandler; use Sylius\Bundle\ApiBundle\Application\Command\FooCommand; use Symfony\Component\Messenger\Attribute\AsMessageHandler; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; #[AsMessageHandler] final class FooHandler diff --git a/src/Sylius/Bundle/CoreBundle/CommandHandler/Admin/Account/RequestResetPasswordEmailHandler.php b/src/Sylius/Bundle/CoreBundle/CommandHandler/Admin/Account/RequestResetPasswordEmailHandler.php index b5081e3526..638ca63817 100644 --- a/src/Sylius/Bundle/CoreBundle/CommandHandler/Admin/Account/RequestResetPasswordEmailHandler.php +++ b/src/Sylius/Bundle/CoreBundle/CommandHandler/Admin/Account/RequestResetPasswordEmailHandler.php @@ -20,7 +20,6 @@ use Sylius\Component\User\Repository\UserRepositoryInterface; use Sylius\Component\User\Security\Generator\GeneratorInterface; use Symfony\Component\Clock\ClockInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp; diff --git a/src/Sylius/Bundle/CoreBundle/CommandHandler/Admin/Account/SendResetPasswordEmailHandler.php b/src/Sylius/Bundle/CoreBundle/CommandHandler/Admin/Account/SendResetPasswordEmailHandler.php index e17ad3cb5f..a57557a597 100644 --- a/src/Sylius/Bundle/CoreBundle/CommandHandler/Admin/Account/SendResetPasswordEmailHandler.php +++ b/src/Sylius/Bundle/CoreBundle/CommandHandler/Admin/Account/SendResetPasswordEmailHandler.php @@ -18,7 +18,6 @@ use Sylius\Bundle\CoreBundle\Mailer\ResetPasswordEmailManagerInterface; use Sylius\Component\Core\Model\AdminUserInterface; use Sylius\Component\User\Repository\UserRepositoryInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; #[AsMessageHandler] diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php index ff1f0086d9..5e9a006228 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php @@ -14,13 +14,13 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\CommandHandler\Offline; use Sylius\Bundle\CoreBundle\PaymentRequest\Command\Offline\CapturePaymentRequest; -use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Offline\CaptureProcessorInterface; use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; +use Symfony\Component\Messenger\Attribute\AsMessageHandler; /** @experimental */ -final class CapturePaymentRequestHandler implements MessageHandlerInterface +#[AsMessageHandler] +final class CapturePaymentRequestHandler { public function __construct( private readonly PaymentRequestProviderInterface $paymentRequestProvider, diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php index 132e27bed0..61f7de446e 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/ModelPaymentRequestHandler.php @@ -20,9 +20,10 @@ use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestProviderInter use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; +use Symfony\Component\Messenger\Attribute\AsMessageHandler; -final class ModelPaymentRequestHandler implements MessageHandlerInterface +#[AsMessageHandler] +final class ModelPaymentRequestHandler { public function __construct( private PaymentRequestProviderInterface $paymentRequestProvider, diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php index 402227d8cd..fe62eb77d3 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Payum/TokenPaymentRequestHandler.php @@ -21,9 +21,10 @@ use Sylius\Bundle\CoreBundle\PaymentRequest\Processor\Payum\RequestProcessorInte use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestProviderInterface; use Sylius\Bundle\PayumBundle\Factory\TokenAggregateRequestFactoryInterface; use Sylius\Component\Payment\Exception\NonExistingPayumTokenException; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; +use Symfony\Component\Messenger\Attribute\AsMessageHandler; -final class TokenPaymentRequestHandler implements MessageHandlerInterface +#[AsMessageHandler] +final class TokenPaymentRequestHandler { public function __construct( private PaymentRequestProviderInterface $paymentRequestProvider, From d0deea8120e51a4e1193f0f05b543ac108555afd Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 25 Sep 2024 08:40:48 +0200 Subject: [PATCH 187/200] [CI] Fix matrix --- .github/workflows/matrix.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/matrix.json b/.github/workflows/matrix.json index d6793322a4..f43e863230 100644 --- a/.github/workflows/matrix.json +++ b/.github/workflows/matrix.json @@ -39,7 +39,8 @@ "symfony": "^6.4", "api-platform": "^3.3", "mysql": "8.0", - "twig": "^3.3" + "twig": "^3.3", + "env": "test_cached" }, { "php": "8.3", @@ -52,7 +53,7 @@ { "php": "8.3", "symfony": "^6.4", - "api-platform": "^2.7.10", + "api-platform": "^3.3", "mysql": "8.4", "twig": "^3.3", "env": "test_cached_payum" From 2872d794f3f817a0efece01222ef261940babc09 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 25 Sep 2024 08:57:03 +0200 Subject: [PATCH 188/200] [Payum] Remove empty test suite config --- src/Sylius/Bundle/PayumBundle/phpunit.xml.dist | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Sylius/Bundle/PayumBundle/phpunit.xml.dist b/src/Sylius/Bundle/PayumBundle/phpunit.xml.dist index 20f2829b34..8efd23600b 100644 --- a/src/Sylius/Bundle/PayumBundle/phpunit.xml.dist +++ b/src/Sylius/Bundle/PayumBundle/phpunit.xml.dist @@ -7,10 +7,4 @@ - - - - ./Tests/ - - From ac0844a41e91ba1868446a7c6bac592d1479fa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pysiak?= Date: Wed, 25 Sep 2024 08:19:51 +0200 Subject: [PATCH 189/200] Add command bus for payment request --- .../Bundle/CoreBundle/Resources/config/app/messenger.yaml | 4 ++++ .../Resources/config/services/payment_request/announcer.xml | 2 +- .../services/payment_request/offline/command_handlers.xml | 2 +- .../services/payment_request/payum/command_handlers.xml | 6 +++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/messenger.yaml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/messenger.yaml index a6f1b02f76..3aa19039e6 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/app/messenger.yaml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/messenger.yaml @@ -51,3 +51,7 @@ framework: - validation sylius.event_bus: default_middleware: allow_no_handlers + sylius.payment_request.command_bus: + middleware: + - 'validation' + - 'doctrine_transaction' diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/announcer.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/announcer.xml index a660d2af35..3f1081adb7 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/announcer.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/announcer.xml @@ -20,7 +20,7 @@ - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml index de5e05014c..8b15f878bf 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/offline/command_handlers.xml @@ -20,7 +20,7 @@ - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/command_handlers.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/command_handlers.xml index 7b97de204a..07ba477212 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/command_handlers.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/payment_request/payum/command_handlers.xml @@ -28,12 +28,12 @@ - + - + @@ -44,7 +44,7 @@ - + From 5ec2ac0c7ae0626dbdc7f0cc720af62df8dd9450 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 26 Sep 2024 14:36:44 +0200 Subject: [PATCH 190/200] [API] Remove legacy ApiResources --- .../config/legacy_api_resources/Order.xml | 529 ------------------ .../legacy_api_resources/PaymentRequest.xml | 88 --- 2 files changed, 617 deletions(-) delete mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/Order.xml delete mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/PaymentRequest.xml diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/Order.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/Order.xml deleted file mode 100644 index 817a8e4565..0000000000 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/Order.xml +++ /dev/null @@ -1,529 +0,0 @@ - - - - - - - sylius - - - - GET - /admin/orders - - sylius.api.order_channel_filter - sylius.api.order_currency_filter - sylius.api.order_customer_filter - sylius.api.order_date_filter - sylius.api.order_number_filter - sylius.api.order_product_filter - sylius.api.order_shipping_method_filter - sylius.api.order_total_filter - sylius.api.order_variants_filter - - - DESC - - - - admin:order:index - sylius:admin:order:index - - - - - - POST - /shop/orders - input - Sylius\Bundle\ApiBundle\Command\Cart\PickupCart - - - shop:order:create - sylius:shop:order:create - - - - - shop:order:show - sylius:shop:order:show - shop:cart:show - sylius:shop:cart:show - - - - Pickups a new cart. - - - - - GET - /shop/orders - - - shop:order:index - sylius:shop:order:index - - - - - - - - GET - /admin/orders/{tokenValue} - - - admin:order:show - sylius:admin:order:show - - - - - - GET - /admin/orders/{tokenValue}/adjustments - Sylius\Bundle\ApiBundle\Controller\GetOrderAdjustmentsAction - false - - - admin:adjustment:show - sylius:admin:adjustment:show - - - - - - GET - /shop/orders/{tokenValue} - - - shop:cart:show - sylius:shop:cart:show - - - - - - DELETE - /shop/orders/{tokenValue} - - Deletes cart. - - - - shop:order:show - sylius:shop:order:show - - - - - - PATCH - /admin/orders/{tokenValue}/cancel - false - Sylius\Bundle\ApiBundle\Applicator\OrderStateMachineTransitionApplicatorInterface::cancel - - - admin:order:update - sylius:admin:order:update - - - - - admin:order:show - sylius:admin:order:show - - - - Cancels Order. - - - - - POST - /shop/orders/{tokenValue}/items - input - Sylius\Bundle\ApiBundle\Command\Cart\AddItemToCart - - - shop:cart:show - sylius:shop:cart:show - - - - - shop:cart:add_item - sylius:shop:cart:add_item - - - - Adds Item to cart. - - - - - PATCH - - sylius - - /shop/orders/{tokenValue}/shipments/{shipmentId} - input - Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod - - - shop:cart:select_shipping_method - sylius:shop:cart:select_shipping_method - - - - - shop:order:show - sylius:shop:order:show - shop:cart:show - sylius:shop:cart:show - - - - Selects shipping methods for particular shipment. - - - tokenValue - path - true - - string - - - - shipmentId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/payments/{paymentId} - input - Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod - - - shop:cart:select_payment_method - sylius:shop:cart:select_payment_method - - - - - shop:order:show - sylius:shop:order:show - shop:cart:show - sylius:shop:cart:show - - - - Selects payment methods for particular payment. - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - PATCH - /shop/account/orders/{tokenValue}/payments/{paymentId} - input - Sylius\Bundle\ApiBundle\Command\Account\ChangePaymentMethod - - - shop:order:account:change_payment_method - sylius:shop:order:account:change_payment_method - - - - - shop:order:account:show - sylius:shop:order:account:show - - - - Change the payment method as logged shop user. - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - GET - Sylius\Bundle\ApiBundle\Controller\Payment\GetPaymentConfiguration - /shop/orders/{tokenValue}/payments/{paymentId}/configuration - - Retrieve payment method configuration. - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/complete - - sylius - sylius_checkout_complete - - input - Sylius\Bundle\ApiBundle\Command\Checkout\CompleteOrder - - - shop:cart:complete - sylius:shop:cart:complete - - - - - shop:order:show - sylius:shop:order:show - shop:cart:show - sylius:shop:cart:show - - - - Completes checkout. - - - - - DELETE - /shop/orders/{tokenValue}/items/{itemId} - Sylius\Bundle\ApiBundle\Controller\DeleteOrderItemAction - false - - - shop:cart:remove_item - sylius:shop:cart:remove_item - - - - - - tokenValue - path - true - - string - - - - itemId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/items/{orderItemId} - input - Sylius\Bundle\ApiBundle\Command\Cart\ChangeItemQuantityInCart - - - shop:cart:change_quantity - sylius:shop:cart:change_quantity - - - - - shop:cart:show - sylius:shop:cart:show - - - - Changes quantity of order item. - - - tokenValue - path - true - - string - - - - orderItemId - path - true - - string - - - - - - - - PUT - /shop/orders/{tokenValue} - input - Sylius\Bundle\ApiBundle\Command\Checkout\UpdateCart - - - shop:cart:update - sylius:shop:cart:update - - - - - shop:order:show - sylius:shop:order:show - shop:cart:show - sylius:shop:cart:show - - - - Addresses cart to given location, logged in Customer does not have to provide an email. Applies coupon to cart. - - - - - POST - /admin/orders/{tokenValue}/resend-confirmation-email - input - Sylius\Bundle\ApiBundle\Command\ResendOrderConfirmationEmail - false - 202 - - Resends order confirmation email. - - - - - - - GET - /shop/orders/{tokenValue}/items - - - - GET - /admin/orders/{tokenValue}/shipments - - - - GET - /admin/orders/{tokenValue}/payments - - - - GET - /shop/orders/{tokenValue}/adjustments - - - - GET - /shop/orders/{tokenValue}/items/{items}/adjustments - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/PaymentRequest.xml deleted file mode 100644 index 51cc46e6f4..0000000000 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/PaymentRequest.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - sylius - - - DESC - - - - - POST - /shop/payment-requests - input - Sylius\Bundle\ApiBundle\Command\Payment\AddPaymentRequest - - sylius:shop:payment_request:create - - - sylius:shop:payment_request:show - - - - - - - GET - /admin/payment-requests/{hash} - - sylius:admin:payment_request:show - - - - - GET - /shop/payment-requests/{hash} - - sylius:shop:payment_request:show - - - - - PUT - /shop/payment-requests/{hash} - input - Sylius\Bundle\ApiBundle\Command\Payment\UpdatePaymentRequest - - sylius:shop:payment_request:update - - - - sylius:shop:payment_request:show - - - - - - - - - sylius:admin:payment_request:index - - - - - - - - - - - - From 2d65680fb0618e7c245b223e9989fef2f0689f1e Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Wed, 25 Sep 2024 13:42:27 +0200 Subject: [PATCH 191/200] [Admin] Add payment request index and show pages --- .../config/app/twig_hooks/order/show.yaml | 2 + .../payment/payment_request/index.yaml | 5 + .../payment/payment_request/show.yaml | 38 ++++++++ .../Resources/config/grids/payment.yml | 9 ++ .../config/grids/payment_request_payment.yml | 93 +++++++++++++++++++ .../Resources/config/routing/payment.yml | 26 ++++++ .../sections/payments/item/actions.html.twig | 2 +- .../actions/list_payment_requests.html.twig | 7 ++ .../common/label/state/cancelled.html.twig | 3 + .../common/label/state/completed.html.twig | 3 + .../common/label/state/failed.html.twig | 3 + .../common/label/state/new.html.twig | 3 + .../common/label/state/processing.html.twig | 3 + .../grid/field/action.html.twig | 1 + .../grid/field/method.html.twig | 1 + .../grid/field/state.html.twig | 1 + .../payment/payment_request/index.html.twig | 3 + .../content/header/breadcrumbs.html.twig | 10 ++ .../payment/payment_request/show.html.twig | 3 + .../show/content/header/breadcrumbs.html.twig | 12 +++ .../show/content/sections.html.twig | 13 +++ .../show/content/sections/general.html.twig | 12 +++ .../content/sections/general/action.html.twig | 6 ++ .../sections/general/created_at.html.twig | 8 ++ .../content/sections/general/hash.html.twig | 4 + .../content/sections/general/method.html.twig | 8 ++ .../content/sections/general/state.html.twig | 6 ++ .../sections/general/updated_at.html.twig | 8 ++ .../show/content/sections/payload.html.twig | 10 ++ .../content/sections/response_data.html.twig | 10 ++ .../Command/Payment/AddPaymentRequest.php | 3 +- .../Payment/AddPaymentRequestHandler.php | 1 - .../Payment/UpdatePaymentRequestHandler.php | 1 - .../properties/PaymentRequest.xml | 2 +- .../resources/admin/PaymentRequest.xml | 9 +- .../resources/shop/PaymentRequest.xml | 2 +- .../Resources/config/services/filters.xml | 9 ++ .../Announcer/PaymentRequestAnnouncer.php | 2 + .../Offline/CapturePaymentRequestHandler.php | 1 - .../Doctrine/ORM/PaymentRequestRepository.php | 27 ++++++ .../doctrine/model/PaymentRequest.orm.xml | 2 +- .../Resources/translations/messages.en.yml | 11 +++ .../PaymentRequestRepositoryInterface.php | 5 + 43 files changed, 376 insertions(+), 12 deletions(-) create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/index.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/show.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request_payment.yml create mode 100644 src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/cancelled.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/completed.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/failed.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/new.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/processing.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/action.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/method.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/state.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index/content/header/breadcrumbs.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/action.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/created_at.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/hash.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/method.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/state.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/updated_at.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/payload.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/response_data.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/order/show.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/order/show.yaml index 8be199f635..8e0be838cb 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/order/show.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/order/show.yaml @@ -124,6 +124,8 @@ twig_hooks: template: '@SyliusAdmin/order/show/content/sections/payments/item/actions.html.twig' 'sylius_admin.order.show.content.sections.payments.item.actions': + list_payment_requests: + template: '@SyliusAdmin/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig' complete: template: '@SyliusAdmin/order/show/content/sections/payments/item/actions/complete.html.twig' refund: diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/index.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/index.yaml new file mode 100644 index 0000000000..65a77dcde3 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/index.yaml @@ -0,0 +1,5 @@ +twig_hooks: + hooks: + 'sylius_admin.payment.payment_request.index.content.header': + breadcrumbs: + template: '@SyliusAdmin/payment/payment_request/index/content/header/breadcrumbs.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/show.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/show.yaml new file mode 100644 index 0000000000..0300d97740 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/show.yaml @@ -0,0 +1,38 @@ +twig_hooks: + hooks: + 'sylius_admin.payment.payment_request.show.content': + sections: + template: '@SyliusAdmin/payment/payment_request/show/content/sections.html.twig' + + 'sylius_admin.payment.payment_request.show.content.header': + breadcrumbs: + template: '@SyliusAdmin/payment/payment_request/show/content/header/breadcrumbs.html.twig' + + 'sylius_admin.payment.payment_request.show.content.sections': + general: + template: '@SyliusAdmin/payment/payment_request/show/content/sections/general.html.twig' + + 'sylius_admin.payment.payment_request.show.content.sections#left': + payload: + template: '@SyliusAdmin/payment/payment_request/show/content/sections/payload.html.twig' + + 'sylius_admin.payment.payment_request.show.content.sections#right': + response_data: + template: '@SyliusAdmin/payment/payment_request/show/content/sections/response_data.html.twig' + + 'sylius_admin.payment.payment_request.show.content.sections.general': + hash: + template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/hash.html.twig' + method: + template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/method.html.twig' + action: + template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/action.html.twig' + state: + template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/state.html.twig' + created_at: + template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/created_at.html.twig' + updated_at: + template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/updated_at.html.twig' + + + diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml index 9e68b20060..da8938a081 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml @@ -69,6 +69,15 @@ sylius_grid: class: "%sylius.model.channel.class%" actions: item: + show_payment_requests: + type: show + icon: list_letters + label: sylius.ui.list_payment_requests + options: + link: + route: sylius_admin_payment_payment_request_index + parameters: + id: resource.id complete: type: apply_transition label: sylius.ui.complete diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request_payment.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request_payment.yml new file mode 100644 index 0000000000..0193850f42 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request_payment.yml @@ -0,0 +1,93 @@ +sylius_grid: + grids: + sylius_admin_payment_payment_request: + driver: + name: doctrine/orm + options: + class: "%sylius.model.payment_request.class%" + repository: + method: createForPaymentQueryBuilder + arguments: + paymentId: $id + sorting: + createdAt: desc + fields: + hash: + type: string + label: sylius.ui.hash + sortable: ~ + method: + type: twig + label: sylius.ui.payment_method + path: . + options: + template: "@SyliusAdmin/payment/payment_request/grid/field/method.html.twig" + action: + type: twig + label: sylius.ui.action + options: + template: "@SyliusAdmin/payment/payment_request/grid/field/action.html.twig" + state: + type: twig + label: sylius.ui.state + options: + template: "@SyliusAdmin/payment/payment_request/grid/field/state.html.twig" + createdAt: + type: twig + label: sylius.ui.creation_date + sortable: ~ + options: + template: "@SyliusAdmin/shared/grid/field/date.html.twig" + vars: + th_class: "w-1 text-center" + updatedAt: + type: twig + label: sylius.ui.updating_date + sortable: ~ + options: + template: "@SyliusAdmin/shared/grid/field/date.html.twig" + vars: + th_class: "w-1 text-center" + filters: + payment_method: + type: ux_translatable_autocomplete + label: sylius.ui.payment_method + form_options: + extra_options: + class: "%sylius.model.payment_method.class%" + translation_fields: [ name ] + choice_label: name + options: + fields: [ method.id ] + action: + type: select + label: sylius.ui.action + form_options: + choices: + sylius.ui.authorize: authorize + sylius.ui.cancel: cancel + sylius.ui.capture: capture + sylius.ui.payout: payout + sylius.ui.refund: refund + sylius.ui.status: status + sylius.ui.sync: sync + state: + type: select + label: sylius.ui.state + form_options: + choices: + sylius.ui.cancelled: cancelled + sylius.ui.completed: completed + sylius.ui.failed: failed + sylius.ui.new: new + sylius.ui.processing: processing + actions: + item: + show: + type: show + options: + link: + route: sylius_admin_payment_payment_request_show + parameters: + hash: resource.hash + paymentId: resource.payment.id diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment.yml index 7836913aa2..1cf8a99c7d 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment.yml @@ -27,3 +27,29 @@ sylius_admin_payment_complete: transition: complete redirect: sylius_admin_payment_index flash: sylius.payment.completed + +sylius_admin_payment_payment_request_index: + path: /payments/{id}/payment_requests + methods: [GET] + defaults: + _controller: sylius.controller.payment_request::indexAction + _sylius: + section: admin + permission: true + template: "@SyliusAdmin/payment/payment_request/index.html.twig" + grid: sylius_admin_payment_payment_request + +sylius_admin_payment_payment_request_show: + path: /payments/{paymentId}/payment_requests/{hash} + methods: [GET] + defaults: + _controller: sylius.controller.payment_request::showAction + _sylius: + section: admin + permission: true + template: "@SyliusAdmin/payment/payment_request/show.html.twig" + repository: + method: findOneByPaymentId + arguments: + hash: $hash + paymentId: $paymentId diff --git a/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions.html.twig b/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions.html.twig index adda10e322..bd819d830f 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions.html.twig @@ -1,5 +1,5 @@ -
+
{% hook 'actions' %}
diff --git a/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig b/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig new file mode 100644 index 0000000000..35b236f598 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig @@ -0,0 +1,7 @@ +{% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon %} + +{% set payment = hookable_metadata.context.payment %} + + + {{ icon({ icon: 'list_letters', class: 'icon icon-tabler' }) }} + diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/cancelled.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/cancelled.html.twig new file mode 100644 index 0000000000..32ccce80d9 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/cancelled.html.twig @@ -0,0 +1,3 @@ + + {{ 'sylius.ui.cancelled'|trans }} + diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/completed.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/completed.html.twig new file mode 100644 index 0000000000..a5905f47ca --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/completed.html.twig @@ -0,0 +1,3 @@ + + {{ 'sylius.ui.completed'|trans }} + diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/failed.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/failed.html.twig new file mode 100644 index 0000000000..fe3f039a82 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/failed.html.twig @@ -0,0 +1,3 @@ + + {{ 'sylius.ui.failed'|trans }} + diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/new.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/new.html.twig new file mode 100644 index 0000000000..a4d06f6191 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/new.html.twig @@ -0,0 +1,3 @@ + + {{ 'sylius.ui.new'|trans }} + diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/processing.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/processing.html.twig new file mode 100644 index 0000000000..73cc86d08f --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/processing.html.twig @@ -0,0 +1,3 @@ + + {{ 'sylius.ui.processing'|trans }} + diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/action.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/action.html.twig new file mode 100644 index 0000000000..fdd927ad81 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/action.html.twig @@ -0,0 +1 @@ +{{ ('sylius.ui.' ~ data)|trans }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/method.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/method.html.twig new file mode 100644 index 0000000000..27de352225 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/method.html.twig @@ -0,0 +1 @@ +{{ data.method.name }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/state.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/state.html.twig new file mode 100644 index 0000000000..f4e5ed460d --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/state.html.twig @@ -0,0 +1 @@ +{{ include('@SyliusAdmin/payment/payment_request/common/label/state/' ~ data ~ '.html.twig') }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index.html.twig new file mode 100644 index 0000000000..0173df70ac --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index.html.twig @@ -0,0 +1,3 @@ +{% extends '@SyliusAdmin/shared/crud/index.html.twig' %} + +{% set resource_name = 'payment.payment_request' %} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index/content/header/breadcrumbs.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index/content/header/breadcrumbs.html.twig new file mode 100644 index 0000000000..6bb28bc2b8 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index/content/header/breadcrumbs.html.twig @@ -0,0 +1,10 @@ +{% from '@SyliusAdmin/shared/helper/breadcrumbs.html.twig' import breadcrumbs %} + +{% set configuration = hookable_metadata.context.resources.requestConfiguration %} + +{{ breadcrumbs([ + { name: 'sylius.ui.dashboard', url: path('sylius_admin_dashboard'), active: false }, + { name: 'sylius.ui.payments'|trans, url: path('sylius_admin_payment_index'), active: false }, + { name: configuration.request.get('id'), active: false }, + { name: 'sylius.ui.payment_requests'|trans, active: true }, +]) }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show.html.twig new file mode 100644 index 0000000000..b7fccd3b30 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show.html.twig @@ -0,0 +1,3 @@ +{% extends '@SyliusAdmin/shared/crud/show.html.twig' %} + +{% set resource_name = 'payment.payment_request' %} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig new file mode 100644 index 0000000000..4dfdab9d99 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig @@ -0,0 +1,12 @@ +{% from '@SyliusAdmin/shared/helper/breadcrumbs.html.twig' import breadcrumbs %} + +{% set payment_request = hookable_metadata.context.resource %} +{% set payment_id = payment_request.payment.id %} + +{{ breadcrumbs([ + { name: 'sylius.ui.dashboard', url: path('sylius_admin_dashboard'), active: false }, + { name: 'sylius.ui.payments'|trans, url: path('sylius_admin_payment_index'), active: false }, + { name: payment_id, active: false }, + { name: 'sylius.ui.payment_requests'|trans, url: path('sylius_admin_payment_payment_request_index', {'id': payment_id}), active: false }, + { name: payment_request.hash, active: true }, +]) }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections.html.twig new file mode 100644 index 0000000000..5c8568ec9d --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections.html.twig @@ -0,0 +1,13 @@ +
+
+ {% hook 'sections' %} +
+
+ {% hook 'sections#left' %} +
+
+ {% hook 'sections#right' %} +
+
+
+
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general.html.twig new file mode 100644 index 0000000000..ef8fb0c36a --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general.html.twig @@ -0,0 +1,12 @@ +
+
+
+ {{ 'sylius.ui.general'|trans }} +
+
+
+
+ {% hook 'general' %} +
+
+
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/action.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/action.html.twig new file mode 100644 index 0000000000..1ac90f6367 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/action.html.twig @@ -0,0 +1,6 @@ +
+
{{ 'sylius.ui.action'|trans }}
+
+ {{ ('sylius.ui.' ~ hookable_metadata.context.resource.action)|trans }} +
+
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/created_at.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/created_at.html.twig new file mode 100644 index 0000000000..b0d951d92f --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/created_at.html.twig @@ -0,0 +1,8 @@ +{% set date_format = hookable_metadata.configuration.date_format|default('YYYY-MM-dd HH:mm:ss') %} + +
+
{{ 'sylius.ui.created_at'|trans }}
+
+ {{ hookable_metadata.context.resource.createdAt|format_datetime(pattern=date_format) }} +
+
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/hash.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/hash.html.twig new file mode 100644 index 0000000000..ebd52237b9 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/hash.html.twig @@ -0,0 +1,4 @@ +
+
{{ 'sylius.ui.hash'|trans }}
+
{{ hookable_metadata.context.resource.hash }}
+
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/method.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/method.html.twig new file mode 100644 index 0000000000..bc03040d24 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/method.html.twig @@ -0,0 +1,8 @@ +{% set payment_method = hookable_metadata.context.resource.method %} + +
+
{{ 'sylius.ui.payment_method'|trans }}
+ +
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/state.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/state.html.twig new file mode 100644 index 0000000000..a541449a76 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/state.html.twig @@ -0,0 +1,6 @@ +
+
{{ 'sylius.ui.state'|trans }}
+
+ {{ include('@SyliusAdmin/payment/payment_request/common/label/state/' ~ hookable_metadata.context.resource.state ~ '.html.twig') }} +
+
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/updated_at.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/updated_at.html.twig new file mode 100644 index 0000000000..b2118eff8c --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/updated_at.html.twig @@ -0,0 +1,8 @@ +{% set date_format = hookable_metadata.configuration.date_format|default('YYYY-MM-dd HH:mm:ss') %} + +
+
{{ 'sylius.ui.updated_at'|trans }}
+
+ {{ hookable_metadata.context.resource.updatedAt|format_datetime(pattern=date_format) }} +
+
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/payload.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/payload.html.twig new file mode 100644 index 0000000000..d84ed901b7 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/payload.html.twig @@ -0,0 +1,10 @@ +
+
+
+ {{ 'sylius.ui.payload'|trans }} +
+
+
+
{{ hookable_metadata.context.resource.payload|json_encode(constant('JSON_PRETTY_PRINT')) }}
+
+
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/response_data.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/response_data.html.twig new file mode 100644 index 0000000000..4b0f4776c7 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/response_data.html.twig @@ -0,0 +1,10 @@ +
+
+
+ {{ 'sylius.ui.response_data'|trans }} +
+
+
+
{{ hookable_metadata.context.resource.responseData|json_encode(constant('JSON_PRETTY_PRINT')) }}
+
+
diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php index dd26d165a4..42a6a16d87 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php @@ -15,11 +15,10 @@ namespace Sylius\Bundle\ApiBundle\Command\Payment; use Sylius\Bundle\ApiBundle\Command\IriToIdentifierConversionAwareInterface; -/** @experimental */ class AddPaymentRequest implements IriToIdentifierConversionAwareInterface { public function __construct( - public readonly int|string $paymentId, + public readonly mixed $paymentId, public readonly string $paymentMethodCode, public readonly ?string $action = null, public readonly mixed $payload = null, diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php index b3d5707568..44e7ce8755 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/AddPaymentRequestHandler.php @@ -27,7 +27,6 @@ use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; -/** @experimental */ #[AsMessageHandler] final class AddPaymentRequestHandler { diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php index 26496baa19..c2ad290a3c 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Payment/UpdatePaymentRequestHandler.php @@ -19,7 +19,6 @@ use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; -/** @experimental */ #[AsMessageHandler] final class UpdatePaymentRequestHandler { diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/PaymentRequest.xml index 37dc151843..9377f9aea0 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/PaymentRequest.xml @@ -15,5 +15,5 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0 https://api-platform.com/schema/metadata/properties-3.0.xsd" > - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/admin/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/admin/PaymentRequest.xml index 1354ca0dea..5d77f2b6f9 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/admin/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/admin/PaymentRequest.xml @@ -16,7 +16,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0 https://api-platform.com/schema/metadata/resources-3.0.xsd" > - + - + - + @@ -47,6 +47,9 @@ + + sylius_api.search_filter.admin.payment_request + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/shop/PaymentRequest.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/shop/PaymentRequest.xml index d504ba2edb..2c0c96dc6b 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/shop/PaymentRequest.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/shop/PaymentRequest.xml @@ -16,7 +16,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0 https://api-platform.com/schema/metadata/resources-3.0.xsd" > - + + + + exact + exact + exact + + + + partial diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php index a52b60ee8d..e54a7aa93b 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php @@ -13,6 +13,8 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Announcer; +use Sylius\Bundle\CoreBundle\Command\Admin\Account\RequestResetPasswordEmail; +use Sylius\Bundle\CoreBundle\Command\CapturePaymentRequest; use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Component\Messenger\MessageBusInterface; diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php index 5e9a006228..a4fe9fdb42 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/CommandHandler/Offline/CapturePaymentRequestHandler.php @@ -18,7 +18,6 @@ use Sylius\Bundle\CoreBundle\PaymentRequest\Provider\PaymentRequestProviderInter use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; -/** @experimental */ #[AsMessageHandler] final class CapturePaymentRequestHandler { diff --git a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php index 8fffe03f0f..58e0c255d4 100644 --- a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php +++ b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php @@ -13,9 +13,11 @@ declare(strict_types=1); namespace Sylius\Bundle\PaymentBundle\Doctrine\ORM; +use Doctrine\ORM\QueryBuilder; 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 @@ -24,6 +26,31 @@ use Sylius\Component\Payment\Repository\PaymentRequestRepositoryInterface; */ class PaymentRequestRepository extends EntityRepository implements PaymentRequestRepositoryInterface { + public function findOneByPaymentId(mixed $hash, mixed $paymentId): ?PaymentRequestInterface + { + $queryBuilder = $this->createQueryBuilder('o'); + + return $queryBuilder + ->andWhere($queryBuilder->expr()->eq('o.hash', ':hash')) + ->andWhere($queryBuilder->expr()->eq('o.payment', ':paymentId')) + ->setParameter('hash', $hash, UuidType::NAME) + ->setParameter('paymentId', $paymentId) + ->getQuery() + ->getOneOrNullResult() + ; + } + + public function createForPaymentQueryBuilder(string $paymentId): QueryBuilder + { + $queryBuilder = $this->createQueryBuilder('o'); + $queryBuilder + ->andWhere($queryBuilder->expr()->eq('o.payment', ':paymentId')) + ->setParameter('paymentId', $paymentId) + ; + + return $queryBuilder; + } + public function duplicateExists(PaymentRequestInterface $paymentRequest): bool { /** @var PaymentRequestInterface[] $paymentRequests */ diff --git a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml index 476b0bf906..b63f9e74a0 100644 --- a/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml +++ b/src/Sylius/Bundle/PaymentBundle/Resources/config/doctrine/model/PaymentRequest.orm.xml @@ -24,7 +24,7 @@ - + diff --git a/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml index 5a195f699b..c4e695c119 100644 --- a/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml @@ -75,6 +75,7 @@ sylius: assortment: 'Assortment' attributes: 'Attributes' author: 'Author' + authorize: 'Authorize' authorized: 'Authorized' authorized_payment: 'Authorized payment' availability: 'Availability' @@ -110,6 +111,7 @@ sylius: call_us: 'Call us!' cancel: 'Cancel' cancelled: 'Cancelled' + capture: 'Capture' cart: 'Cart' cart_locked: 'Cart locked' cart_summary: 'Cart summary' @@ -397,6 +399,7 @@ sylius: guest: 'Guest' guest_customer: 'Guest customer' have_an_account_already: 'Have an account already?' + hash: 'Hash' height: 'Height' hello: 'Hello' hello_name: 'Hello %name%' @@ -448,6 +451,7 @@ sylius: license: 'License' links: 'Links' list_coupons: 'List coupons' + list_payment_requests: 'List payment requests' list_variants: 'List variants' loading: 'Loading' locale: 'Locale' @@ -646,14 +650,18 @@ sylius: password: 'Password' pay: 'Pay' pay_again: 'Click pay to try again' + payload: 'Payload' payment: 'Payment' payment_details: 'Payment details' payment_method: 'Payment method' payment_methods: 'Payment methods' payment_mode: 'Payment mode' payment_ready_to_pay: 'You can now make your payment' + payment_request: 'Payment request' + payment_requests: 'Payment requests' payment_state: 'Payment state' payments: 'Payments' + payout: 'Payout' pending: 'Pending' per_customer_usage_limit: 'Per customer usage limit' percent: 'Percent' @@ -751,6 +759,7 @@ sylius: reset: 'Reset' reset_button: 'Reset' reset_password: 'Reset password' + response_data: 'Response data' restore: 'Restore' retail_price: 'Retail price' return: 'Return' @@ -852,6 +861,7 @@ sylius: summary_of_your_order: 'Summary of your order' support: 'Support' sylius_logo: 'Sylius' + sync: 'Sync' target_currency: 'Target currency' tax: 'Tax' tax_categories: 'Tax Categories' @@ -951,6 +961,7 @@ sylius: update_cart: 'Update cart' update_product_association_type: 'Update product association type' updated: 'Updated' + updated_at: 'Updated at' updating_date: 'Updating date' updating_tax_rate: 'Updating tax rate' usage: 'Usage' diff --git a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php index 2eaca0a92d..a3f7887948 100644 --- a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php +++ b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php @@ -13,6 +13,7 @@ declare(strict_types=1); namespace Sylius\Component\Payment\Repository; +use Doctrine\ORM\QueryBuilder; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Sylius\Resource\Doctrine\Persistence\RepositoryInterface; @@ -23,5 +24,9 @@ use Sylius\Resource\Doctrine\Persistence\RepositoryInterface; */ interface PaymentRequestRepositoryInterface extends RepositoryInterface { + public function findOneByPaymentId(mixed $hash, mixed $paymentId): ?PaymentRequestInterface; + + public function createForPaymentQueryBuilder(string $paymentId): QueryBuilder; + public function duplicateExists(PaymentRequestInterface $paymentRequest): bool; } From e4cbd6b46ad01c457eae49df461c2654709c36d1 Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Wed, 25 Sep 2024 13:42:48 +0200 Subject: [PATCH 192/200] [Admin][PaymentRequest] Add behat tests --- .../browsing_payment_requests.feature | 25 +++ .../filtering_payment_requests.feature | 46 ++++++ .../seeing_payment_request_details.feature | 23 +++ ...nt_method_after_order_confirmation.feature | 2 +- src/Sylius/Behat/Client/ApiPlatformClient.php | 6 +- .../Admin/ManagingPaymentRequestsContext.php | 156 ++++++++++++++++++ .../Api/Admin/ManagingPaymentsContext.php | 14 ++ .../Api/Shop/PaymentRequestContext.php | 3 +- .../Behat/Context/Setup/PaymentContext.php | 24 +-- .../Context/Setup/PaymentRequestContext.php | 45 +++++ .../Admin/ManagingPaymentRequestsContext.php | 132 +++++++++++++++ .../Ui/Admin/ManagingPaymentsContext.php | 8 + .../Behat/Page/Admin/Payment/IndexPage.php | 11 ++ .../Page/Admin/Payment/IndexPageInterface.php | 2 + .../Payment/PaymentRequest/IndexPage.php | 74 +++++++++ .../PaymentRequest/IndexPageInterface.php | 26 +++ .../Admin/Payment/PaymentRequest/ShowPage.php | 40 +++++ .../PaymentRequest/ShowPageInterface.php | 21 +++ .../config/services/contexts/api/admin.xml | 7 + .../config/services/contexts/api/shop.xml | 1 - .../config/services/contexts/setup.xml | 5 +- .../Resources/config/services/contexts/ui.xml | 6 + .../config/services/pages/admin/payment.xml | 18 ++ .../suites/api/payment/managing_payments.yml | 3 + .../suites/ui/payment/managing_payments.yml | 2 + .../get_payment_requests_for_payment.json | 45 ++++- 26 files changed, 718 insertions(+), 27 deletions(-) create mode 100644 features/admin/payment/managing_payments/payment_request/browsing_payment_requests.feature create mode 100644 features/admin/payment/managing_payments/payment_request/filtering_payment_requests.feature create mode 100644 features/admin/payment/managing_payments/payment_request/seeing_payment_request_details.feature create mode 100644 src/Sylius/Behat/Context/Api/Admin/ManagingPaymentRequestsContext.php create mode 100644 src/Sylius/Behat/Context/Setup/PaymentRequestContext.php create mode 100644 src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php create mode 100644 src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPage.php create mode 100644 src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPageInterface.php create mode 100644 src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/ShowPage.php create mode 100644 src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/ShowPageInterface.php diff --git a/features/admin/payment/managing_payments/payment_request/browsing_payment_requests.feature b/features/admin/payment/managing_payments/payment_request/browsing_payment_requests.feature new file mode 100644 index 0000000000..3b53205378 --- /dev/null +++ b/features/admin/payment/managing_payments/payment_request/browsing_payment_requests.feature @@ -0,0 +1,25 @@ +@managing_payments +Feature: Browsing payment requests + In order to have an overview of all payment requests of a specific payment + As an Administrator + I want to browse all payment requests of a payment + + Background: + Given the store operates on a single channel in "United States" + And the store has a product "PHP T-Shirt" + And the store ships everywhere for Free + And the store allows paying with "Cash on Delivery" + And there is an "#00000001" order with "PHP T-Shirt" product + And the payment request action "authorize" has been executed for order "#00000001" with the payment method "Cash on Delivery" + And the payment request action "capture" has been executed for order "#00000001" with the payment method "Cash on Delivery" + And the payment request action "sync" has been executed for order "#00000001" with the payment method "Cash on Delivery" + And I am logged in as an administrator + + @api @ui + Scenario: Browsing payment requests of a payment + When I browse payments + And I want to view the payment request of the first payment + Then there should be 3 payment requests on the list + And it should be the payment request with action "authorize" + And it should be the payment request with action "capture" + And it should be the payment request with action "sync" diff --git a/features/admin/payment/managing_payments/payment_request/filtering_payment_requests.feature b/features/admin/payment/managing_payments/payment_request/filtering_payment_requests.feature new file mode 100644 index 0000000000..444c4d18d0 --- /dev/null +++ b/features/admin/payment/managing_payments/payment_request/filtering_payment_requests.feature @@ -0,0 +1,46 @@ +@managing_payments +Feature: Filtering payment requests + In order to see specific payment requests + As an Administrator + I want to be able to filter payment requests on the list + + Background: + Given the store operates on a single channel in "United States" + And the store has a product "PHP T-Shirt" + And the store ships everywhere for Free + And the store allows paying with "Cash on Delivery" + And the store allows paying with "Credit Card" + And there is an "#00000001" order with "PHP T-Shirt" product + And there is an "#00000002" order with "PHP T-Shirt" product + And the payment request action "authorize" has been executed for order "#00000001" with the payment method "Credit Card" + And the payment request action "authorize" has been executed for order "#00000001" with the payment method "Cash on Delivery" + And the payment request action "capture" has been executed for order "#00000001" with the payment method "Cash on Delivery" + And the payment request action "sync" has been executed for order "#00000001" with the payment method "Cash on Delivery" + And the payment request action "capture" has been executed for order "#00000002" with the payment method "Cash on Delivery" + And I am logged in as an administrator + + @api @ui + Scenario: Filtering payment requests by action + When I browse payment requests of an order "#00000001" + And I filter by the "capture" action + Then there should be 1 payment request on the list + And it should be the payment request with action "capture" + + @api @ui @mink:chromedriver + Scenario: Filtering payment requests by payment method + When I browse payment requests of an order "#00000001" + And I filter by the "Credit Card" payment method + Then there should be 1 payment request on the list + And it should be the payment request with payment method "Credit Card" + + @api @ui + Scenario: Filtering payment requests by state "New" + When I browse payment requests of an order "#00000001" + And I filter by the "new" state + Then there should be 4 payment requests on the list + + @api @ui + Scenario: Filtering payment requests by state "Completed" + When I browse payment requests of an order "#00000001" + And I filter by the "completed" state + Then there should be 0 payment request on the list diff --git a/features/admin/payment/managing_payments/payment_request/seeing_payment_request_details.feature b/features/admin/payment/managing_payments/payment_request/seeing_payment_request_details.feature new file mode 100644 index 0000000000..f51af8331a --- /dev/null +++ b/features/admin/payment/managing_payments/payment_request/seeing_payment_request_details.feature @@ -0,0 +1,23 @@ +@managing_payments +Feature: Seeing payment request details + In order to have an overview of one of payment requests + As an Administrator + I want to be able to see its details + + Background: + Given the store operates on a single channel in "United States" + And the store has a product "PHP T-Shirt" + And the store ships everywhere for Free + And the store allows paying with "Cash on Delivery" + And there is an "#00000001" order with "PHP T-Shirt" product + And the payment request action "authorize" has been executed for order "#00000001" with the payment method "Cash on Delivery" + And I am logged in as an administrator + + @api @ui + Scenario: Seeing payment request's details + When I view details of the payment request for the "#00000001" order + Then its method should be "Cash on Delivery" + And its action should be "Authorize" + And its state should be "New" + And its payload should has empty value + And its response data should has empty value diff --git a/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature b/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature index e27714f35c..1c5517809d 100644 --- a/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature +++ b/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature @@ -21,7 +21,7 @@ Feature: Changing the offline payment method after order confirmation And I retry the payment with "Offline" payment method Then I should have chosen "Offline" payment method - @api @ui @javascript + @api Scenario: Retrying the payment with different Offline payment works correctly together with inventory Given there is 1 unit of product "PHP T-Shirt" available in the inventory And this product is tracked by the inventory diff --git a/src/Sylius/Behat/Client/ApiPlatformClient.php b/src/Sylius/Behat/Client/ApiPlatformClient.php index a93447efe2..32833811e2 100644 --- a/src/Sylius/Behat/Client/ApiPlatformClient.php +++ b/src/Sylius/Behat/Client/ApiPlatformClient.php @@ -55,10 +55,10 @@ final class ApiPlatformClient implements ApiClientInterface /** @param array $queryParameters */ public function subResourceIndex(string $resource, string $subResource, string $id, array $queryParameters = [], bool $forgetResponse = false): Response { - $request = $this->requestFactory->subResourceIndex($this->section, $resource, $id, $subResource, $queryParameters); - $request->authorize($this->getToken(), $this->authorizationHeader); + $this->request = $this->requestFactory->subResourceIndex($this->section, $resource, $id, $subResource, $queryParameters); + $this->request->authorize($this->getToken(), $this->authorizationHeader); - return $this->request($request, $forgetResponse); + return $this->request($this->request, $forgetResponse); } public function show(string $resource, string $id, bool $forgetResponse = false): Response diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentRequestsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentRequestsContext.php new file mode 100644 index 0000000000..7fcded27b0 --- /dev/null +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentRequestsContext.php @@ -0,0 +1,156 @@ +client->subResourceIndex( + Resources::PAYMENTS, + Resources::PAYMENT_REQUESTS, + (string) $order->getLastPayment()->getId() + ); + } + + /** + * @When I view details of the payment request for the :order order + */ + public function iViewDetailsOfThePaymentRequestForTheOrder(OrderInterface $order): void + { + $paymentRequest = $this->paymentRequestRepository->findOneBy(['payment' => $order->getLastPayment()]); + + $this->client->show(Resources::PAYMENT_REQUESTS, (string) $paymentRequest->getHash()); + } + + /** + * @When I filter by the :action action + */ + public function iFilterByTheAction(string $action): void + { + $this->client->addFilter('action', $action); + $this->client->filter(); + } + + /** + * @When I filter by the :paymentMethod payment method + */ + public function iFilterByThePaymentMethod(PaymentMethodInterface $paymentMethod): void + { + $this->client->addFilter('method.code', $paymentMethod->getCode()); + $this->client->filter(); + } + + /** + * @When I filter by the :state state + */ + public function iFilterByTheState(string $state): void + { + $this->client->addFilter('state', $state); + $this->client->filter(); + } + + /** + * @Then /^there should be (\d+) payment requests? on the list$/ + */ + public function thereShouldBeProductVariantsOnTheList(int $count): void + { + Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), $count); + } + + /** + * @Then it should be the payment request with action :action + */ + public function itShouldBeThePaymentRequestWithAction(string $action): void + { + Assert::true($this->responseChecker->hasItemWithValue($this->client->getLastResponse(), 'action', $action)); + } + + /** + * @Then it should be the payment request with payment method :paymentMethod + */ + public function itShouldBeThePaymentRequestWithPaymentMethod(PaymentMethodInterface $paymentMethod): void + { + Assert::true( + $this->responseChecker->hasItemWithValue( + $this->client->getLastResponse(), + 'method', + $this->iriConverter->getIriFromResourceInSection($paymentMethod, 'admin'), + ), + ); + } + + /** + * @Then its method should be :paymentMethod + */ + public function itsMethodShouldBe(PaymentMethodInterface $paymentMethod): void + { + Assert::true($this->responseChecker->hasValue( + $this->client->getLastResponse(), + 'method', + $this->iriConverter->getIriFromResourceInSection($paymentMethod, 'admin')) + ); + } + + /** + * @Then /^its (action|state) should be "([^"]+)"$/ + */ + public function itsActionStateShouldBe(string $field, string $value): void + { + Assert::true($this->responseChecker->hasValue($this->client->getLastResponse(), $field, strtolower($value))); + } + + /** + * @Then its payload should has empty value + */ + public function itsPayloadShouldHasEmptyValue(): void + { + Assert::isEmpty($this->responseChecker->getValue($this->client->getLastResponse(), 'payload')); + } + + /** + * @Then its response data should has empty value + */ + public function itsResponseDataShouldHasEmptyValue(): void + { + Assert::isEmpty($this->responseChecker->getValue($this->client->getLastResponse(), 'responseData')); + } + +} diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentsContext.php index d79eb9302a..8175dde7a4 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentsContext.php @@ -58,6 +58,20 @@ final readonly class ManagingPaymentsContext implements Context $this->client->customItemAction(Resources::ORDERS, $order->getTokenValue(), HttpRequest::METHOD_GET, 'payments'); } + /** + * @When I want to view the payment request of the first payment + */ + public function iWantToViewThePaymentRequestOfTheFirstPayment(): void + { + $response = $this->client->getLastResponse(); + + $this->client->subResourceIndex( + Resources::PAYMENTS, + Resources::PAYMENT_REQUESTS, + (string) $this->responseChecker->getCollection($response)[0]['id'] + ); + } + /** * @Then I should see the details of order :order */ diff --git a/src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php b/src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php index 2b42fc164e..e8cae881e5 100644 --- a/src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php @@ -15,14 +15,13 @@ use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; use Symfony\Component\HttpFoundation\Request as HTTPRequest; -final class PaymentRequestContext implements Context +final readonly class PaymentRequestContext implements Context { public function __construct( private SharedStorageInterface $sharedStorage, private ApiClientInterface $client, private ResponseCheckerInterface $responseChecker, private RequestFactoryInterface $requestFactory, - private PaymentMethodRepositoryInterface $paymentMethodRepository, ) { } diff --git a/src/Sylius/Behat/Context/Setup/PaymentContext.php b/src/Sylius/Behat/Context/Setup/PaymentContext.php index 9a7fe0dd2e..2de4188c42 100644 --- a/src/Sylius/Behat/Context/Setup/PaymentContext.php +++ b/src/Sylius/Behat/Context/Setup/PaymentContext.php @@ -20,12 +20,10 @@ use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; use Sylius\Component\Core\Formatter\StringInflector; use Sylius\Component\Core\Model\ChannelInterface; -use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Payment\Model\PaymentMethodTranslationInterface; use Sylius\Component\Payment\Repository\PaymentMethodRepositoryInterface; use Sylius\Resource\Factory\FactoryInterface; -use Webmozart\Assert\Assert; final readonly class PaymentContext implements Context { @@ -72,7 +70,7 @@ final readonly class PaymentContext implements Context /** * @Given /^the store allows paying (\w+) for (all channels)$/ */ - public function storeAllowsPayingForAllChannels($paymentMethodName, array $channels) + public function storeAllowsPayingForAllChannels($paymentMethodName, array $channels): void { $paymentMethod = $this->createPaymentMethod($paymentMethodName, StringInflector::nameToUppercaseCode($paymentMethodName), 'Offline', 'Payment method', false); @@ -92,7 +90,7 @@ final readonly class PaymentContext implements Context /** * @Given /^(this payment method) is named "([^"]+)" in the "([^"]+)" locale$/ */ - public function thisPaymentMethodIsNamedIn(PaymentMethodInterface $paymentMethod, $name, $locale) + public function thisPaymentMethodIsNamedIn(PaymentMethodInterface $paymentMethod, $name, $locale): void { /** @var PaymentMethodTranslationInterface $translation */ $translation = $this->paymentMethodTranslationFactory->createNew(); @@ -109,7 +107,7 @@ final readonly class PaymentContext implements Context * @Given /^(this payment method) (?:has been|is) disabled$/ * @When the payment method :paymentMethod gets disabled */ - public function theStoreHasAPaymentMethodDisabled(PaymentMethodInterface $paymentMethod) + public function theStoreHasAPaymentMethodDisabled(PaymentMethodInterface $paymentMethod): void { $paymentMethod->disable(); @@ -119,7 +117,7 @@ final readonly class PaymentContext implements Context /** * @Given /^(it) has instructions "([^"]+)"$/ */ - public function itHasInstructions(PaymentMethodInterface $paymentMethod, $instructions) + public function itHasInstructions(PaymentMethodInterface $paymentMethod, $instructions): void { $paymentMethod->setInstructions($instructions); @@ -129,7 +127,7 @@ final readonly class PaymentContext implements Context /** * @Given the store has :paymentMethodName payment method not assigned to any channel */ - public function theStoreHasPaymentMethodNotAssignedToAnyChannel($paymentMethodName) + public function theStoreHasPaymentMethodNotAssignedToAnyChannel($paymentMethodName): void { $this->createPaymentMethod($paymentMethodName, 'PM_' . $paymentMethodName, 'Offline', 'Payment method', false); } @@ -137,7 +135,7 @@ final readonly class PaymentContext implements Context /** * @Given the payment method :paymentMethod requires authorization before capturing */ - public function thePaymentMethodRequiresAuthorizationBeforeCapturing(PaymentMethodInterface $paymentMethod) + public function thePaymentMethodRequiresAuthorizationBeforeCapturing(PaymentMethodInterface $paymentMethod): void { /** @var GatewayConfigInterface $config */ $config = $paymentMethod->getGatewayConfig(); @@ -163,16 +161,6 @@ final readonly class PaymentContext implements Context $paymentMethod->addChannel($channel); } - /** - * @Then /^the (latest order) should have a payment with state "([^"]+)"$/ - */ - public function theLatestOrderHasAuthorizedPayment(OrderInterface $order, string $state) - { - $payment = $order->getLastPayment(); - - Assert::eq($payment->getState(), $state); - } - private function createPaymentMethod( string $name, string $code, diff --git a/src/Sylius/Behat/Context/Setup/PaymentRequestContext.php b/src/Sylius/Behat/Context/Setup/PaymentRequestContext.php new file mode 100644 index 0000000000..652a7becd0 --- /dev/null +++ b/src/Sylius/Behat/Context/Setup/PaymentRequestContext.php @@ -0,0 +1,45 @@ +getLastPayment()->getId(), + paymentMethodCode: $paymentMethod->getCode(), + action: $action, + ); + + $this->commandBus->dispatch($addPaymentRequest); + } +} diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php new file mode 100644 index 0000000000..95aec44a99 --- /dev/null +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php @@ -0,0 +1,132 @@ +indexPage->open(['id' => $order->getLastPayment()->getId()]); + } + + /** + * @When I view details of the payment request for the :order order + */ + public function iViewDetailsOfThePaymentRequestForTheOrder(OrderInterface $order): void + { + $payment = $order->getLastPayment(); + $paymentRequest = $this->paymentRequestRepository->findOneBy(['payment' => $payment]); + + $this->showPage->open([ + 'hash' => $paymentRequest->getHash(), + 'paymentId' => $payment->getId() + ]); + } + + /** + * @When I filter by the :action action + */ + public function iFilterByTheAction(string $action): void + { + $this->indexPage->chooseActionToFilter($action); + $this->indexPage->filter(); + } + + /** + * @When I filter by the :paymentMethod payment method + */ + public function iFilterByThePaymentMethod(PaymentMethodInterface $paymentMethod): void + { + $this->indexPage->choosePaymentMethodToFilter($paymentMethod->getName()); + $this->indexPage->filter(); + } + + /** + * @When I filter by the :state state + */ + public function iFilterByTheState(string $state): void + { + $this->indexPage->chooseStateToFilter($state); + $this->indexPage->filter(); + } + + /** + * @Then /^there should be (\d+) payment requests? on the list$/ + */ + public function thereShouldBeProductVariantsOnTheList(int $count): void + { + Assert::same( + $this->indexPage->countItems(), + $count, + ); + } + + /** + * @Then it should be the payment request with action :action + */ + public function itShouldBeThePaymentRequestWithAction(string $action): void + { + Assert::true($this->indexPage->isSingleResourceOnPage(['action' => $action])); + } + + /** + * @Then it should be the payment request with payment method :paymentMethod + */ + public function itShouldBeThePaymentRequestWithPaymentMethod(PaymentMethodInterface $paymentMethod): void + { + Assert::true($this->indexPage->isSingleResourceOnPage(['method' => $paymentMethod->getName()])); + } + + /** + * @Then its :field should be :value + */ + public function itsFieldShouldBe(string $field, string $value): void + { + Assert::same($this->showPage->getFieldText($field), $value); + } + + /** + * @Then its payload should has empty value + */ + public function itsPayloadShouldHasEmptyValue(): void + { + Assert::same($this->showPage->getFieldText('payload'), 'null'); + } + + /** + * @Then its response data should has empty value + */ + public function itsResponseDataShouldBe(): void + { + Assert::same($this->showPage->getFieldText('response_data'), json_encode([])); + } +} diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentsContext.php index 3effca2332..e9cf67042b 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentsContext.php @@ -80,6 +80,14 @@ final class ManagingPaymentsContext implements Context $this->indexPage->chooseChannelFilter($channelName); } + /** + * @When I want to view the payment request of the first payment + */ + public function iWantToViewThePaymentRequestOfTheFirstPayment(): void + { + $this->indexPage->showPaymentRequestOfNthPayment(1); + } + /** * @Then I should see :count payments in the list * @Then I should see a single payment in the list diff --git a/src/Sylius/Behat/Page/Admin/Payment/IndexPage.php b/src/Sylius/Behat/Page/Admin/Payment/IndexPage.php index 0a2d7bef50..a62f87753a 100644 --- a/src/Sylius/Behat/Page/Admin/Payment/IndexPage.php +++ b/src/Sylius/Behat/Page/Admin/Payment/IndexPage.php @@ -48,6 +48,17 @@ class IndexPage extends BaseIndexPage implements IndexPageInterface $this->getOrderLinkForRow($position)->clickLink('#'); } + public function showPaymentRequestOfNthPayment(int $position): void + { + $tableAccessor = $this->getTableAccessor(); + $table = $this->getElement('table'); + + $row = $tableAccessor->getRowsWithFields($table, [])[$position]; + $field = $tableAccessor->getFieldFromRow($table, $row, 'actions'); + + $field->find('css', '[data-test-show-action="List payment requests"]')->click(); + } + public function chooseChannelFilter(string $channelName): void { $this->getElement('filter_channel')->selectOption($channelName); diff --git a/src/Sylius/Behat/Page/Admin/Payment/IndexPageInterface.php b/src/Sylius/Behat/Page/Admin/Payment/IndexPageInterface.php index d02b24a266..e7f3ec27c0 100644 --- a/src/Sylius/Behat/Page/Admin/Payment/IndexPageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Payment/IndexPageInterface.php @@ -27,5 +27,7 @@ interface IndexPageInterface extends BaseIndexPageInterface public function showOrderPageForNthPayment(int $position): void; + public function showPaymentRequestOfNthPayment(int $position): void; + public function chooseChannelFilter(string $channelName): void; } diff --git a/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPage.php b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPage.php new file mode 100644 index 0000000000..3ac6d0a016 --- /dev/null +++ b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPage.php @@ -0,0 +1,74 @@ +specifyAutocompleteFilter($this->getElement('filter_payment_method'), $paymentMethodName); + } + + public function chooseActionToFilter(string $action): void + { + $this->getElement('filter_action')->selectOption($action); + } + + public function chooseStateToFilter(string $state): void + { + $this->getElement('filter_state')->selectOption($state); + } + + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + 'filter_action' => '#criteria_action', + 'filter_payment_method' => '#criteria_payment_method', + 'filter_state' => '#criteria_state', + ]); + } + + private function specifyAutocompleteFilter(NodeElement $autocomplete, string $value): void + { + if (!$this->areFiltersVisible()) { + $this->toggleFilters(); + } + + $this->autocompleteHelper->selectByName( + $this->getDriver(), + $autocomplete->getXpath(), + $value, + ); + + $this->waitForFormUpdate(); + } +} diff --git a/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPageInterface.php b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPageInterface.php new file mode 100644 index 0000000000..348607d720 --- /dev/null +++ b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPageInterface.php @@ -0,0 +1,26 @@ +getElement($fieldName)->getText(); + } + + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + 'action' => '[data-test-action]', + 'method' => '[data-test-method]', + 'payload' => '[data-test-payload]', + 'response_data' => '[data-test-response-data]', + 'state' => '[data-test-state]', + ]); + } +} diff --git a/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/ShowPageInterface.php b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/ShowPageInterface.php new file mode 100644 index 0000000000..61e2309546 --- /dev/null +++ b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/ShowPageInterface.php @@ -0,0 +1,21 @@ + + + + + + + + diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml index 6fe24f8604..8591a4a31d 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml @@ -166,7 +166,6 @@ - diff --git a/src/Sylius/Behat/Resources/config/services/contexts/setup.xml b/src/Sylius/Behat/Resources/config/services/contexts/setup.xml index 4738917e42..6827a6e528 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/setup.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/setup.xml @@ -142,7 +142,6 @@ Offline - @@ -320,5 +319,9 @@ + + + + diff --git a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml index 29ad8a5557..9d737355d2 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml @@ -613,5 +613,11 @@ + + + + + + diff --git a/src/Sylius/Behat/Resources/config/services/pages/admin/payment.xml b/src/Sylius/Behat/Resources/config/services/pages/admin/payment.xml index 6aa10f4483..415f7382a4 100644 --- a/src/Sylius/Behat/Resources/config/services/pages/admin/payment.xml +++ b/src/Sylius/Behat/Resources/config/services/pages/admin/payment.xml @@ -14,6 +14,8 @@ Sylius\Behat\Page\Admin\Payment\IndexPage + Sylius\Behat\Page\Admin\Payment\PaymentRequest\IndexPage + Sylius\Behat\Page\Admin\Payment\PaymentRequest\ShowPage @@ -22,5 +24,21 @@ sylius_admin_payment_index + + + sylius_admin_payment_payment_request_index + + + + + diff --git a/src/Sylius/Behat/Resources/config/suites/api/payment/managing_payments.yml b/src/Sylius/Behat/Resources/config/suites/api/payment/managing_payments.yml index 0df135235c..38f71963a6 100644 --- a/src/Sylius/Behat/Resources/config/suites/api/payment/managing_payments.yml +++ b/src/Sylius/Behat/Resources/config/suites/api/payment/managing_payments.yml @@ -11,6 +11,7 @@ default: - sylius.behat.context.transform.customer - sylius.behat.context.transform.lexical - sylius.behat.context.transform.order + - sylius.behat.context.transform.payment - sylius.behat.context.transform.product - sylius.behat.context.transform.shared_storage @@ -18,10 +19,12 @@ default: - sylius.behat.context.setup.channel - sylius.behat.context.setup.order - sylius.behat.context.setup.payment + - sylius.behat.context.setup.payment_request - sylius.behat.context.setup.product - sylius.behat.context.setup.shipping - sylius.behat.context.api.admin.managing_payments + - sylius.behat.context.api.admin.managing_payment_requests filters: tags: "@managing_payments&&@api" diff --git a/src/Sylius/Behat/Resources/config/suites/ui/payment/managing_payments.yml b/src/Sylius/Behat/Resources/config/suites/ui/payment/managing_payments.yml index 20797a92d1..b8bd2d9a81 100644 --- a/src/Sylius/Behat/Resources/config/suites/ui/payment/managing_payments.yml +++ b/src/Sylius/Behat/Resources/config/suites/ui/payment/managing_payments.yml @@ -23,6 +23,7 @@ default: - sylius.behat.context.setup.geographical - sylius.behat.context.setup.order - sylius.behat.context.setup.payment + - sylius.behat.context.setup.payment_request - sylius.behat.context.setup.product - sylius.behat.context.setup.shipping - sylius.behat.context.setup.zone @@ -30,6 +31,7 @@ default: - sylius.behat.context.ui.email - sylius.behat.context.ui.admin.managing_payments + - sylius.behat.context.ui.admin.managing_payment_requests - sylius.behat.context.ui.shop.cart filters: tags: "@managing_payments&&@ui" diff --git a/tests/Api/Responses/admin/payment_request/get_payment_requests_for_payment.json b/tests/Api/Responses/admin/payment_request/get_payment_requests_for_payment.json index 3f3ebee59c..a242e65a17 100644 --- a/tests/Api/Responses/admin/payment_request/get_payment_requests_for_payment.json +++ b/tests/Api/Responses/admin/payment_request/get_payment_requests_for_payment.json @@ -2,6 +2,7 @@ "@context": "\/api\/v2\/contexts\/PaymentRequest", "@id": "\/api\/v2\/admin\/payments\/@integer@\/payment-requests", "@type": "hydra:Collection", + "hydra:totalItems": 3, "hydra:member": [ { "@id": "\/api\/v2\/admin\/payment-requests\/@string@", @@ -31,5 +32,47 @@ "method": "\/api\/v2\/admin\/payment-methods\/CASH_ON_DELIVERY" } ], - "hydra:totalItems": 3 + "hydra:search": { + "@type": "hydra:IriTemplate", + "hydra:template": "\/api\/v2\/admin\/payments\/@integer@\/payment-requests{?action,action[],method.code,method.code[],state,state[]}", + "hydra:variableRepresentation": "BasicRepresentation", + "hydra:mapping": [ + { + "@type": "IriTemplateMapping", + "variable": "action", + "property": "action", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "action[]", + "property": "action", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "method.code", + "property": "method.code", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "method.code[]", + "property": "method.code", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "state", + "property": "state", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "state[]", + "property": "state", + "required": false + } + ] + } } From 6ea219dd8eddec902a4835f416eb96879d3d8bdf Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Wed, 25 Sep 2024 13:45:17 +0200 Subject: [PATCH 193/200] Mirror improvement --- ...ging_offline_payment_method_after_order_confirmation.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature b/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature index 1c5517809d..e27714f35c 100644 --- a/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature +++ b/features/shop/checkout/paying_for_order/changing_offline_payment_method_after_order_confirmation.feature @@ -21,7 +21,7 @@ Feature: Changing the offline payment method after order confirmation And I retry the payment with "Offline" payment method Then I should have chosen "Offline" payment method - @api + @api @ui @javascript Scenario: Retrying the payment with different Offline payment works correctly together with inventory Given there is 1 unit of product "PHP T-Shirt" available in the inventory And this product is tracked by the inventory From 619bb4cfa69911ee52cb0ecea6021b86f3f4394b Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Wed, 25 Sep 2024 13:57:11 +0200 Subject: [PATCH 194/200] Fix AddPaymentRequest --- .../Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php index 42a6a16d87..fce0e32116 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php +++ b/src/Sylius/Bundle/ApiBundle/Command/Payment/AddPaymentRequest.php @@ -18,7 +18,7 @@ use Sylius\Bundle\ApiBundle\Command\IriToIdentifierConversionAwareInterface; class AddPaymentRequest implements IriToIdentifierConversionAwareInterface { public function __construct( - public readonly mixed $paymentId, + public readonly int|string $paymentId, public readonly string $paymentMethodCode, public readonly ?string $action = null, public readonly mixed $payload = null, From 01fa7911090eec843ae0a62a12f4655971ec3347 Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Thu, 26 Sep 2024 08:31:12 +0200 Subject: [PATCH 195/200] Move payment request routes to separate file --- .../Resources/config/grids/payment.yml | 2 +- .../AdminBundle/Resources/config/routing.yml | 4 +++ .../Resources/config/routing/payment.yml | 26 ------------------- .../config/routing/payment_request.yaml | 25 ++++++++++++++++++ .../actions/list_payment_requests.html.twig | 2 +- .../show/content/header/breadcrumbs.html.twig | 2 +- .../Announcer/PaymentRequestAnnouncer.php | 4 +-- 7 files changed, 33 insertions(+), 32 deletions(-) create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment_request.yaml diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml index da8938a081..d154262af3 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml @@ -77,7 +77,7 @@ sylius_grid: link: route: sylius_admin_payment_payment_request_index parameters: - id: resource.id + paymentId: resource.id complete: type: apply_transition label: sylius.ui.complete diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing.yml index 63c11f29fc..f6d439d180 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing.yml @@ -53,6 +53,10 @@ sylius_admin_payment: sylius_admin_payment_method: resource: "@SyliusAdminBundle/Resources/config/routing/payment_method.yml" +sylius_admin_payment_request: + resource: "@SyliusAdminBundle/Resources/config/routing/payment_request.yaml" + prefix: /payments/{paymentId}/payment-requests/ + sylius_admin_product: resource: "@SyliusAdminBundle/Resources/config/routing/product.yml" diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment.yml index 1cf8a99c7d..7836913aa2 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment.yml @@ -27,29 +27,3 @@ sylius_admin_payment_complete: transition: complete redirect: sylius_admin_payment_index flash: sylius.payment.completed - -sylius_admin_payment_payment_request_index: - path: /payments/{id}/payment_requests - methods: [GET] - defaults: - _controller: sylius.controller.payment_request::indexAction - _sylius: - section: admin - permission: true - template: "@SyliusAdmin/payment/payment_request/index.html.twig" - grid: sylius_admin_payment_payment_request - -sylius_admin_payment_payment_request_show: - path: /payments/{paymentId}/payment_requests/{hash} - methods: [GET] - defaults: - _controller: sylius.controller.payment_request::showAction - _sylius: - section: admin - permission: true - template: "@SyliusAdmin/payment/payment_request/show.html.twig" - repository: - method: findOneByPaymentId - arguments: - hash: $hash - paymentId: $paymentId diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment_request.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment_request.yaml new file mode 100644 index 0000000000..d627e4e3f4 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment_request.yaml @@ -0,0 +1,25 @@ +sylius_admin_payment_payment_request_index: + path: / + methods: [GET] + defaults: + _controller: sylius.controller.payment_request::indexAction + _sylius: + section: admin + permission: true + template: "@SyliusAdmin/payment/payment_request/index.html.twig" + grid: sylius_admin_payment_payment_request + +sylius_admin_payment_payment_request_show: + path: /{hash} + methods: [GET] + defaults: + _controller: sylius.controller.payment_request::showAction + _sylius: + section: admin + permission: true + template: "@SyliusAdmin/payment/payment_request/show.html.twig" + repository: + method: findOneByPaymentId + arguments: + hash: $hash + paymentId: $paymentId diff --git a/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig b/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig index 35b236f598..1ef5f85c2e 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig @@ -2,6 +2,6 @@ {% set payment = hookable_metadata.context.payment %} - + {{ icon({ icon: 'list_letters', class: 'icon icon-tabler' }) }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig index 4dfdab9d99..48ecd8d00c 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig @@ -7,6 +7,6 @@ { name: 'sylius.ui.dashboard', url: path('sylius_admin_dashboard'), active: false }, { name: 'sylius.ui.payments'|trans, url: path('sylius_admin_payment_index'), active: false }, { name: payment_id, active: false }, - { name: 'sylius.ui.payment_requests'|trans, url: path('sylius_admin_payment_payment_request_index', {'id': payment_id}), active: false }, + { name: 'sylius.ui.payment_requests'|trans, url: path('sylius_admin_payment_payment_request_index', {'paymentId': payment_id}), active: false }, { name: payment_request.hash, active: true }, ]) }} diff --git a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php index e54a7aa93b..8b68a35743 100644 --- a/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php +++ b/src/Sylius/Bundle/CoreBundle/PaymentRequest/Announcer/PaymentRequestAnnouncer.php @@ -13,13 +13,11 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\PaymentRequest\Announcer; -use Sylius\Bundle\CoreBundle\Command\Admin\Account\RequestResetPasswordEmail; -use Sylius\Bundle\CoreBundle\Command\CapturePaymentRequest; use Sylius\Bundle\CoreBundle\PaymentRequest\CommandProvider\PaymentRequestCommandProviderInterface; use Sylius\Component\Payment\Model\PaymentRequestInterface; use Symfony\Component\Messenger\MessageBusInterface; -final class PaymentRequestAnnouncer implements PaymentRequestAnnouncerInterface +final readonly class PaymentRequestAnnouncer implements PaymentRequestAnnouncerInterface { public function __construct( private PaymentRequestCommandProviderInterface $paymentRequestCommandProvider, From 43e935ee8257a63b27891e64729bdfe7e343d9c6 Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Thu, 26 Sep 2024 08:31:49 +0200 Subject: [PATCH 196/200] [PaymentRequest] Use constants in grid --- ...ayment.yml => payment_payment_request.yml} | 30 +++++++++---------- .../Doctrine/ORM/PaymentRequestRepository.php | 2 +- .../PaymentRequestRepositoryInterface.php | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) rename src/Sylius/Bundle/AdminBundle/Resources/config/grids/{payment_request_payment.yml => payment_payment_request.yml} (64%) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request_payment.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_payment_request.yml similarity index 64% rename from src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request_payment.yml rename to src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_payment_request.yml index 0193850f42..26ca780b22 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request_payment.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_payment_request.yml @@ -6,9 +6,9 @@ sylius_grid: options: class: "%sylius.model.payment_request.class%" repository: - method: createForPaymentQueryBuilder + method: createQueryBuilderForPayment arguments: - paymentId: $id + paymentId: $paymentId sorting: createdAt: desc fields: @@ -63,24 +63,24 @@ sylius_grid: type: select label: sylius.ui.action form_options: - choices: - sylius.ui.authorize: authorize - sylius.ui.cancel: cancel - sylius.ui.capture: capture - sylius.ui.payout: payout - sylius.ui.refund: refund - sylius.ui.status: status - sylius.ui.sync: sync + choices: + sylius.ui.authorize: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::ACTION_AUTHORIZE + sylius.ui.cancel: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::ACTION_CANCEL + sylius.ui.capture: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::ACTION_CAPTURE + sylius.ui.payout: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::ACTION_PAYOUT + sylius.ui.refund: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::ACTION_REFUND + sylius.ui.status: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::ACTION_STATUS + sylius.ui.sync: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::ACTION_SYNC state: type: select label: sylius.ui.state form_options: choices: - sylius.ui.cancelled: cancelled - sylius.ui.completed: completed - sylius.ui.failed: failed - sylius.ui.new: new - sylius.ui.processing: processing + sylius.ui.cancelled: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::STATE_CANCELLED + sylius.ui.completed: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::STATE_COMPLETED + sylius.ui.failed: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::STATE_FAILED + sylius.ui.new: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::STATE_NEW + sylius.ui.processing: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::STATE_PROCESSING actions: item: show: diff --git a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php index 58e0c255d4..1b1711c4f4 100644 --- a/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php +++ b/src/Sylius/Bundle/PaymentBundle/Doctrine/ORM/PaymentRequestRepository.php @@ -40,7 +40,7 @@ class PaymentRequestRepository extends EntityRepository implements PaymentReques ; } - public function createForPaymentQueryBuilder(string $paymentId): QueryBuilder + public function createQueryBuilderForPayment(string $paymentId): QueryBuilder { $queryBuilder = $this->createQueryBuilder('o'); $queryBuilder diff --git a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php index a3f7887948..de63cb8da8 100644 --- a/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php +++ b/src/Sylius/Component/Payment/Repository/PaymentRequestRepositoryInterface.php @@ -26,7 +26,7 @@ interface PaymentRequestRepositoryInterface extends RepositoryInterface { public function findOneByPaymentId(mixed $hash, mixed $paymentId): ?PaymentRequestInterface; - public function createForPaymentQueryBuilder(string $paymentId): QueryBuilder; + public function createQueryBuilderForPayment(string $paymentId): QueryBuilder; public function duplicateExists(PaymentRequestInterface $paymentRequest): bool; } From cda6fcf1d925c84608e20e3da0ed208084a077fd Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Thu, 26 Sep 2024 09:08:03 +0200 Subject: [PATCH 197/200] [PaymentBundle] Add symfony/doctrine-bridge --- .../Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php | 2 +- src/Sylius/Bundle/PaymentBundle/composer.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php index 95aec44a99..22e7ee7245 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php @@ -35,7 +35,7 @@ final readonly class ManagingPaymentRequestsContext implements Context */ public function iBrowseOrdersOfACustomer(OrderInterface $order): void { - $this->indexPage->open(['id' => $order->getLastPayment()->getId()]); + $this->indexPage->open(['paymentId' => $order->getLastPayment()->getId()]); } /** diff --git a/src/Sylius/Bundle/PaymentBundle/composer.json b/src/Sylius/Bundle/PaymentBundle/composer.json index f7d5272f99..63afad1961 100644 --- a/src/Sylius/Bundle/PaymentBundle/composer.json +++ b/src/Sylius/Bundle/PaymentBundle/composer.json @@ -29,6 +29,7 @@ "php": "^8.2", "sylius/payment": "^2.0", "sylius/resource-bundle": "^1.11 || ^1.12@alpha", + "symfony/doctrine-bridge": "^6.4.0 || ^7.1", "symfony/framework-bundle": "^6.4.1 || ^7.1" }, "conflict": { From 89cd8b63577c9ca4f114c900ad31e756594b5260 Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Thu, 26 Sep 2024 13:09:20 +0200 Subject: [PATCH 198/200] [PaymentBundle] Move payment request to outside of payment --- .../Admin/Payment/PaymentRequest/ShowPage.php | 2 +- .../config/services/pages/admin/payment.xml | 2 +- .../payment/payment_request/index.yaml | 5 --- .../payment/payment_request/show.yaml | 38 ------------------- .../app/twig_hooks/payment_request/index.yaml | 5 +++ .../app/twig_hooks/payment_request/show.yaml | 38 +++++++++++++++++++ .../Resources/config/grids/payment.yml | 2 +- ...ayment_request.yml => payment_request.yml} | 10 ++--- .../config/routing/payment_request.yaml | 10 ++--- .../actions/list_payment_requests.html.twig | 2 +- .../grid/field/state.html.twig | 1 - .../payment/payment_request/index.html.twig | 3 -- .../payment/payment_request/show.html.twig | 3 -- .../common/label/state/cancelled.html.twig | 0 .../common/label/state/completed.html.twig | 0 .../common/label/state/failed.html.twig | 0 .../common/label/state/new.html.twig | 0 .../common/label/state/processing.html.twig | 0 .../grid/field/action.html.twig | 0 .../grid/field/method.html.twig | 0 .../grid/field/state.html.twig | 1 + .../content/header/breadcrumbs.html.twig | 0 .../show/content/header/breadcrumbs.html.twig | 2 +- .../show/content/sections.html.twig | 0 .../show/content/sections/general.html.twig | 0 .../content/sections/general/action.html.twig | 0 .../sections/general/created_at.html.twig | 0 .../content/sections/general/hash.html.twig | 0 .../content/sections/general/method.html.twig | 0 .../content/sections/general/state.html.twig | 2 +- .../sections/general/updated_at.html.twig | 0 .../show/content/sections/payload.html.twig | 0 .../content/sections/response_data.html.twig | 0 33 files changed, 60 insertions(+), 66 deletions(-) delete mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/index.yaml delete mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/show.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/index.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/show.yaml rename src/Sylius/Bundle/AdminBundle/Resources/config/grids/{payment_payment_request.yml => payment_request.yml} (91%) delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/state.html.twig delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index.html.twig delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show.html.twig rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/common/label/state/cancelled.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/common/label/state/completed.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/common/label/state/failed.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/common/label/state/new.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/common/label/state/processing.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/grid/field/action.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/grid/field/method.html.twig (100%) create mode 100644 src/Sylius/Bundle/AdminBundle/templates/payment_request/grid/field/state.html.twig rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/index/content/header/breadcrumbs.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/header/breadcrumbs.html.twig (86%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections/general.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections/general/action.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections/general/created_at.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections/general/hash.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections/general/method.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections/general/state.html.twig (57%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections/general/updated_at.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections/payload.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/{payment => }/payment_request/show/content/sections/response_data.html.twig (100%) diff --git a/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/ShowPage.php b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/ShowPage.php index 5e8ced226f..bbdc46d091 100644 --- a/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/ShowPage.php +++ b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/ShowPage.php @@ -19,7 +19,7 @@ class ShowPage extends SymfonyPage implements ShowPageInterface { public function getRouteName(): string { - return 'sylius_admin_payment_payment_request_show'; + return 'sylius_admin_payment_request_show'; } public function getFieldText(string $fieldName): string diff --git a/src/Sylius/Behat/Resources/config/services/pages/admin/payment.xml b/src/Sylius/Behat/Resources/config/services/pages/admin/payment.xml index 415f7382a4..e872f8c5c7 100644 --- a/src/Sylius/Behat/Resources/config/services/pages/admin/payment.xml +++ b/src/Sylius/Behat/Resources/config/services/pages/admin/payment.xml @@ -30,7 +30,7 @@ class="%sylius.behat.page.admin.payment.payment_request.index.class%" parent="sylius.behat.page.admin.crud.index" > - sylius_admin_payment_payment_request_index + sylius_admin_payment_request_index diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/index.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/index.yaml deleted file mode 100644 index 65a77dcde3..0000000000 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/index.yaml +++ /dev/null @@ -1,5 +0,0 @@ -twig_hooks: - hooks: - 'sylius_admin.payment.payment_request.index.content.header': - breadcrumbs: - template: '@SyliusAdmin/payment/payment_request/index/content/header/breadcrumbs.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/show.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/show.yaml deleted file mode 100644 index 0300d97740..0000000000 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment/payment_request/show.yaml +++ /dev/null @@ -1,38 +0,0 @@ -twig_hooks: - hooks: - 'sylius_admin.payment.payment_request.show.content': - sections: - template: '@SyliusAdmin/payment/payment_request/show/content/sections.html.twig' - - 'sylius_admin.payment.payment_request.show.content.header': - breadcrumbs: - template: '@SyliusAdmin/payment/payment_request/show/content/header/breadcrumbs.html.twig' - - 'sylius_admin.payment.payment_request.show.content.sections': - general: - template: '@SyliusAdmin/payment/payment_request/show/content/sections/general.html.twig' - - 'sylius_admin.payment.payment_request.show.content.sections#left': - payload: - template: '@SyliusAdmin/payment/payment_request/show/content/sections/payload.html.twig' - - 'sylius_admin.payment.payment_request.show.content.sections#right': - response_data: - template: '@SyliusAdmin/payment/payment_request/show/content/sections/response_data.html.twig' - - 'sylius_admin.payment.payment_request.show.content.sections.general': - hash: - template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/hash.html.twig' - method: - template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/method.html.twig' - action: - template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/action.html.twig' - state: - template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/state.html.twig' - created_at: - template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/created_at.html.twig' - updated_at: - template: '@SyliusAdmin/payment/payment_request/show/content/sections/general/updated_at.html.twig' - - - diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/index.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/index.yaml new file mode 100644 index 0000000000..087c9da377 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/index.yaml @@ -0,0 +1,5 @@ +twig_hooks: + hooks: + 'sylius_admin.payment_request.index.content.header': + breadcrumbs: + template: '@SyliusAdmin/payment_request/index/content/header/breadcrumbs.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/show.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/show.yaml new file mode 100644 index 0000000000..0fc8760724 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/show.yaml @@ -0,0 +1,38 @@ +twig_hooks: + hooks: + 'sylius_admin.payment_request.show.content': + sections: + template: '@SyliusAdmin/payment_request/show/content/sections.html.twig' + + 'sylius_admin.payment_request.show.content.header': + breadcrumbs: + template: '@SyliusAdmin/payment_request/show/content/header/breadcrumbs.html.twig' + + 'sylius_admin.payment_request.show.content.sections': + general: + template: '@SyliusAdmin/payment_request/show/content/sections/general.html.twig' + + 'sylius_admin.payment_request.show.content.sections#left': + payload: + template: '@SyliusAdmin/payment_request/show/content/sections/payload.html.twig' + + 'sylius_admin.payment_request.show.content.sections#right': + response_data: + template: '@SyliusAdmin/payment_request/show/content/sections/response_data.html.twig' + + 'sylius_admin.payment_request.show.content.sections.general': + hash: + template: '@SyliusAdmin/payment_request/show/content/sections/general/hash.html.twig' + method: + template: '@SyliusAdmin/payment_request/show/content/sections/general/method.html.twig' + action: + template: '@SyliusAdmin/payment_request/show/content/sections/general/action.html.twig' + state: + template: '@SyliusAdmin/payment_request/show/content/sections/general/state.html.twig' + created_at: + template: '@SyliusAdmin/payment_request/show/content/sections/general/created_at.html.twig' + updated_at: + template: '@SyliusAdmin/payment_request/show/content/sections/general/updated_at.html.twig' + + + diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml index d154262af3..3d72df10f9 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml @@ -75,7 +75,7 @@ sylius_grid: label: sylius.ui.list_payment_requests options: link: - route: sylius_admin_payment_payment_request_index + route: sylius_admin_payment_request_index parameters: paymentId: resource.id complete: diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_payment_request.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request.yml similarity index 91% rename from src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_payment_request.yml rename to src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request.yml index 26ca780b22..59a908ad5c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_payment_request.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_request.yml @@ -1,6 +1,6 @@ sylius_grid: grids: - sylius_admin_payment_payment_request: + sylius_admin_payment_request: driver: name: doctrine/orm options: @@ -21,17 +21,17 @@ sylius_grid: label: sylius.ui.payment_method path: . options: - template: "@SyliusAdmin/payment/payment_request/grid/field/method.html.twig" + template: "@SyliusAdmin/payment_request/grid/field/method.html.twig" action: type: twig label: sylius.ui.action options: - template: "@SyliusAdmin/payment/payment_request/grid/field/action.html.twig" + template: "@SyliusAdmin/payment_request/grid/field/action.html.twig" state: type: twig label: sylius.ui.state options: - template: "@SyliusAdmin/payment/payment_request/grid/field/state.html.twig" + template: "@SyliusAdmin/payment_request/grid/field/state.html.twig" createdAt: type: twig label: sylius.ui.creation_date @@ -87,7 +87,7 @@ sylius_grid: type: show options: link: - route: sylius_admin_payment_payment_request_show + route: sylius_admin_payment_request_show parameters: hash: resource.hash paymentId: resource.payment.id diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment_request.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment_request.yaml index d627e4e3f4..b70fcc573c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment_request.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/payment_request.yaml @@ -1,4 +1,4 @@ -sylius_admin_payment_payment_request_index: +sylius_admin_payment_request_index: path: / methods: [GET] defaults: @@ -6,10 +6,10 @@ sylius_admin_payment_payment_request_index: _sylius: section: admin permission: true - template: "@SyliusAdmin/payment/payment_request/index.html.twig" - grid: sylius_admin_payment_payment_request + template: "@SyliusAdmin/shared/crud/index.html.twig" + grid: sylius_admin_payment_request -sylius_admin_payment_payment_request_show: +sylius_admin_payment_request_show: path: /{hash} methods: [GET] defaults: @@ -17,7 +17,7 @@ sylius_admin_payment_payment_request_show: _sylius: section: admin permission: true - template: "@SyliusAdmin/payment/payment_request/show.html.twig" + template: "@SyliusAdmin/shared/crud/show.html.twig" repository: method: findOneByPaymentId arguments: diff --git a/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig b/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig index 1ef5f85c2e..eb9d4afdf5 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/order/show/content/sections/payments/item/actions/list_payment_requests.html.twig @@ -2,6 +2,6 @@ {% set payment = hookable_metadata.context.payment %} - + {{ icon({ icon: 'list_letters', class: 'icon icon-tabler' }) }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/state.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/state.html.twig deleted file mode 100644 index f4e5ed460d..0000000000 --- a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/state.html.twig +++ /dev/null @@ -1 +0,0 @@ -{{ include('@SyliusAdmin/payment/payment_request/common/label/state/' ~ data ~ '.html.twig') }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index.html.twig deleted file mode 100644 index 0173df70ac..0000000000 --- a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index.html.twig +++ /dev/null @@ -1,3 +0,0 @@ -{% extends '@SyliusAdmin/shared/crud/index.html.twig' %} - -{% set resource_name = 'payment.payment_request' %} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show.html.twig deleted file mode 100644 index b7fccd3b30..0000000000 --- a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show.html.twig +++ /dev/null @@ -1,3 +0,0 @@ -{% extends '@SyliusAdmin/shared/crud/show.html.twig' %} - -{% set resource_name = 'payment.payment_request' %} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/cancelled.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/cancelled.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/cancelled.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/cancelled.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/completed.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/completed.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/completed.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/completed.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/failed.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/failed.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/failed.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/failed.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/new.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/new.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/new.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/new.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/processing.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/processing.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/common/label/state/processing.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/common/label/state/processing.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/action.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/grid/field/action.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/action.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/grid/field/action.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/method.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/grid/field/method.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/grid/field/method.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/grid/field/method.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment_request/grid/field/state.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/grid/field/state.html.twig new file mode 100644 index 0000000000..3aa2d08bac --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/templates/payment_request/grid/field/state.html.twig @@ -0,0 +1 @@ +{{ include('@SyliusAdmin/payment_request/common/label/state/' ~ data ~ '.html.twig') }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index/content/header/breadcrumbs.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/index/content/header/breadcrumbs.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/index/content/header/breadcrumbs.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/index/content/header/breadcrumbs.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/header/breadcrumbs.html.twig similarity index 86% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/header/breadcrumbs.html.twig index 48ecd8d00c..64db485e5f 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/header/breadcrumbs.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/header/breadcrumbs.html.twig @@ -7,6 +7,6 @@ { name: 'sylius.ui.dashboard', url: path('sylius_admin_dashboard'), active: false }, { name: 'sylius.ui.payments'|trans, url: path('sylius_admin_payment_index'), active: false }, { name: payment_id, active: false }, - { name: 'sylius.ui.payment_requests'|trans, url: path('sylius_admin_payment_payment_request_index', {'paymentId': payment_id}), active: false }, + { name: 'sylius.ui.payment_requests'|trans, url: path('sylius_admin_payment_request_index', {'paymentId': payment_id}), active: false }, { name: payment_request.hash, active: true }, ]) }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/action.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/action.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/action.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/action.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/created_at.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/created_at.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/created_at.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/created_at.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/hash.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/hash.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/hash.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/hash.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/method.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/method.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/method.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/method.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/state.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/state.html.twig similarity index 57% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/state.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/state.html.twig index a541449a76..3db192851d 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/state.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/state.html.twig @@ -1,6 +1,6 @@
{{ 'sylius.ui.state'|trans }}
- {{ include('@SyliusAdmin/payment/payment_request/common/label/state/' ~ hookable_metadata.context.resource.state ~ '.html.twig') }} + {{ include('@SyliusAdmin/payment_request/common/label/state/' ~ hookable_metadata.context.resource.state ~ '.html.twig') }}
diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/updated_at.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/updated_at.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/general/updated_at.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/general/updated_at.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/payload.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/payload.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/payload.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/payload.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/response_data.html.twig b/src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/response_data.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/templates/payment/payment_request/show/content/sections/response_data.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/payment_request/show/content/sections/response_data.html.twig From 5e753f591a1d6d8b2274957e48cb5369c7e73063 Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Fri, 27 Sep 2024 09:44:07 +0200 Subject: [PATCH 199/200] [PaymentBundle] Minor improvements --- .../payment_request/browsing_payment_requests.feature | 2 +- .../payment_request/seeing_payment_request_details.feature | 2 +- src/Sylius/Behat/Context/Setup/PaymentContext.php | 2 +- .../Context/Ui/Admin/ManagingPaymentRequestsContext.php | 5 +---- .../Page/Admin/Payment/PaymentRequest/IndexPageInterface.php | 1 - .../config/app/twig_hooks/payment_request/show.yaml | 3 --- .../Bundle/AdminBundle/Resources/config/grids/payment.yml | 2 +- 7 files changed, 5 insertions(+), 12 deletions(-) diff --git a/features/admin/payment/managing_payments/payment_request/browsing_payment_requests.feature b/features/admin/payment/managing_payments/payment_request/browsing_payment_requests.feature index 3b53205378..84df289684 100644 --- a/features/admin/payment/managing_payments/payment_request/browsing_payment_requests.feature +++ b/features/admin/payment/managing_payments/payment_request/browsing_payment_requests.feature @@ -18,7 +18,7 @@ Feature: Browsing payment requests @api @ui Scenario: Browsing payment requests of a payment When I browse payments - And I want to view the payment request of the first payment + And I want to view the payment requests of the first payment Then there should be 3 payment requests on the list And it should be the payment request with action "authorize" And it should be the payment request with action "capture" diff --git a/features/admin/payment/managing_payments/payment_request/seeing_payment_request_details.feature b/features/admin/payment/managing_payments/payment_request/seeing_payment_request_details.feature index f51af8331a..a1af8f9f26 100644 --- a/features/admin/payment/managing_payments/payment_request/seeing_payment_request_details.feature +++ b/features/admin/payment/managing_payments/payment_request/seeing_payment_request_details.feature @@ -1,5 +1,5 @@ @managing_payments -Feature: Seeing payment request details +Feature: Seeing payment request's details In order to have an overview of one of payment requests As an Administrator I want to be able to see its details diff --git a/src/Sylius/Behat/Context/Setup/PaymentContext.php b/src/Sylius/Behat/Context/Setup/PaymentContext.php index 2de4188c42..e5d3b91e73 100644 --- a/src/Sylius/Behat/Context/Setup/PaymentContext.php +++ b/src/Sylius/Behat/Context/Setup/PaymentContext.php @@ -127,7 +127,7 @@ final readonly class PaymentContext implements Context /** * @Given the store has :paymentMethodName payment method not assigned to any channel */ - public function theStoreHasPaymentMethodNotAssignedToAnyChannel($paymentMethodName): void + public function theStoreHasPaymentMethodNotAssignedToAnyChannel(string $paymentMethodName): void { $this->createPaymentMethod($paymentMethodName, 'PM_' . $paymentMethodName, 'Offline', 'Payment method', false); } diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php index 22e7ee7245..cc74e4ffc9 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentRequestsContext.php @@ -84,10 +84,7 @@ final readonly class ManagingPaymentRequestsContext implements Context */ public function thereShouldBeProductVariantsOnTheList(int $count): void { - Assert::same( - $this->indexPage->countItems(), - $count, - ); + Assert::same($this->indexPage->countItems(), $count); } /** diff --git a/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPageInterface.php b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPageInterface.php index 348607d720..2aa4f49da1 100644 --- a/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Payment/PaymentRequest/IndexPageInterface.php @@ -22,5 +22,4 @@ interface IndexPageInterface extends BaseIndexPageInterface public function chooseActionToFilter(string $action): void; public function chooseStateToFilter(string $state): void; - } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/show.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/show.yaml index 0fc8760724..731c453478 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/show.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/payment_request/show.yaml @@ -33,6 +33,3 @@ twig_hooks: template: '@SyliusAdmin/payment_request/show/content/sections/general/created_at.html.twig' updated_at: template: '@SyliusAdmin/payment_request/show/content/sections/general/updated_at.html.twig' - - - diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml index 3d72df10f9..48567073b3 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment.yml @@ -69,7 +69,7 @@ sylius_grid: class: "%sylius.model.channel.class%" actions: item: - show_payment_requests: + list_payment_requests: type: show icon: list_letters label: sylius.ui.list_payment_requests From f8063051297a5e2fc55db17bcee47670e3119745 Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Fri, 27 Sep 2024 10:20:51 +0200 Subject: [PATCH 200/200] [PaymentBundle] Minor improvement --- .../Behat/Context/Api/Admin/ManagingPaymentsContext.php | 4 ++-- src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentsContext.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentsContext.php index 8175dde7a4..73c778c96e 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingPaymentsContext.php @@ -59,9 +59,9 @@ final readonly class ManagingPaymentsContext implements Context } /** - * @When I want to view the payment request of the first payment + * @When I want to view the payment requests of the first payment */ - public function iWantToViewThePaymentRequestOfTheFirstPayment(): void + public function iWantToViewThePaymentRequestsOfTheFirstPayment(): void { $response = $this->client->getLastResponse(); diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentsContext.php index e9cf67042b..308462e854 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentsContext.php @@ -81,9 +81,9 @@ final class ManagingPaymentsContext implements Context } /** - * @When I want to view the payment request of the first payment + * @When I want to view the payment requests of the first payment */ - public function iWantToViewThePaymentRequestOfTheFirstPayment(): void + public function iWantToViewThePaymentRequestsOfTheFirstPayment(): void { $this->indexPage->showPaymentRequestOfNthPayment(1); }