Skip to content

Commit

Permalink
Add a support for Symfony Workflow while a refunding process
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed Sep 6, 2024
1 parent 97bc58c commit 90ffd3b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 5 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/_matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,30 @@
"php": "8.0",
"sylius": "1.12.*",
"symfony": "5.4.*",
"mysql": "8.0"
"mysql": "8.0",
"state_machine": "winzou_state_machine"
},
{
"php": "8.3",
"sylius": "1.13.*",
"symfony": "6.4.*",
"mysql": "8.0"
"mysql": "8.0",
"state_machine": "symfony_workflow"
}
]
},
"daily": {
"php": ["8.0", "8.3"],
"sylius": ["1.12.*", "1.13.*"],
"symfony": ["5.4.*", "6.4.*"],
"mysql": ["8.0"]
"mysql": ["8.0"],
"state_machine": ["winzou_state_machine", "symfony_workflow"],
"exclude": [
{
"sylius": "1.12.*",
"state_machine": "symfony_workflow"
}
]
}
}
}
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

runs-on: ubuntu-latest

name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}"
name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}, State Machine ${{ matrix.state_machine }}"

strategy:
fail-fast: false
Expand All @@ -41,6 +41,7 @@ jobs:
env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"
STATE_MACHINE_DEFAULT_ADAPTER: ${{ matrix.state_machine }}

steps:
-
Expand Down
13 changes: 12 additions & 1 deletion config/services/refunding.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use CommerceWeavers\SyliusTpayPlugin\Refunding\Dispatcher\RefundDispatcher;
use CommerceWeavers\SyliusTpayPlugin\Refunding\Dispatcher\RefundDispatcherInterface;
use CommerceWeavers\SyliusTpayPlugin\Refunding\Workflow\Listener\DispatchRefundListener;
use Sylius\Bundle\CoreBundle\SyliusCoreBundle;

return function(ContainerConfigurator $container): void {
$services = $container->services();
Expand All @@ -15,6 +17,15 @@
->args([
service('payum'),
])
->alias(RefundDispatcherInterface::class, 'commerce_weavers.tpay.refunding.dispatcher.refund');
->alias(RefundDispatcherInterface::class, 'commerce_weavers.tpay.refunding.dispatcher.refund')
;

if (SyliusCoreBundle::VERSION_ID >= 11300) {
$services->set('commerce_weavers.tpay.refunding.workflow.listener.dispatch_refund', DispatchRefundListener::class)
->args([
service('commerce_weavers.tpay.refunding.dispatcher.refund'),
])
->tag('kernel.event_listener', ['event' => 'workflow.sylius_payment.transition.refund'])
;
}
};
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ parameters:
ignoreErrors:
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'
- '/Parameter \#1 \$request \([^)]+\) of method [^:]+::execute\(\) should be contravariant with parameter \$request \(mixed\) of method Payum\\Core\\Action\\ActionInterface::execute\(\)/'
- '/Parameter \$event of method CommerceWeavers\\SyliusTpayPlugin\\Refunding\\Workflow\\Listener\\DispatchRefundListener::__invoke\(\) has invalid type Symfony\\Component\\Workflow\\Event\\TransitionEvent\./'
- '/Call to method getSubject\(\) on an unknown class Symfony\\Component\\Workflow\\Event\\TransitionEvent\./'
30 changes: 30 additions & 0 deletions src/Refunding/Workflow/Listener/DispatchRefundListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Refunding\Workflow\Listener;

use CommerceWeavers\SyliusTpayPlugin\Refunding\Dispatcher\RefundDispatcherInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Symfony\Component\Workflow\Event\TransitionEvent;

final class DispatchRefundListener
{
public function __construct(
private RefundDispatcherInterface $refundDispatcher,
) {
}

public function __invoke(TransitionEvent $event): void
{
$payment = $event->getSubject();

if (!$payment instanceof PaymentInterface) {
throw new \UnexpectedValueException(
sprintf('Expected instance of "%s", got "%s"', PaymentInterface::class, get_class($payment)),
);
}

$this->refundDispatcher->dispatch($payment);
}
}
1 change: 1 addition & 0 deletions tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ imports:
- { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" }

parameters:
env(STATE_MACHINE_DEFAULT_ADAPTER): 'winzou_state_machine'
sylius_core.public_dir: '%kernel.project_dir%/public'

sylius_shop:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sylius\Bundle\CoreBundle\SyliusCoreBundle;

if (SyliusCoreBundle::VERSION_ID < 11300) {
return;
}

return function(ContainerConfigurator $container): void {
$container->extension('sylius_state_machine_abstraction', [
'default_adapter' => '%env(STATE_MACHINE_DEFAULT_ADAPTER)%',
]);
};

0 comments on commit 90ffd3b

Please sign in to comment.