From d5812cdb13c139a4f5bf73309417134980d8ce14 Mon Sep 17 00:00:00 2001 From: Kevin Kaniaburka Date: Thu, 7 Nov 2024 13:18:25 +0100 Subject: [PATCH] Fix integration with SyliusRefundPlugin and Winzou SM --- config/config/winzou_state_machine.php | 41 +++++++++ src/CommerceWeaversSyliusTpayPlugin.php | 2 - ...AddWinzouStateMachineConfigurationPass.php | 83 ------------------- 3 files changed, 41 insertions(+), 85 deletions(-) create mode 100644 config/config/winzou_state_machine.php delete mode 100644 src/DependencyInjection/CompilerPass/AddWinzouStateMachineConfigurationPass.php diff --git a/config/config/winzou_state_machine.php b/config/config/winzou_state_machine.php new file mode 100644 index 00000000..0bc0d20a --- /dev/null +++ b/config/config/winzou_state_machine.php @@ -0,0 +1,41 @@ +getParameter('kernel.bundles'); + + $container->extension('winzou_state_machine', [ + 'sylius_payment' => [ + 'callbacks' => [ + 'before' => [ + 'tpay_refund_payment' => [ + 'on' => ['refund'], + 'do' => ['@commerce_weavers_sylius_tpay.refunding.dispatcher.refund', 'dispatch'], + 'args' => ['object'], + ], + ], + ], + ], + ]); + + if (isset($kernelBundles['SyliusRefundPlugin']) && $kernelBundles['winzouStateMachineBundle']) { + $container->extension('winzou_state_machine', [ + 'sylius_refund_refund_payment' => [ + 'callbacks' => [ + 'before' => [ + 'tpay_refund_payment' => [ + 'on' => ['complete'], + 'do' => ['@commerce_weavers_sylius_tpay.refunding.dispatcher.refund', 'dispatch'], + 'args' => ['object'], + ], + ] + ] + ], + ]); + } +}; diff --git a/src/CommerceWeaversSyliusTpayPlugin.php b/src/CommerceWeaversSyliusTpayPlugin.php index 3b553db7..230fc5a8 100644 --- a/src/CommerceWeaversSyliusTpayPlugin.php +++ b/src/CommerceWeaversSyliusTpayPlugin.php @@ -5,7 +5,6 @@ namespace CommerceWeavers\SyliusTpayPlugin; use CommerceWeavers\SyliusTpayPlugin\DependencyInjection\CompilerPass\AddSupportedRefundPaymentMethodPass; -use CommerceWeavers\SyliusTpayPlugin\DependencyInjection\CompilerPass\AddWinzouStateMachineConfigurationPass; use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -17,7 +16,6 @@ final class CommerceWeaversSyliusTpayPlugin extends Bundle public function build(ContainerBuilder $container): void { $container->addCompilerPass(new AddSupportedRefundPaymentMethodPass()); - $container->addCompilerPass(new AddWinzouStateMachineConfigurationPass()); } public function getPath(): string diff --git a/src/DependencyInjection/CompilerPass/AddWinzouStateMachineConfigurationPass.php b/src/DependencyInjection/CompilerPass/AddWinzouStateMachineConfigurationPass.php deleted file mode 100644 index ca402a04..00000000 --- a/src/DependencyInjection/CompilerPass/AddWinzouStateMachineConfigurationPass.php +++ /dev/null @@ -1,83 +0,0 @@ -resolveEnvPlaceholders( - $container->getParameter('sylius_abstraction.state_machine.default_adapter'), - true, - ); - /** @var array $stateMachineAdapterMapping */ - $stateMachineAdapterMapping = $container->resolveEnvPlaceholders( - $container->getParameter('sylius_abstraction.state_machine.graphs_to_adapters_mapping'), - true, - ); - } catch (ParameterNotFoundException) { - return; - } - - if ($this->hasWinzouStateMachineGraph('sylius_payment', $stateMachineDefaultAdapter, $stateMachineAdapterMapping)) { - $container->prependExtensionConfig('winzou_state_machine', [ - 'sylius_payment' => [ - 'callbacks' => [ - 'before' => [ - 'tpay_refund_payment' => [ - 'on' => ['refund'], - 'do' => ['@commerce_weavers_sylius_tpay.refunding.dispatcher.refund', 'dispatch'], - 'args' => ['object'], - ], - ], - ], - ], - ]); - } - - if ( - $container->hasExtension('sylius_refund') && - $this->hasWinzouStateMachineGraph('sylius_refund_refund_payment', $stateMachineDefaultAdapter, $stateMachineAdapterMapping) - ) { - $container->prependExtensionConfig('winzou_state_machine', [ - 'sylius_refund_refund_payment' => [ - 'callbacks' => [ - 'before' => [ - 'tpay_refund_payment' => [ - 'on' => ['complete'], - 'do' => ['@commerce_weavers_sylius_tpay.refunding.dispatcher.refund', 'dispatch'], - 'args' => ['object'], - ], - ], - ], - ], - ]); - } - } - - /** - * @param array $stateMachineAdapterMapping - */ - private function hasWinzouStateMachineGraph( - string $graphName, - string $stateMachineDefaultAdapter, - array $stateMachineAdapterMapping, - ): bool { - return ( - isset($stateMachineAdapterMapping[$graphName]) && - $stateMachineAdapterMapping[$graphName] === 'winzou_state_machine' - ) || - ( - !isset($stateMachineAdapterMapping[$graphName]) && - $stateMachineDefaultAdapter === 'winzou_state_machine' - ); - } -}