Skip to content

Commit

Permalink
Merge 7dba2ab into 8c1b1af
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Jun 28, 2018
2 parents 8c1b1af + 7dba2ab commit f8214b2
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 93 deletions.
8 changes: 0 additions & 8 deletions app/config/eccube/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ services:
lazy: true
public: true

Eccube\Service\PaymentService:
lazy: true
public: true

Eccube\Service\Payment\Method\Cash:
lazy: true
public: true

Eccube\Service\SystemService:
lazy: true
public: true
Expand Down
10 changes: 3 additions & 7 deletions src/Eccube/Controller/ShoppingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ public function completeOrder(Request $request)
if ($dispatcher->isForward()) {
return $this->forwardToRoute($dispatcher->getRoute(), $dispatcher->getPathParameters(), $dispatcher->getQueryParameters());
} else {
return $this->redirectToRoute($dispatcher->getRoute(), $dispatcher->getQueryParameters());
return $this->redirectToRoute($dispatcher->getRoute(), array_merge($dispatcher->getPathParameters(), $dispatcher->getQueryParameters()));
}
}

Expand Down Expand Up @@ -961,17 +961,13 @@ public function afterComplete(Request $request)
private function createPaymentService(Order $Order)
{
$serviceClass = $Order->getPayment()->getServiceClass();
$paymentService = new $serviceClass($this->container->get('request_stack')); // コンテナから取得したい

return $paymentService;
return $this->container->get($serviceClass);
}

private function createPaymentMethod(Order $Order, $form)
{
$methodClass = $Order->getPayment()->getMethodClass();

// TODO Plugin/Xxx/Resouce/config/services.yamlでpublicにする必要がある
$PaymentMethod = $this->container->get($methodClass);
$PaymentMethod = $this->container->get($Order->getPayment()->getMethodClass());
$PaymentMethod->setOrder($Order);
$PaymentMethod->setFormType($form);

Expand Down
40 changes: 40 additions & 0 deletions src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eccube\DependencyInjection\Compiler;

use Eccube\Service\Payment\PaymentMethodInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class PaymentMethodPass implements CompilerPassInterface
{
const PAYMENT_METHOD_TAG = 'eccube.payment.method';

public function process(ContainerBuilder $container)
{
$ids = $container->findTaggedServiceIds(self::PAYMENT_METHOD_TAG);

foreach ($ids as $id => $tags) {
$def = $container->getDefinition($id);
$def->setPublic(true);
$class = $container->getParameterBag()->resolveValue($def->getClass());
if (!is_subclass_of($class, PaymentMethodInterface::class)) {
throw new \InvalidArgumentException(
sprintf('Service "%s" must implement interface "%s".', $id, PaymentMethodInterface::class));
}

$container->setParameter($class, $class);
}
}
}
40 changes: 40 additions & 0 deletions src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eccube\DependencyInjection\Compiler;

use Eccube\Service\PaymentServiceInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class PaymentServicePass implements CompilerPassInterface
{
const PAYMENT_TAG = 'eccube.payment';

public function process(ContainerBuilder $container)
{
$ids = $container->findTaggedServiceIds(self::PAYMENT_TAG);

foreach ($ids as $id => $tags) {
$def = $container->getDefinition($id);
$def->setPublic(true);
$class = $container->getParameterBag()->resolveValue($def->getClass());
if (!is_subclass_of($class, PaymentServiceInterface::class)) {
throw new \InvalidArgumentException(
sprintf('Service "%s" must implement interface "%s".', $id, PaymentServiceInterface::class));
}

$container->setParameter($class, $class);
}
}
}
14 changes: 14 additions & 0 deletions src/Eccube/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Eccube\Common\EccubeTwigBlock;
use Eccube\DependencyInjection\Compiler\AutoConfigurationTagPass;
use Eccube\DependencyInjection\Compiler\NavCompilerPass;
use Eccube\DependencyInjection\Compiler\PaymentMethodPass;
use Eccube\DependencyInjection\Compiler\PaymentServicePass;
use Eccube\DependencyInjection\Compiler\PluginPass;
use Eccube\DependencyInjection\Compiler\QueryCustomizerPass;
use Eccube\DependencyInjection\Compiler\TemplateListenerPass;
Expand All @@ -30,6 +32,8 @@
use Eccube\Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Eccube\Doctrine\Query\QueryCustomizer;
use Eccube\Plugin\ConfigManager;
use Eccube\Service\PaymentServiceInterface;
use Eccube\Service\Payment\PaymentMethodInterface;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
Expand Down Expand Up @@ -182,6 +186,16 @@ protected function build(ContainerBuilder $container)
$container->registerForAutoconfiguration(EccubeTwigBlock::class)
->addTag(TwigBlockPass::TWIG_BLOCK_TAG);
$container->addCompilerPass(new TwigBlockPass());

// PaymentService の拡張
$container->registerForAutoconfiguration(PaymentServiceInterface::class)
->addTag(PaymentServicePass::PAYMENT_TAG);
$container->addCompilerPass(new PaymentServicePass());

// PaymentMethod の拡張
$container->registerForAutoconfiguration(PaymentMethodInterface::class)
->addTag(PaymentMethodPass::PAYMENT_METHOD_TAG);
$container->addCompilerPass(new PaymentMethodPass());
}

protected function addEntityExtensionPass(ContainerBuilder $container)
Expand Down
12 changes: 9 additions & 3 deletions src/Eccube/Service/Payment/Method/Cash.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@
namespace Eccube\Service\Payment\Method;

use Eccube\Entity\Order;
use Eccube\Service\Payment\PaymentMethod;
use Eccube\Service\Payment\PaymentMethodInterface;
use Eccube\Service\Payment\PaymentResult;
use Symfony\Component\Form\FormInterface;

class Cash implements PaymentMethod
/**
* 銀行振込, 代金引き換えなど, 主に現金を扱う支払い方法を扱うクラス.
*/
class Cash implements PaymentMethodInterface
{
/**
* {@inheritdoc}
*/
public function checkout()
{
return new PaymentResult();
$result = new PaymentResult();
$result->setSuccess(true);

return $result;
}

/**
Expand Down
16 changes: 13 additions & 3 deletions src/Eccube/Service/Payment/Method/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@
namespace Eccube\Service\Payment\Method;

use Eccube\Entity\Order;
use Eccube\Service\Payment\PaymentMethod;
use Eccube\Service\Payment\PaymentMethodInterface;
use Symfony\Component\Form\FormInterface;

abstract class CreditCard implements PaymentMethod
/**
* クレジットカード払いの基底クラス.
*
* クレジットカード決済を実装する場合は, このクラスを継承します.
*/
abstract class CreditCard implements PaymentMethodInterface
{
/**
* @var
* @var Order
*/
protected $Order;

/**
* {@inheritdoc}
*/
abstract public function verify();

/**
* {@inheritdoc}
*/
Expand Down
62 changes: 0 additions & 62 deletions src/Eccube/Service/Payment/Method/EccubePaymentCreditCard.php

This file was deleted.

Loading

0 comments on commit f8214b2

Please sign in to comment.