From 9e6326afe27dc22f40a84bdf98be1599ff62e9da Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 28 Jun 2018 10:44:02 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E8=BF=BD=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/ShoppingController.php | 2 +- src/Eccube/Service/Payment/Method/Cash.php | 7 ++- .../Service/Payment/Method/CreditCard.php | 12 +++- .../Method/EccubePaymentCreditCard.php | 62 ------------------- .../Service/Payment/PaymentDispatcher.php | 57 +++++++++++++++++ src/Eccube/Service/Payment/PaymentMethod.php | 19 ++++++ src/Eccube/Service/Payment/PaymentResult.php | 23 ++++++- src/Eccube/Service/PaymentService.php | 20 +++++- 8 files changed, 134 insertions(+), 68 deletions(-) delete mode 100644 src/Eccube/Service/Payment/Method/EccubePaymentCreditCard.php diff --git a/src/Eccube/Controller/ShoppingController.php b/src/Eccube/Controller/ShoppingController.php index 8c983d65a7c..9e1595bdf9f 100644 --- a/src/Eccube/Controller/ShoppingController.php +++ b/src/Eccube/Controller/ShoppingController.php @@ -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())); } } diff --git a/src/Eccube/Service/Payment/Method/Cash.php b/src/Eccube/Service/Payment/Method/Cash.php index 6247bc8b2ac..996f84a1cc9 100644 --- a/src/Eccube/Service/Payment/Method/Cash.php +++ b/src/Eccube/Service/Payment/Method/Cash.php @@ -18,6 +18,9 @@ use Eccube\Service\Payment\PaymentResult; use Symfony\Component\Form\FormInterface; +/** + * 銀行振込, 代金引き換えなど, 主に現金を扱う支払い方法を扱うクラス. + */ class Cash implements PaymentMethod { /** @@ -25,7 +28,9 @@ class Cash implements PaymentMethod */ public function checkout() { - return new PaymentResult(); + $result = new PaymentResult(); + $result->setSuccess(true); + return $result; } /** diff --git a/src/Eccube/Service/Payment/Method/CreditCard.php b/src/Eccube/Service/Payment/Method/CreditCard.php index 09d41f53e0a..e1b9ab5a577 100644 --- a/src/Eccube/Service/Payment/Method/CreditCard.php +++ b/src/Eccube/Service/Payment/Method/CreditCard.php @@ -17,13 +17,23 @@ use Eccube\Service\Payment\PaymentMethod; use Symfony\Component\Form\FormInterface; +/** + * クレジットカード払いの基底クラス. + * + * クレジットカード決済を実装する場合は, このクラスを継承します. + */ abstract class CreditCard implements PaymentMethod { /** - * @var + * @var Order */ protected $Order; + /** + * {@inheritdoc} + */ + abstract public function verify(); + /** * {@inheritdoc} */ diff --git a/src/Eccube/Service/Payment/Method/EccubePaymentCreditCard.php b/src/Eccube/Service/Payment/Method/EccubePaymentCreditCard.php deleted file mode 100644 index 0c358bc8205..00000000000 --- a/src/Eccube/Service/Payment/Method/EccubePaymentCreditCard.php +++ /dev/null @@ -1,62 +0,0 @@ -setForward(true); - $dispatcher->setRoute('shopping_***'); - - return $dispatcher; - } - - /** - * {@inheritdoc} - */ - public function setFormType(FormInterface $form) - { - // nothing - } - - /** - * {@inheritdoc} - */ - public function verify() - { - // 有効性チェック等の処理をする - return new PaymentResult(); - } -} diff --git a/src/Eccube/Service/Payment/PaymentDispatcher.php b/src/Eccube/Service/Payment/PaymentDispatcher.php index 96173584ac0..a30d0b2b0f3 100644 --- a/src/Eccube/Service/Payment/PaymentDispatcher.php +++ b/src/Eccube/Service/Payment/PaymentDispatcher.php @@ -15,6 +15,9 @@ use Symfony\Component\HttpFoundation\Response; +/** + * 他のコントローラに処理を移譲するための情報を設定するクラス. + */ class PaymentDispatcher { /** @@ -42,21 +45,47 @@ class PaymentDispatcher */ private $queryParameters = []; + /** + * Forward を使用するかどうか. + * + * @return boolean + */ public function isForward() { return $this->forward; } + /** + * Forward を使用するかどうかを設定します. + * + * Forward を使用する場合は true, Redirect を使用する場合は false を設定します. + * + * @param boolean $forward + * @return PaymentDispatcher + */ public function setForward($forward) { $this->forward = $forward; + + return $this; } + /** + * 処理を移譲するルート名を返します. + * + * @return string + */ public function getRoute() { return $this->route; } + /** + * 処理を移譲するルート名を設定します. + * + * @param string $route + * @return PaymentDispatcher + */ public function setRoute($route) { $this->route = $route; @@ -64,11 +93,22 @@ public function setRoute($route) return $this; } + /** + * クエリパラメータの配列を返します. + * + * @return array + */ public function getQueryParameters() { return $this->queryParameters; } + /** + * クエリパラメータの配列を設定します. + * + * @param array + * @return PaymentDispatcher + */ public function setQueryParameters(array $queryParameters) { $this->queryParameters = $queryParameters; @@ -76,11 +116,22 @@ public function setQueryParameters(array $queryParameters) return $this; } + /** + * パスパラメータの配列を返します. + * + * @return array + */ public function getPathParameters() { return $this->pathParameters; } + /** + * パスパラメータの配列を設定します. + * + * @param array + * @return PaymentDispatcher + */ public function setPathParameters(array $pathParameters) { $this->pathParameters = $pathParameters; @@ -89,6 +140,10 @@ public function setPathParameters(array $pathParameters) } /** + * Response を設定します. + * + * 外部のサイトへリダイレクトする等, 特殊な用途に使用してください. + * * @param Response $response * * @return PaymentResult @@ -101,6 +156,8 @@ public function setResponse(Response $response) } /** + * Response を返します. + * * @return Response */ public function getResponse() diff --git a/src/Eccube/Service/Payment/PaymentMethod.php b/src/Eccube/Service/Payment/PaymentMethod.php index 546f78b90a3..461f7ea2a66 100644 --- a/src/Eccube/Service/Payment/PaymentMethod.php +++ b/src/Eccube/Service/Payment/PaymentMethod.php @@ -24,27 +24,46 @@ interface PaymentMethod { /** + * 決済の妥当性を検証し, 検証結果を返します. + * + * 主にクレジットカードの有効性チェック等を実装します. + * * @return PaymentResult */ public function verify(); /** + * 決済を実行し, 実行結果を返します. + * + * 主に決済の確定処理を実装します. + * * @return PaymentResult */ public function checkout(); /** + * 注文に決済を適用します. + * + * このメソッドは PaymentService::dispatch() でコールされます. + * PaymentDispatcher に遷移先の情報を設定することで, 他のコントローラに処理を移譲できます. + * * @return PaymentDispatcher */ public function apply(); /** + * PaymentMethod の処理に必要な FormInterface を設定します. + * * @param FormInterface + * @return PaymentMethod */ public function setFormType(FormInterface $form); /** + * この決済を使用する Order を設定します. + * * @param Order + * @return PaymentMethod */ public function setOrder(Order $Order); } diff --git a/src/Eccube/Service/Payment/PaymentResult.php b/src/Eccube/Service/Payment/PaymentResult.php index 020c0e23d84..cefad93923e 100644 --- a/src/Eccube/Service/Payment/PaymentResult.php +++ b/src/Eccube/Service/Payment/PaymentResult.php @@ -15,6 +15,9 @@ use Symfony\Component\HttpFoundation\Response; +/** + * 決済結果のクラス. + */ class PaymentResult { /** @@ -33,6 +36,10 @@ class PaymentResult private $response; /** + * 決済が成功したかどうかを設定します. + * + * 決済が成功した場合は true, 失敗した場合は false を設定します. + * * @param boolean $success * * @return PaymentResult @@ -45,14 +52,20 @@ public function setSuccess($success) } /** + * 決済が成功したかどうか. + * + * 決済が成功した場合 true + * * @return boolean */ public function isSuccess() { - return true; + return $this->success; } /** + * 決済が失敗した場合のエラーの配列を返します. + * * @return array */ public function getErrors() @@ -61,6 +74,8 @@ public function getErrors() } /** + * 決済が失敗した場合のエラーの配列を設定します. + * * @param array $errors * * @return PaymentResult @@ -73,6 +88,10 @@ public function setErrors(array $errors) } /** + * Response を設定します. + * + * 3Dセキュアなど, 決済中に他のサイトへリダイレクトが必要な特殊な用途に使用します. + * * @param Response $response * * @return PaymentResult @@ -85,6 +104,8 @@ public function setResponse(Response $response) } /** + * Response を返します. + * * @return Response */ public function getResponse() diff --git a/src/Eccube/Service/PaymentService.php b/src/Eccube/Service/PaymentService.php index fb489637996..b9d5c048555 100644 --- a/src/Eccube/Service/PaymentService.php +++ b/src/Eccube/Service/PaymentService.php @@ -21,7 +21,7 @@ /** * PaymentService * - * 必要に応じて決済代行会社ごとに継承して実装する + * 必要に応じて決済代行会社ごとに継承して実装すること */ class PaymentService { @@ -41,6 +41,11 @@ public function __construct(RequestStack $requestStack) } /** + * 他のコントローラに処理を移譲する. + * + * 注文確認画面→完了画面で呼ばれます. + * このメソッドは, 内部で PaymentMethod::apply() をコールし, 処理を移譲します. + * * @return PaymentDispatcher */ public function dispatch(PaymentMethod $method) @@ -48,10 +53,16 @@ public function dispatch(PaymentMethod $method) // PaymentMethod->apply に処理を移譲する // 別のコントローラに forward など - return $method->apply(); // Order 渡す + return $method->apply(); } /** + * 決済の妥当性を検証する. + * + * 注文入力画面→確認画面での入力チェックに利用します. + * 主にクレジットカードの有効性チェックに利用します. + * このメソッドは, 内部で PaymentMethod::verify() をコールします. + * * @return PaymentResult */ public function doVerify(PaymentMethod $method) @@ -64,6 +75,11 @@ public function doVerify(PaymentMethod $method) } /** + * 決済処理を実行します. + * + * 注文確認画面→完了画面で呼ばれます. + * このメソッドは, 内部で PeymentMethod::checkout() をコールします. + * * @return PaymentResult */ public function doCheckout(PaymentMethod $method) From 9d9a8b03326d4cf1ec403aa08cc05919f6bbd2a4 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 28 Jun 2018 10:50:06 +0900 Subject: [PATCH 2/5] Apply php-cs-fixer --- src/Eccube/Service/Payment/Method/Cash.php | 1 + src/Eccube/Service/Payment/PaymentDispatcher.php | 4 ++++ src/Eccube/Service/Payment/PaymentMethod.php | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/Eccube/Service/Payment/Method/Cash.php b/src/Eccube/Service/Payment/Method/Cash.php index 996f84a1cc9..81e270819c4 100644 --- a/src/Eccube/Service/Payment/Method/Cash.php +++ b/src/Eccube/Service/Payment/Method/Cash.php @@ -30,6 +30,7 @@ public function checkout() { $result = new PaymentResult(); $result->setSuccess(true); + return $result; } diff --git a/src/Eccube/Service/Payment/PaymentDispatcher.php b/src/Eccube/Service/Payment/PaymentDispatcher.php index a30d0b2b0f3..e266f23e77c 100644 --- a/src/Eccube/Service/Payment/PaymentDispatcher.php +++ b/src/Eccube/Service/Payment/PaymentDispatcher.php @@ -61,6 +61,7 @@ public function isForward() * Forward を使用する場合は true, Redirect を使用する場合は false を設定します. * * @param boolean $forward + * * @return PaymentDispatcher */ public function setForward($forward) @@ -84,6 +85,7 @@ public function getRoute() * 処理を移譲するルート名を設定します. * * @param string $route + * * @return PaymentDispatcher */ public function setRoute($route) @@ -107,6 +109,7 @@ public function getQueryParameters() * クエリパラメータの配列を設定します. * * @param array + * * @return PaymentDispatcher */ public function setQueryParameters(array $queryParameters) @@ -130,6 +133,7 @@ public function getPathParameters() * パスパラメータの配列を設定します. * * @param array + * * @return PaymentDispatcher */ public function setPathParameters(array $pathParameters) diff --git a/src/Eccube/Service/Payment/PaymentMethod.php b/src/Eccube/Service/Payment/PaymentMethod.php index 461f7ea2a66..db18b0f0182 100644 --- a/src/Eccube/Service/Payment/PaymentMethod.php +++ b/src/Eccube/Service/Payment/PaymentMethod.php @@ -55,6 +55,7 @@ public function apply(); * PaymentMethod の処理に必要な FormInterface を設定します. * * @param FormInterface + * * @return PaymentMethod */ public function setFormType(FormInterface $form); @@ -63,6 +64,7 @@ public function setFormType(FormInterface $form); * この決済を使用する Order を設定します. * * @param Order + * * @return PaymentMethod */ public function setOrder(Order $Order); From 274f1530ae1d0b18f4696f34525fe6470e929ad6 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 28 Jun 2018 13:21:25 +0900 Subject: [PATCH 3/5] =?UTF-8?q?PaymentMethod=20=E3=82=92=20PaymentMethodIn?= =?UTF-8?q?terface=20=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/Payment/Method/Cash.php | 4 +- .../Service/Payment/Method/CreditCard.php | 4 +- ...tMethod.php => PaymentMethodInterface.php} | 4 +- src/Eccube/Service/PaymentService.php | 16 ++--- .../Service/PaymentServiceInterface.php | 58 +++++++++++++++++++ 5 files changed, 72 insertions(+), 14 deletions(-) rename src/Eccube/Service/Payment/{PaymentMethod.php => PaymentMethodInterface.php} (96%) create mode 100644 src/Eccube/Service/PaymentServiceInterface.php diff --git a/src/Eccube/Service/Payment/Method/Cash.php b/src/Eccube/Service/Payment/Method/Cash.php index 81e270819c4..dc60e196577 100644 --- a/src/Eccube/Service/Payment/Method/Cash.php +++ b/src/Eccube/Service/Payment/Method/Cash.php @@ -14,14 +14,14 @@ 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} diff --git a/src/Eccube/Service/Payment/Method/CreditCard.php b/src/Eccube/Service/Payment/Method/CreditCard.php index e1b9ab5a577..fd80f3250e7 100644 --- a/src/Eccube/Service/Payment/Method/CreditCard.php +++ b/src/Eccube/Service/Payment/Method/CreditCard.php @@ -14,7 +14,7 @@ namespace Eccube\Service\Payment\Method; use Eccube\Entity\Order; -use Eccube\Service\Payment\PaymentMethod; +use Eccube\Service\Payment\PaymentMethodInterface; use Symfony\Component\Form\FormInterface; /** @@ -22,7 +22,7 @@ * * クレジットカード決済を実装する場合は, このクラスを継承します. */ -abstract class CreditCard implements PaymentMethod +abstract class CreditCard implements PaymentMethodInterface { /** * @var Order diff --git a/src/Eccube/Service/Payment/PaymentMethod.php b/src/Eccube/Service/Payment/PaymentMethodInterface.php similarity index 96% rename from src/Eccube/Service/Payment/PaymentMethod.php rename to src/Eccube/Service/Payment/PaymentMethodInterface.php index db18b0f0182..155327aa21c 100644 --- a/src/Eccube/Service/Payment/PaymentMethod.php +++ b/src/Eccube/Service/Payment/PaymentMethodInterface.php @@ -17,11 +17,11 @@ use Symfony\Component\Form\FormInterface; /** - * PaymentMethod + * PaymentMethodInterface * * 必要に応じて決済手段ごとに実装する */ -interface PaymentMethod +interface PaymentMethodInterface { /** * 決済の妥当性を検証し, 検証結果を返します. diff --git a/src/Eccube/Service/PaymentService.php b/src/Eccube/Service/PaymentService.php index b9d5c048555..f13c95ae2df 100644 --- a/src/Eccube/Service/PaymentService.php +++ b/src/Eccube/Service/PaymentService.php @@ -14,7 +14,7 @@ namespace Eccube\Service; use Eccube\Service\Payment\PaymentDispatcher; -use Eccube\Service\Payment\PaymentMethod; +use Eccube\Service\Payment\PaymentMethodInterface; use Eccube\Service\Payment\PaymentResult; use Symfony\Component\HttpFoundation\RequestStack; @@ -23,7 +23,7 @@ * * 必要に応じて決済代行会社ごとに継承して実装すること */ -class PaymentService +class PaymentService implements PaymentServiceInterface { /** * @var RequestStack @@ -44,11 +44,11 @@ public function __construct(RequestStack $requestStack) * 他のコントローラに処理を移譲する. * * 注文確認画面→完了画面で呼ばれます. - * このメソッドは, 内部で PaymentMethod::apply() をコールし, 処理を移譲します. + * このメソッドは, 内部で PaymentMethodInterface::apply() をコールし, 処理を移譲します. * * @return PaymentDispatcher */ - public function dispatch(PaymentMethod $method) + public function dispatch(PaymentMethodInterface $method) { // PaymentMethod->apply に処理を移譲する // 別のコントローラに forward など @@ -61,11 +61,11 @@ public function dispatch(PaymentMethod $method) * * 注文入力画面→確認画面での入力チェックに利用します. * 主にクレジットカードの有効性チェックに利用します. - * このメソッドは, 内部で PaymentMethod::verify() をコールします. + * このメソッドは, 内部で PaymentMethodInterface::verify() をコールします. * * @return PaymentResult */ - public function doVerify(PaymentMethod $method) + public function doVerify(PaymentMethodInterface $method) { // 注文入力画面→確認画面での入力チェックに利用する // 主にカードの有効性チェック等を行なう @@ -78,11 +78,11 @@ public function doVerify(PaymentMethod $method) * 決済処理を実行します. * * 注文確認画面→完了画面で呼ばれます. - * このメソッドは, 内部で PeymentMethod::checkout() をコールします. + * このメソッドは, 内部で PeymentMethodInterface::checkout() をコールします. * * @return PaymentResult */ - public function doCheckout(PaymentMethod $method) + public function doCheckout(PaymentMethodInterface $method) { // ここに EventDispatcher を仕掛けておけば,いろいろできるけど,やりすぎないで. $PaymentResult = $method->checkout(); diff --git a/src/Eccube/Service/PaymentServiceInterface.php b/src/Eccube/Service/PaymentServiceInterface.php new file mode 100644 index 00000000000..76a7f0802f4 --- /dev/null +++ b/src/Eccube/Service/PaymentServiceInterface.php @@ -0,0 +1,58 @@ + Date: Thu, 28 Jun 2018 14:43:14 +0900 Subject: [PATCH 4/5] =?UTF-8?q?PaymentMethod,=20PaymentService=20=E3=82=92?= =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=86=E3=83=8A=E3=81=8B=E3=82=89=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/config/eccube/services.yaml | 8 ---- src/Eccube/Controller/ShoppingController.php | 9 +--- .../Compiler/PaymentMethodPass.php | 41 +++++++++++++++++++ .../Compiler/PaymentServicePass.php | 41 +++++++++++++++++++ src/Eccube/Kernel.php | 14 +++++++ 5 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php create mode 100644 src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php diff --git a/app/config/eccube/services.yaml b/app/config/eccube/services.yaml index 958879f8acd..72fd1f204af 100644 --- a/app/config/eccube/services.yaml +++ b/app/config/eccube/services.yaml @@ -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 diff --git a/src/Eccube/Controller/ShoppingController.php b/src/Eccube/Controller/ShoppingController.php index 9e1595bdf9f..8cc6d07f727 100644 --- a/src/Eccube/Controller/ShoppingController.php +++ b/src/Eccube/Controller/ShoppingController.php @@ -961,17 +961,12 @@ 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); diff --git a/src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php b/src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php new file mode 100644 index 00000000000..218c82e9aa7 --- /dev/null +++ b/src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php @@ -0,0 +1,41 @@ +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); + } + } +} diff --git a/src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php b/src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php new file mode 100644 index 00000000000..bb9b429f240 --- /dev/null +++ b/src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php @@ -0,0 +1,41 @@ +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); + } + } +} diff --git a/src/Eccube/Kernel.php b/src/Eccube/Kernel.php index a8a5a8a7cd7..c0a751a66b3 100644 --- a/src/Eccube/Kernel.php +++ b/src/Eccube/Kernel.php @@ -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; @@ -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; @@ -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) From 7dba2abbeed6de9a2df96653f5bbdaeba48d1d6a Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 28 Jun 2018 14:55:03 +0900 Subject: [PATCH 5/5] Apply php-cs-fixer --- src/Eccube/Controller/ShoppingController.php | 1 + src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php | 1 - src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php | 1 - src/Eccube/Service/PaymentServiceInterface.php | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Eccube/Controller/ShoppingController.php b/src/Eccube/Controller/ShoppingController.php index 8cc6d07f727..8d556af437e 100644 --- a/src/Eccube/Controller/ShoppingController.php +++ b/src/Eccube/Controller/ShoppingController.php @@ -961,6 +961,7 @@ public function afterComplete(Request $request) private function createPaymentService(Order $Order) { $serviceClass = $Order->getPayment()->getServiceClass(); + return $this->container->get($serviceClass); } diff --git a/src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php b/src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php index 218c82e9aa7..fe00f715be4 100644 --- a/src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php +++ b/src/Eccube/DependencyInjection/Compiler/PaymentMethodPass.php @@ -26,7 +26,6 @@ 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()); diff --git a/src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php b/src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php index bb9b429f240..71f7101aa2e 100644 --- a/src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php +++ b/src/Eccube/DependencyInjection/Compiler/PaymentServicePass.php @@ -26,7 +26,6 @@ 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()); diff --git a/src/Eccube/Service/PaymentServiceInterface.php b/src/Eccube/Service/PaymentServiceInterface.php index 76a7f0802f4..7c4223ad434 100644 --- a/src/Eccube/Service/PaymentServiceInterface.php +++ b/src/Eccube/Service/PaymentServiceInterface.php @@ -16,7 +16,6 @@ use Eccube\Service\Payment\PaymentDispatcher; use Eccube\Service\Payment\PaymentMethodInterface; use Eccube\Service\Payment\PaymentResult; -use Symfony\Component\HttpFoundation\RequestStack; /** * PaymentService