Skip to content

Commit

Permalink
[PayumBundle] Fix application crash while capturing payments
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Jan 21, 2021
1 parent e9e191b commit 9a6e0d4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Sylius\Bundle\PayumBundle\DependencyInjection\Compiler;

use Payum\Bundle\PayumBundle\Controller;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Reference;

/**
* @see https://github.com/Payum/PayumBundle/issues/507
*
* @internal
*/
final class InjectContainerIntoControllersPass implements CompilerPassInterface
{
private const SERVICES = [
Controller\AuthorizeController::class,
Controller\CancelController::class,
Controller\CaptureController::class,
Controller\NotifyController::class,
Controller\PayoutController::class,
Controller\RefundController::class,
Controller\SyncController::class,
];

public function process(ContainerBuilder $container): void
{
foreach (self::SERVICES as $service) {
try {
$definition = $container->findDefinition($service);
} catch (ServiceNotFoundException $exception) {
$definition = new Definition($service);

$container->setDefinition($service, $definition);
}

$definition->addMethodCall('setContainer', [new Reference('service_container')]);
$definition->setPublic(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @internal
*/
final class UseTweakedDoctrineStoragePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@

namespace Sylius\Bundle\PayumBundle\DependencyInjection;

use Payum\Bundle\PayumBundle\Controller;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;

final class SyliusPayumExtension extends AbstractResourceExtension implements PrependExtensionInterface
{
Expand All @@ -30,6 +34,26 @@ public function load(array $configs, ContainerBuilder $container): void

$loader->load('services.xml');

// $services = [
// Controller\AuthorizeController::class,
// Controller\CancelController::class,
// Controller\CaptureController::class,
// Controller\NotifyController::class,
// Controller\PayoutController::class,
// Controller\RefundController::class,
// Controller\SyncController::class,
// ];
//
// foreach ($services as $service) {
// try {
// $definition = $container->findDefinition($service);
// } catch (ServiceNotFoundException $exception) {
// $definition = new Definition($service);
// }
//
// $definition->addMethodCall('setContainer', [new Reference('service_container')]);
// }

$container->setParameter('payum.template.layout', $config['template']['layout']);
$container->setParameter('payum.template.obtain_credit_card', $config['template']['obtain_credit_card']);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Bundle/PayumBundle/SyliusPayumBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Bundle\PayumBundle;

use Sylius\Bundle\PayumBundle\DependencyInjection\Compiler\InjectContainerIntoControllersPass;
use Sylius\Bundle\PayumBundle\DependencyInjection\Compiler\RegisterGatewayConfigTypePass;
use Sylius\Bundle\PayumBundle\DependencyInjection\Compiler\UseTweakedDoctrineStoragePass;
use Sylius\Bundle\ResourceBundle\AbstractResourceBundle;
Expand All @@ -32,6 +33,7 @@ public function build(ContainerBuilder $container): void
{
parent::build($container);

$container->addCompilerPass(new InjectContainerIntoControllersPass());
$container->addCompilerPass(new RegisterGatewayConfigTypePass());
$container->addCompilerPass(new UseTweakedDoctrineStoragePass());
}
Expand Down

0 comments on commit 9a6e0d4

Please sign in to comment.