From 860f885dc19b9c2ecc4d977d9486365a4c42388b Mon Sep 17 00:00:00 2001 From: Mantas Date: Wed, 12 Apr 2023 13:41:28 +0300 Subject: [PATCH] SL-158-league-service-container --- composer.json | 3 +- config/config.yml | 49 --- config/index.php | 32 -- config/repository.yml | 27 -- config/service.yml | 288 ------------------ .../AdminSaferPayOfficialOrderController.php | 6 +- ...AdminSaferPayOfficialPaymentController.php | 32 +- ...dminSaferPayOfficialSettingsController.php | 2 +- controllers/front/ajax.php | 6 +- controllers/front/creditCards.php | 2 +- controllers/front/creditCards16.php | 2 +- controllers/front/failValidation.php | 4 +- controllers/front/iframe.php | 6 +- controllers/front/notify.php | 4 +- controllers/front/pendingNotify.php | 6 +- controllers/front/successHosted.php | 4 +- controllers/front/successIFrame.php | 4 +- controllers/front/validation.php | 7 +- saferpayofficial.php | 82 ++--- .../OrderConfirmationMessageTemplate.php | 12 +- src/Factory/ModuleFactory.php | 22 ++ .../Loader/PaymentFormAssetLoader.php | 15 +- src/Provider/PaymentRedirectionProvider.php | 24 +- src/Service/LegacyTranslator.php | 8 +- src/Service/SaferPayCartService.php | 7 +- src/Service/SaferPayExceptionService.php | 7 +- src/Service/SaferPayInitialize.php | 16 +- src/Service/SaferPayOrderStatusService.php | 8 +- .../SaferPayTransactionAuthorization.php | 6 +- src/ServiceProvider/BaseServiceProvider.php | 61 ++++ .../LeagueServiceContainerProvider.php | 50 +++ .../ServiceContainerProviderInterface.php | 34 +++ 32 files changed, 285 insertions(+), 551 deletions(-) delete mode 100755 config/config.yml delete mode 100755 config/index.php delete mode 100755 config/repository.yml delete mode 100755 config/service.yml create mode 100755 src/Factory/ModuleFactory.php create mode 100755 src/ServiceProvider/BaseServiceProvider.php create mode 100755 src/ServiceProvider/LeagueServiceContainerProvider.php create mode 100755 src/ServiceProvider/ServiceContainerProviderInterface.php diff --git a/composer.json b/composer.json index 1ad6c41aa..019a5c446 100755 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "symfony/dependency-injection": "^3.4", "symfony/filesystem": "^3.4", "apimatic/unirest-php": "^2.3", - "symfony/yaml": "^3.4" + "symfony/yaml": "^3.4", + "league/container": "2.5.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "*", diff --git a/config/config.yml b/config/config.yml deleted file mode 100755 index 026d8a458..000000000 --- a/config/config.yml +++ /dev/null @@ -1,49 +0,0 @@ -imports: - - { resource: service.yml } - - { resource: repository.yml } - -services: - _defaults: - public: true - - saferpay: - class: 'SaferPayOfficial' - factory: ['Module', 'getInstanceByName'] - arguments: - - 'saferpayofficial' - - config: - class: Invertus\SaferPay\Config\SaferPayConfig - - api.request: - class: 'Invertus\SaferPay\Api\ApiRequest' - - saferpay.order.repository: - class: Invertus\SaferPay\Repository\SaferPayOrderRepository - - object.creator.auth: - class: Invertus\SaferPay\Service\Response\AuthorizationResponseObjectCreator - - #todo: task if its better to just call context in constructor - adapter.context: - class: Invertus\SaferPay\Adapter\LegacyContext - - Invertus\SaferPay\EntityBuilder\SaferPayAssertBuilder: - class: Invertus\SaferPay\EntityBuilder\SaferPayAssertBuilder - - Invertus\SaferPay\EntityBuilder\SaferPayAssertRefundBuilder: - class: Invertus\SaferPay\EntityBuilder\SaferPayAssertRefundBuilder - - Invertus\SaferPay\EntityBuilder\SaferPayCardAliasBuilder: - class: Invertus\SaferPay\EntityBuilder\SaferPayCardAliasBuilder - arguments: - - '@Invertus\SaferPay\Repository\SaferPayCardAliasRepository' - - Invertus\SaferPay\EntityBuilder\SaferPayOrderBuilder: - class: Invertus\SaferPay\EntityBuilder\SaferPayOrderBuilder - - Invertus\SaferPay\Presentation\Loader\PaymentFormAssetLoader: - class: Invertus\SaferPay\Presentation\Loader\PaymentFormAssetLoader - arguments: - - '@saferpay' - - '@=service("adapter.context").getContext()' diff --git a/config/index.php b/config/index.php deleted file mode 100755 index eeb2b1cf3..000000000 --- a/config/index.php +++ /dev/null @@ -1,32 +0,0 @@ - - *@copyright SIX Payment Services - *@license SIX Payment Services - */ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/config/repository.yml b/config/repository.yml deleted file mode 100755 index 6873012f6..000000000 --- a/config/repository.yml +++ /dev/null @@ -1,27 +0,0 @@ -services: - _defaults: - public: true - - Invertus\SaferPay\Repository\SaferPayLogoRepository: - class: Invertus\SaferPay\Repository\SaferPayLogoRepository - - Invertus\SaferPay\Repository\SaferPayOrderRepository: - class: Invertus\SaferPay\Repository\SaferPayOrderRepository - - Invertus\SaferPay\Repository\SaferPayPaymentRepository: - class: Invertus\SaferPay\Repository\SaferPayPaymentRepository - - Invertus\SaferPay\Repository\SaferPayRestrictionRepository: - class: Invertus\SaferPay\Repository\SaferPayRestrictionRepository - - Invertus\SaferPay\Repository\SaferPayCardAliasRepository: - class: Invertus\SaferPay\Repository\SaferPayCardAliasRepository - - Invertus\SaferPay\Repository\SaferPaySavedCreditCardRepository: - class: Invertus\SaferPay\Repository\SaferPaySavedCreditCardRepository - - Invertus\SaferPay\Repository\SaferPayFieldRepository: - class: Invertus\SaferPay\Repository\SaferPayFieldRepository - - Invertus\SaferPay\Repository\OrderRepository: - class: Invertus\SaferPay\Repository\OrderRepository \ No newline at end of file diff --git a/config/service.yml b/config/service.yml deleted file mode 100755 index 9fb59ba31..000000000 --- a/config/service.yml +++ /dev/null @@ -1,288 +0,0 @@ -services: - _defaults: - public: true - - Invertus\SaferPay\Service\SaferPayCartService: - class: Invertus\SaferPay\Service\SaferPayCartService - arguments: - - '@saferpay' - - Invertus\SaferPay\Api\Request\InitializeService: - class: Invertus\SaferPay\Api\Request\InitializeService - arguments: - - '@api.request' - - Invertus\SaferPay\Api\Request\AssertService: - class: Invertus\SaferPay\Api\Request\AssertService - arguments: - - '@api.request' - - '@Invertus\SaferPay\Service\Response\AssertResponseObjectCreator' - - '@Invertus\SaferPay\EntityBuilder\SaferPayAssertBuilder' - - Invertus\SaferPay\Api\Request\AssertRefundService: - class: Invertus\SaferPay\Api\Request\AssertRefundService - arguments: - - '@api.request' - - '@Invertus\SaferPay\Service\Response\AssertRefundResponseObjectCreator' - - '@Invertus\SaferPay\EntityBuilder\SaferPayAssertRefundBuilder' - - Invertus\SaferPay\Api\Request\CaptureService: - class: Invertus\SaferPay\Api\Request\CaptureService - arguments: - - '@api.request' - - Invertus\SaferPay\Api\Request\CancelService: - class: Invertus\SaferPay\Api\Request\CancelService - arguments: - - '@api.request' - - Invertus\SaferPay\Api\Request\RefundService: - class: Invertus\SaferPay\Api\Request\RefundService - arguments: - - '@api.request' - - Invertus\SaferPay\Service\Request\RequestObjectCreator: - class: Invertus\SaferPay\Service\Request\RequestObjectCreator - arguments: - - '@saferpay' - - '@Invertus\SaferPay\Utility\PriceUtility' - - '@Invertus\SaferPay\Repository\OrderRepository' - - '@Invertus\SaferPay\Provider\IdempotencyProviderInterface' - - Invertus\SaferPay\Api\Request\AuthorizationService: - class: Invertus\SaferPay\Api\Request\AuthorizationService - arguments: - - '@api.request' - - '@Invertus\SaferPay\Service\Response\AssertResponseObjectCreator' - - '@Invertus\SaferPay\EntityBuilder\SaferPayAssertBuilder' - - '@Invertus\SaferPay\EntityBuilder\SaferPayCardAliasBuilder' - - Invertus\SaferPay\Service\SaferPayInitialize: - class: Invertus\SaferPay\Service\SaferPayInitialize - arguments: - - '@saferpay' - - '@=service("adapter.context").getContext()' - - '@Invertus\SaferPay\Api\Request\InitializeService' - - '@Invertus\SaferPay\Service\Request\InitializeRequestObjectCreator' - - #Request object creator - Invertus\SaferPay\Service\Request\AssertRequestObjectCreator: - class: Invertus\SaferPay\Service\Request\AssertRequestObjectCreator - arguments: - - '@Invertus\SaferPay\Service\Request\RequestObjectCreator' - - '@Invertus\SaferPay\Repository\SaferPayOrderRepository' - - Invertus\SaferPay\Service\Request\AssertRefundRequestObjectCreator: - class: Invertus\SaferPay\Service\Request\AssertRefundRequestObjectCreator - arguments: - - '@Invertus\SaferPay\Service\Request\RequestObjectCreator' - - Invertus\SaferPay\Service\Request\AuthorizationRequestObjectCreator: - class: Invertus\SaferPay\Service\Request\AuthorizationRequestObjectCreator - arguments: - - '@Invertus\SaferPay\Service\Request\RequestObjectCreator' - - Invertus\SaferPay\Service\Request\CaptureRequestObjectCreator: - class: Invertus\SaferPay\Service\Request\CaptureRequestObjectCreator - arguments: - - '@Invertus\SaferPay\Service\Request\RequestObjectCreator' - - Invertus\SaferPay\Service\Request\InitializeRequestObjectCreator: - class: Invertus\SaferPay\Service\Request\InitializeRequestObjectCreator - arguments: - - '@Invertus\SaferPay\Service\Request\RequestObjectCreator' - - Invertus\SaferPay\Service\Request\CancelRequestObjectCreator: - class: Invertus\SaferPay\Service\Request\CancelRequestObjectCreator - arguments: - - '@Invertus\SaferPay\Service\Request\RequestObjectCreator' - - Invertus\SaferPay\Service\Request\RefundRequestObjectCreator: - class: Invertus\SaferPay\Service\Request\RefundRequestObjectCreator - arguments: - - '@Invertus\SaferPay\Service\Request\RequestObjectCreator' - - Invertus\SaferPay\Service\Request\ObtainPaymentMethodsObjectCreator: - class: Invertus\SaferPay\Service\Request\ObtainPaymentMethodsObjectCreator - arguments: - - '@Invertus\SaferPay\Service\Request\RequestObjectCreator' - # - - #Response object creator - Invertus\SaferPay\Service\Response\AssertResponseObjectCreator: - class: Invertus\SaferPay\Service\Response\AssertResponseObjectCreator - - Invertus\SaferPay\Service\Response\AssertRefundResponseObjectCreator: - class: Invertus\SaferPay\Service\Response\AssertRefundResponseObjectCreator - - Invertus\SaferPay\Service\Response\AuthorizationResponseObjectCreator: - class: Invertus\SaferPay\Service\Response\AuthorizationResponseObjectCreator - - Invertus\SaferPay\Service\Response\InitializeResponseObjectCreator: - class: Invertus\SaferPay\Service\Response\InitializeResponseObjectCreator - - Invertus\SaferPay\Service\Response\ResponseObjectCreator: - class: Invertus\SaferPay\Service\Response\ResponseObjectCreator - # - Invertus\SaferPay\Service\PaymentRestrictionValidation: - class: Invertus\SaferPay\Service\PaymentRestrictionValidation - arguments: - - '@Invertus\SaferPay\Provider\PaymentRestrictionProvider' - - Invertus\SaferPay\Service\SaferPayLogoCreator: - class: Invertus\SaferPay\Service\SaferPayLogoCreator - arguments: - - '@Invertus\SaferPay\Repository\SaferPayLogoRepository' - - Invertus\SaferPay\Service\SaferPayFieldCreator: - class: Invertus\SaferPay\Service\SaferPayFieldCreator - arguments: - - '@Invertus\SaferPay\Repository\SaferPayFieldRepository' - - Invertus\SaferPay\Service\SaferPayPaymentCreator: - class: Invertus\SaferPay\Service\SaferPayPaymentCreator - arguments: - - '@Invertus\SaferPay\Repository\SaferPayPaymentRepository' - - Invertus\SaferPay\Service\SaferPayRestrictionCreator: - class: Invertus\SaferPay\Service\SaferPayRestrictionCreator - arguments: - - '@Invertus\SaferPay\Repository\SaferPayRestrictionRepository' - - Invertus\SaferPay\Service\SaferPayOrderStatusService: - class: Invertus\SaferPay\Service\SaferPayOrderStatusService - arguments: - - '@Invertus\SaferPay\Api\Request\CaptureService' - - '@Invertus\SaferPay\Service\Request\CaptureRequestObjectCreator' - - '@Invertus\SaferPay\Repository\SaferPayOrderRepository' - - '@Invertus\SaferPay\Api\Request\CancelService' - - '@Invertus\SaferPay\Service\Request\CancelRequestObjectCreator' - - '@Invertus\SaferPay\Api\Request\RefundService' - - '@Invertus\SaferPay\Service\Request\RefundRequestObjectCreator' - - '@=service("adapter.context")' - - '@saferpay' - - Invertus\SaferPay\Service\SaferPayExceptionService: - class: Invertus\SaferPay\Service\SaferPayExceptionService - arguments: - - '@saferpay' - - Invertus\SaferPay\Service\SaferPayErrorDisplayService: - class: Invertus\SaferPay\Service\SaferPayErrorDisplayService - - Invertus\SaferPay\Service\CartDuplicationService: - class: Invertus\SaferPay\Service\CartDuplicationService - - Invertus\SaferPay\Builder\OrderConfirmationMessageTemplate: - class: Invertus\SaferPay\Builder\OrderConfirmationMessageTemplate - arguments: - - '@saferpay' - - Invertus\SaferPay\Service\PaymentRestrictionValidation\BasePaymentRestrictionValidation: - class: Invertus\SaferPay\Service\PaymentRestrictionValidation\BasePaymentRestrictionValidation - arguments: - - '@=service("adapter.context")' - - '@Invertus\SaferPay\Repository\SaferPayPaymentRepository' - - '@Invertus\SaferPay\Repository\SaferPayRestrictionRepository' - - '@Invertus\SaferPay\Service\SaferPayObtainPaymentMethods' - tags: - - { name: saferpay.paymentrestriction } - - Invertus\SaferPay\Service\PaymentRestrictionValidation\KlarnaPaymentRestrictionValidation: - class: Invertus\SaferPay\Service\PaymentRestrictionValidation\KlarnaPaymentRestrictionValidation - arguments: - - '@=service("adapter.context")' - tags: - - { name: saferpay.paymentrestriction } - - Invertus\SaferPay\Service\PaymentRestrictionValidation\ApplePayPaymentRestrictionValidation: - class: Invertus\SaferPay\Service\PaymentRestrictionValidation\ApplePayPaymentRestrictionValidation - arguments: - - '@=service("adapter.context")' - tags: - - { name: saferpay.paymentrestriction } - - Invertus\SaferPay\Utility\PriceUtility: - class: Invertus\SaferPay\Utility\PriceUtility - - Invertus\SaferPay\Provider\PaymentRedirectionProvider: - class: Invertus\SaferPay\Provider\PaymentRedirectionProvider - arguments: - - '@=service("adapter.context").getContext()' - - '@=service("saferpay").name' - - '@Invertus\SaferPay\Provider\PaymentTypeProvider' - - Invertus\SaferPay\Provider\PaymentRestrictionProvider: - class: Invertus\SaferPay\Provider\PaymentRestrictionProvider - arguments: - - '@Invertus\SaferPay\Service\PaymentRestrictionValidation\ApplePayPaymentRestrictionValidation' - - '@Invertus\SaferPay\Service\PaymentRestrictionValidation\BasePaymentRestrictionValidation' - - '@Invertus\SaferPay\Service\PaymentRestrictionValidation\KlarnaPaymentRestrictionValidation' - - Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization: - class: Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization - arguments: - - '@Invertus\SaferPay\Service\Request\AuthorizationRequestObjectCreator' - - '@Invertus\SaferPay\Repository\SaferPayOrderRepository' - - '@Invertus\SaferPay\Api\Request\AuthorizationService' - - '@Invertus\SaferPay\Service\SaferPayOrderStatusService' - - '@=service("adapter.context").getContext()' - - Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion: - class: Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion - arguments: - - '@Invertus\SaferPay\Service\Request\AssertRequestObjectCreator' - - '@Invertus\SaferPay\Repository\SaferPayOrderRepository' - - '@Invertus\SaferPay\Api\Request\AssertService' - - '@Invertus\SaferPay\Service\SaferPayOrderStatusService' - - Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionRefundAssertion: - class: Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionRefundAssertion - arguments: - - '@Invertus\SaferPay\Service\Request\AssertRefundRequestObjectCreator' - - '@Invertus\SaferPay\Repository\SaferPayOrderRepository' - - '@Invertus\SaferPay\Api\Request\AssertRefundService' - - '@Invertus\SaferPay\Service\SaferPayOrderStatusService' - - Invertus\SaferPay\Service\LegacyTranslator: - class: Invertus\SaferPay\Service\LegacyTranslator - arguments: - - '@saferpay' - - Invertus\SaferPay\Api\Request\ObtainPaymentMethodsService: - class: Invertus\SaferPay\Api\Request\ObtainPaymentMethodsService - arguments: - - '@api.request' - - Invertus\SaferPay\Service\SaferPayObtainPaymentMethods: - class: Invertus\SaferPay\Service\SaferPayObtainPaymentMethods - arguments: -# - '@saferpay' -# - '@=service("adapter.context").getContext()' - - '@Invertus\SaferPay\Api\Request\ObtainPaymentMethodsService' - - '@Invertus\SaferPay\Service\Request\ObtainPaymentMethodsObjectCreator' - - '@Invertus\SaferPay\Service\SaferPayPaymentNotation' - - Invertus\SaferPay\Service\SaferPayRefreshPaymentsService: - class: Invertus\SaferPay\Service\SaferPayRefreshPaymentsService - arguments: - - '@Invertus\SaferPay\Repository\SaferPayPaymentRepository' - - '@Invertus\SaferPay\Service\SaferPayObtainPaymentMethods' - - '@Invertus\SaferPay\Repository\SaferPayRestrictionRepository' - - '@Invertus\SaferPay\Repository\SaferPayFieldRepository' - - Invertus\SaferPay\Service\SaferPayMailService: - class: Invertus\SaferPay\Service\SaferPayMailService - - Invertus\SaferPay\Service\SaferPayPaymentNotation: - class: Invertus\SaferPay\Service\SaferPayPaymentNotation - - Invertus\SaferPay\Provider\PaymentTypeProvider: - class: Invertus\SaferPay\Provider\PaymentTypeProvider - arguments: - - '@Invertus\SaferPay\Repository\SaferPayFieldRepository' - - Invertus\SaferPay\Provider\BasicIdempotencyProvider: - class: Invertus\SaferPay\Provider\BasicIdempotencyProvider - - Invertus\SaferPay\Provider\IdempotencyProviderInterface: '@Invertus\SaferPay\Provider\BasicIdempotencyProvider' \ No newline at end of file diff --git a/controllers/admin/AdminSaferPayOfficialOrderController.php b/controllers/admin/AdminSaferPayOfficialOrderController.php index 243e30305..6d14f4f8a 100755 --- a/controllers/admin/AdminSaferPayOfficialOrderController.php +++ b/controllers/admin/AdminSaferPayOfficialOrderController.php @@ -32,8 +32,7 @@ public function __construct() public function postProcess() { /** @var \Invertus\SaferPay\Service\SaferPayOrderStatusService $orderStatusService */ - $orderStatusService = $this->module->getModuleContainer() - ->get(\Invertus\SaferPay\Service\SaferPayOrderStatusService::class); + $orderStatusService = $this->module->getService(\Invertus\SaferPay\Service\SaferPayOrderStatusService::class); if (\Invertus\SaferPay\Config\SaferPayConfig::isVersionAbove177()) { $orderId = Tools::getValue('orderId'); @@ -56,8 +55,7 @@ public function postProcess() } } catch (Invertus\SaferPay\Exception\Api\SaferPayApiException $e) { /** @var \Invertus\SaferPay\Service\SaferPayExceptionService $exceptionService */ - $exceptionService = $this->module->getModuleContainer() - ->get(\Invertus\SaferPay\Service\SaferPayExceptionService::class); + $exceptionService = $this->module->getService(\Invertus\SaferPay\Service\SaferPayExceptionService::class); $saferPayErrors = json_decode($this->context->cookie->saferPayErrors, true); $saferPayErrors[$orderId] = $exceptionService->getErrorMessageForException( $e, diff --git a/controllers/admin/AdminSaferPayOfficialPaymentController.php b/controllers/admin/AdminSaferPayOfficialPaymentController.php index b9be34bd5..ce67fb90d 100755 --- a/controllers/admin/AdminSaferPayOfficialPaymentController.php +++ b/controllers/admin/AdminSaferPayOfficialPaymentController.php @@ -59,7 +59,7 @@ public function postProcess() { // Refresh payments. /** @var SaferPayRefreshPaymentsService $refreshPaymentsService */ - $refreshPaymentsService = $this->module->getModuleContainer()->get(SaferPayRefreshPaymentsService::class); + $refreshPaymentsService = $this->module->getService(SaferPayRefreshPaymentsService::class); try { $refreshPaymentsService->refreshPayments(); } catch (SaferPayApiException $exception) { @@ -71,16 +71,16 @@ public function postProcess() } /** @var SaferPayPaymentCreator $paymentCreation */ - $paymentCreation = $this->module->getModuleContainer()->get(SaferPayPaymentCreator::class); + $paymentCreation = $this->module->getService(SaferPayPaymentCreator::class); /** @var SaferPayLogoCreator $logoCreation */ - $logoCreation = $this->module->getModuleContainer()->get(SaferPayLogoCreator::class); + $logoCreation = $this->module->getService(SaferPayLogoCreator::class); /** @var SaferPayFieldCreator $fieldCreation */ - $fieldCreation = $this->module->getModuleContainer()->get(SaferPayFieldCreator::class); + $fieldCreation = $this->module->getService(SaferPayFieldCreator::class); /** @var SaferPayRestrictionCreator $restrictionCreator */ - $restrictionCreator = $this->module->getModuleContainer()->get(SaferPayRestrictionCreator::class); + $restrictionCreator = $this->module->getService(SaferPayRestrictionCreator::class); $paymentMethods = $this->getPaymentMethods(); if (is_null($paymentMethods)) { @@ -137,16 +137,16 @@ protected function renderShoppingPointOptions() $referralOptionsForm = new HelperForm(); /** @var SaferPayPaymentRepository $paymentRepository */ - $paymentRepository = $this->module->getModuleContainer()->get(SaferPayPaymentRepository::class); + $paymentRepository = $this->module->getService(SaferPayPaymentRepository::class); /** @var SaferPayLogoRepository $logoRepository */ - $logoRepository = $this->module->getModuleContainer()->get(SaferPayLogoRepository::class); + $logoRepository = $this->module->getService(SaferPayLogoRepository::class); /** @var SaferPayLogoRepository $fieldsRepository */ - $fieldRepository = $this->module->getModuleContainer()->get(SaferPayFieldRepository::class); + $fieldRepository = $this->module->getService(SaferPayFieldRepository::class); /** @var SaferPayRestrictionRepository $restrictionRepository */ - $restrictionRepository = $this->module->getModuleContainer()->get(SaferPayRestrictionRepository::class); + $restrictionRepository = $this->module->getService(SaferPayRestrictionRepository::class); $paymentMethods = $this->getPaymentMethods(); if (is_null($paymentMethods)) { @@ -215,7 +215,7 @@ public function getActiveCountriesList($onlyActive = true) public function getActiveCurrenciesList($paymentMethod) { /** @var \Invertus\SaferPay\Service\SaferPayObtainPaymentMethods $saferPayObtainPaymentMethods */ - $saferPayObtainPaymentMethods = $this->module->getModuleContainer()->get(SaferPayObtainPaymentMethods::class); + $saferPayObtainPaymentMethods = $this->module->getService(SaferPayObtainPaymentMethods::class); $paymentMethods = $saferPayObtainPaymentMethods->obtainPaymentMethods(); @@ -245,12 +245,11 @@ protected function initForm() try { /** @var \Invertus\SaferPay\Service\SaferPayObtainPaymentMethods $saferPayObtainPaymentMethods */ - $saferPayObtainPaymentMethods = $this->module->getModuleContainer()->get(SaferPayObtainPaymentMethods::class); + $saferPayObtainPaymentMethods = $this->module->getService(SaferPayObtainPaymentMethods::class); $paymentMethods = $saferPayObtainPaymentMethods->obtainPaymentMethodsNamesAsArray(); } catch (SaferPayApiException $exception) { /** @var \Invertus\SaferPay\Service\SaferPayExceptionService $exceptionService */ - $exceptionService = $this->module->getModuleContainer() - ->get(\Invertus\SaferPay\Service\SaferPayExceptionService::class); + $exceptionService = $this->module->getService(\Invertus\SaferPay\Service\SaferPayExceptionService::class); $saferPayErrors = json_decode($this->context->cookie->saferPayErrors, true); $saferPayErrors[] = $exceptionService->getErrorMessageForException( $exception, @@ -263,7 +262,7 @@ protected function initForm() return; } /** @var \Invertus\SaferPay\Service\SaferPayPaymentNotation $saferPayPaymentNotation */ - $saferPayPaymentNotation = $this->module->getModuleContainer()->get(SaferPayPaymentNotation::class); + $saferPayPaymentNotation = $this->module->getService(SaferPayPaymentNotation::class); foreach ($paymentMethods as $paymentMethod) { $fields[] = [ @@ -290,13 +289,12 @@ private function getPaymentMethods() { try { /** @var \Invertus\SaferPay\Service\SaferPayObtainPaymentMethods $saferPayObtainPaymentMethods */ - $saferPayObtainPaymentMethods = $this->module->getModuleContainer()->get(SaferPayObtainPaymentMethods::class); + $saferPayObtainPaymentMethods = $this->module->getService(SaferPayObtainPaymentMethods::class); return $saferPayObtainPaymentMethods->obtainPaymentMethodsNamesAsArray(); } catch (SaferPayApiException $exception) { /** @var \Invertus\SaferPay\Service\SaferPayExceptionService $exceptionService */ - $exceptionService = $this->module->getModuleContainer() - ->get(\Invertus\SaferPay\Service\SaferPayExceptionService::class); + $exceptionService = $this->module->getService(\Invertus\SaferPay\Service\SaferPayExceptionService::class); $saferPayErrors = json_decode($this->context->cookie->saferPayErrors, true); $saferPayErrors[] = $exceptionService->getErrorMessageForException( $exception, diff --git a/controllers/admin/AdminSaferPayOfficialSettingsController.php b/controllers/admin/AdminSaferPayOfficialSettingsController.php index f1cc866dc..0b7e0f160 100755 --- a/controllers/admin/AdminSaferPayOfficialSettingsController.php +++ b/controllers/admin/AdminSaferPayOfficialSettingsController.php @@ -51,7 +51,7 @@ public function postProcess() $isCreditCardSaveEnabled = Configuration::get(SaferPayConfig::CREDIT_CARD_SAVE); if (!$isCreditCardSaveEnabled) { /** @var SaferPaySavedCreditCardRepository $cardRepo */ - $cardRepo = $this->module->getModuleContainer()->get(SaferPaySavedCreditCardRepository::class); + $cardRepo = $this->module->getService(SaferPaySavedCreditCardRepository::class); $cardRepo->deleteAllSavedCreditCards(); } } diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index e314f58bf..58d74f7ef 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -45,14 +45,14 @@ private function submitHostedFields() } /** @var SaferPayCardAliasRepository $cardAliasRep */ - $cardAliasRep = $this->module->getModuleContainer()->get(SaferPayCardAliasRepository::class); + $cardAliasRep = $this->module->getService(SaferPayCardAliasRepository::class); $selectedCard = Tools::getValue('selectedCard'); $alias = $cardAliasRep->getSavedCardAliasFromId($selectedCard); /** @var SaferPayInitialize $initializeService */ - $initializeService = $this->module->getModuleContainer()->get(SaferPayInitialize::class); + $initializeService = $this->module->getService(SaferPayInitialize::class); $initializeBody = $initializeService->initialize( Tools::getValue('paymentMethod'), (int) Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE), @@ -105,7 +105,7 @@ private function getRedirectionUrl($initializeBody) private function createSaferPayOrder($initializeBody) { /** @var Invertus\SaferPay\EntityBuilder\SaferPayOrderBuilder $saferPayOrderBuilder */ - $saferPayOrderBuilder = $this->module->getModuleContainer()->get(SaferPayOrderBuilder::class); + $saferPayOrderBuilder = $this->module->getService(SaferPayOrderBuilder::class); $saferPayOrderBuilder->create( $initializeBody, $this->context->cart, diff --git a/controllers/front/creditCards.php b/controllers/front/creditCards.php index a775822a0..423dae94d 100755 --- a/controllers/front/creditCards.php +++ b/controllers/front/creditCards.php @@ -51,7 +51,7 @@ private function initCardList() { $customerId = $this->context->customer->id; /** @var SaferPayCardAliasRepository $cardAliasRep */ - $cardAliasRep = $this->module->getModuleContainer()->get(SaferPayCardAliasRepository::class); + $cardAliasRep = $this->module->getService(SaferPayCardAliasRepository::class); $savedCustomerCards = $cardAliasRep->getSavedCardsByCustomerId($customerId); $rows = []; foreach ($savedCustomerCards as $savedCard) { diff --git a/controllers/front/creditCards16.php b/controllers/front/creditCards16.php index 3be8a1e80..281b81c46 100755 --- a/controllers/front/creditCards16.php +++ b/controllers/front/creditCards16.php @@ -59,7 +59,7 @@ private function initCardList() { $customerId = $this->context->customer->id; /** @var SaferPayCardAliasRepository $cardAliasRep */ - $cardAliasRep = $this->module->getModuleContainer()->get(SaferPayCardAliasRepository::class); + $cardAliasRep = $this->module->getService(SaferPayCardAliasRepository::class); $savedCustomerCards = $cardAliasRep->getSavedCardsByCustomerId($customerId); $rows = []; foreach ($savedCustomerCards as $savedCard) { diff --git a/controllers/front/failValidation.php b/controllers/front/failValidation.php index 8cc932f40..ca805f17a 100755 --- a/controllers/front/failValidation.php +++ b/controllers/front/failValidation.php @@ -52,8 +52,8 @@ public function postProcess() $order->setCurrentState(_SAFERPAY_PAYMENT_AUTHORIZATION_FAILED_); /** @var SaferPayOrderRepository $orderRepo */ /** @var CartDuplicationService $cartDuplicationService */ - $orderRepo = $this->module->getModuleContainer()->get('saferpay.order.repository'); - $cartDuplicationService = $this->module->getModuleContainer()->get(CartDuplicationService::class); + $orderRepo = $this->module->getService('saferpay.order.repository'); + $cartDuplicationService = $this->module->getService(CartDuplicationService::class); $saferPayOrderId = $orderRepo->getIdByOrderId($orderId); $saferPayOrder = new SaferPayOrder($saferPayOrderId); diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index cb42c231e..58f355dc2 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -99,14 +99,14 @@ public function initContent() $selectedCard = Tools::getValue("saved_card_{$paymentMethod}"); } /** @var SaferPayOrderBuilder $saferPayOrderBuilder */ - $saferPayOrderBuilder = $this->module->getModuleContainer()->get(SaferPayOrderBuilder::class); + $saferPayOrderBuilder = $this->module->getService(SaferPayOrderBuilder::class); $isBusinessLicence = Tools::getValue(\Invertus\SaferPay\Config\SaferPayConfig::IS_BUSINESS_LICENCE); /** @var SaferPayInitialize $initializeService */ - $initializeService = $this->module->getModuleContainer()->get(SaferPayInitialize::class); + $initializeService = $this->module->getService(SaferPayInitialize::class); try { /** @var SaferPayCardAliasRepository $cardAliasRep */ - $cardAliasRep = $this->module->getModuleContainer()->get(SaferPayCardAliasRepository::class); + $cardAliasRep = $this->module->getService(SaferPayCardAliasRepository::class); $alias = $cardAliasRep->getSavedCardAliasFromId($selectedCard); $response = $initializeService->initialize($paymentMethod, $isBusinessLicence, $selectedCard, $alias); } catch (Exception $e) { diff --git a/controllers/front/notify.php b/controllers/front/notify.php index 74f8e9563..c7f83c6c0 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -56,7 +56,7 @@ public function postProcess() $order = new Order($orderId); /** @var SaferPayOrderStatusService $orderStatusService */ - $orderStatusService = $this->module->getModuleContainer()->get(SaferPayOrderStatusService::class); + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); $paymentBehaviourWithout3DS = (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D); @@ -109,7 +109,7 @@ public function postProcess() private function assertTransaction($cartId) { /** @var SaferPayTransactionAssertion $transactionAssert */ - $transactionAssert = $this->module->getModuleContainer()->get(SaferPayTransactionAssertion::class); + $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); $assertionResponse = $transactionAssert->assert(Order::getOrderByCartId($cartId)); return $assertionResponse; diff --git a/controllers/front/pendingNotify.php b/controllers/front/pendingNotify.php index e28250c71..dc072ffdd 100755 --- a/controllers/front/pendingNotify.php +++ b/controllers/front/pendingNotify.php @@ -47,7 +47,7 @@ public function postProcess() die($this->module->l('Error. Insecure cart', self::FILENAME)); } /** @var SaferPayOrderRepository $saferPayOrderRepository */ - $saferPayOrderRepository = $this->module->getModuleContainer()->get(SaferPayOrderRepository::class); + $saferPayOrderRepository = $this->module->getService(SaferPayOrderRepository::class); $saferPayOrderId = $saferPayOrderRepository->getIdByOrderId($orderId); $orderRefunds = $saferPayOrderRepository->getOrderRefunds($saferPayOrderId); @@ -73,7 +73,7 @@ public function postProcess() private function assertRefundTransaction($transactionId) { /** @var SaferPayTransactionRefundAssertion $transactionAssertRefund */ - $transactionAssertRefund = $this->module->getModuleContainer()->get(SaferPayTransactionRefundAssertion::class); + $transactionAssertRefund = $this->module->getService(SaferPayTransactionRefundAssertion::class); return $transactionAssertRefund->assertRefund($transactionId); } @@ -81,7 +81,7 @@ private function assertRefundTransaction($transactionId) private function handleCapturedRefund($orderRefundId) { /** @var SaferPayOrderRepository $saferPayOrderRepository */ - $saferPayOrderRepository = $this->module->getModuleContainer()->get(SaferPayOrderRepository::class); + $saferPayOrderRepository = $this->module->getService(SaferPayOrderRepository::class); $orderRefund = new SaferPayOrderRefund($orderRefundId); $orderRefund->status = SaferPayConfig::TRANSACTION_STATUS_CAPTURED; diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 6d9d7fd96..d9d657f68 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -58,12 +58,12 @@ public function postProcess() try { /** @var SaferPayOrderStatusService $orderStatusService */ - $orderStatusService = $this->module->getModuleContainer()->get(SaferPayOrderStatusService::class); + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); $order = new Order($orderId); /** @var SaferPayTransactionAuthorization $saferPayTransactionAuthorization */ - $saferPayTransactionAuthorization = $this->module->getModuleContainer()->get(SaferPayTransactionAuthorization::class); + $saferPayTransactionAuthorization = $this->module->getService(SaferPayTransactionAuthorization::class); $authResponseBody = $saferPayTransactionAuthorization->authorize( $orderId, diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index fd64e2d31..f659de81a 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -59,10 +59,10 @@ public function postProcess() } /** @var SaferPayTransactionAuthorization $saferPayTransactionAuthorization */ - $saferPayTransactionAuthorization = $this->module->getModuleContainer()->get(SaferPayTransactionAuthorization::class); + $saferPayTransactionAuthorization = $this->module->getService(SaferPayTransactionAuthorization::class); /** @var SaferPayOrderStatusService $orderStatusService */ - $orderStatusService = $this->module->getModuleContainer()->get(SaferPayOrderStatusService::class); + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); $order = new Order($orderId); diff --git a/controllers/front/validation.php b/controllers/front/validation.php index 71518abc9..3ea73764b 100755 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -95,13 +95,13 @@ public function postProcess() } /** @var SaferPayInitialize $initializeService */ - $initializeService = $this->module->getModuleContainer()->get(SaferPayInitialize::class); + $initializeService = $this->module->getService(SaferPayInitialize::class); try { $isBusinessLicence = Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE); $initializeBody = $initializeService->initialize($paymentMethod, $isBusinessLicence); } catch (SaferPayApiException $e) { /** @var SaferPayExceptionService $exceptionService */ - $exceptionService = $this->module->getModuleContainer()->get(SaferPayExceptionService::class); + $exceptionService = $this->module->getService(SaferPayExceptionService::class); $this->errors[] = $exceptionService->getErrorMessageForException($e, $exceptionService->getErrorMessages()); $redirectLink = $this->context->link->getModuleLink( $this->module->name, @@ -117,8 +117,7 @@ public function postProcess() $this->redirectWithNotifications($redirectLink); } /** @var Invertus\SaferPay\EntityBuilder\SaferPayOrderBuilder $saferPayOrderBuilder */ - $saferPayOrderBuilder = $this->module->getModuleContainer() - ->get(\Invertus\SaferPay\EntityBuilder\SaferPayOrderBuilder::class); + $saferPayOrderBuilder = $this->module->getService(\Invertus\SaferPay\EntityBuilder\SaferPayOrderBuilder::class); $saferPayOrderBuilder->create( $initializeBody, $this->context->cart, diff --git a/saferpayofficial.php b/saferpayofficial.php index dcecc140b..c99c8799b 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -50,8 +50,6 @@ public function __construct($name = null) parent::__construct($name); $this->autoload(); - $this->loadConfig(); - $this->compile(); } public function getContent() @@ -106,58 +104,28 @@ private function loadConfig() { require $this->getLocalPath() . 'saferpay.config.php'; } - - /** - * @return mixed - */ - public function getModuleContainer() - { - return $this->moduleContainer; - } - public function getService($service) { - return $this->getModuleContainer()->get($service); - } + $containerProvider = new \Invertus\SaferPay\ServiceProvider\LeagueServiceContainerProvider(); - private function compile() - { - $containerCache = $this->getLocalPath() . 'var/cache/container.php'; - $containerConfigCache = new \Symfony\Component\Config\ConfigCache($containerCache, self::DISABLE_CACHE); - $containerClass = get_class($this) . 'Container'; - if (!$containerConfigCache->isFresh()) { - $containerBuilder = new \Symfony\Component\DependencyInjection\ContainerBuilder(); - $locator = new \Symfony\Component\Config\FileLocator($this->getLocalPath() . 'config'); - $loader = new \Symfony\Component\DependencyInjection\Loader\YamlFileLoader($containerBuilder, $locator); - $loader->load('config.yml'); - $containerBuilder->compile(); - $dumper = new \Symfony\Component\DependencyInjection\Dumper\PhpDumper($containerBuilder); - $containerConfigCache->write( - $dumper->dump(['class' => $containerClass]), - $containerBuilder->getResources() - ); - } - require_once $containerCache; - $this->moduleContainer = new $containerClass(); + return $containerProvider->getService($service); } public function hookPaymentOptions($params) { /** @var Invertus\SaferPay\Service\SaferPayCartService $assertService */ - $cartService = $this->getModuleContainer()->get(\Invertus\SaferPay\Service\SaferPayCartService::class); + $cartService = $this->getService(\Invertus\SaferPay\Service\SaferPayCartService::class); if (!$cartService->isCurrencyAvailable($params['cart'])) { return; } /** @var \Invertus\SaferPay\Provider\PaymentTypeProvider $paymentTypeProvider */ - $paymentTypeProvider = $this->getModuleContainer()->get(\Invertus\SaferPay\Provider\PaymentTypeProvider::class); + $paymentTypeProvider = $this->getService(\Invertus\SaferPay\Provider\PaymentTypeProvider::class); /** @var \Invertus\SaferPay\Service\SaferPayObtainPaymentMethods $obtainPaymentMethods */ - $obtainPaymentMethods = $this->getModuleContainer() - ->get(\Invertus\SaferPay\Service\SaferPayObtainPaymentMethods::class); + $obtainPaymentMethods = $this->getService(\Invertus\SaferPay\Service\SaferPayObtainPaymentMethods::class); /** @var \Invertus\SaferPay\Repository\SaferPayPaymentRepository $paymentRepository */ - $paymentRepository = $this->getModuleContainer() - ->get(\Invertus\SaferPay\Repository\SaferPayPaymentRepository::class); + $paymentRepository = $this->getService(\Invertus\SaferPay\Repository\SaferPayPaymentRepository::class); try { $paymentMethods = $obtainPaymentMethods->obtainPaymentMethods(); @@ -168,7 +136,7 @@ public function hookPaymentOptions($params) $paymentOptions = []; /** @var \Invertus\SaferPay\Service\PaymentRestrictionValidation $paymentRestrictionValidation */ - $paymentRestrictionValidation = $this->getModuleContainer()->get( + $paymentRestrictionValidation = $this->getService( \Invertus\SaferPay\Service\PaymentRestrictionValidation::class ); @@ -193,7 +161,7 @@ public function hookPaymentOptions($params) ); /** @var \Invertus\SaferPay\Repository\SaferPayCardAliasRepository $cardAliasRep */ - $cardAliasRep = $this->getModuleContainer()->get( + $cardAliasRep = $this->getService( \Invertus\SaferPay\Repository\SaferPayCardAliasRepository::class ); $isCreditCardSavingEnabled = Configuration::get( @@ -206,16 +174,14 @@ public function hookPaymentOptions($params) } /** @var \Invertus\SaferPay\Provider\PaymentRedirectionProvider $paymentRedirectionProvider */ - $paymentRedirectionProvider = $this->getModuleContainer() - ->get(\Invertus\SaferPay\Provider\PaymentRedirectionProvider::class); + $paymentRedirectionProvider = $this->getService(\Invertus\SaferPay\Provider\PaymentRedirectionProvider::class); $newOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption(); - $translator = $this->getModuleContainer()->get( + $translator = $this->getService( \Invertus\SaferPay\Service\LegacyTranslator::class ); /** @var \Invertus\SaferPay\Service\SaferPayPaymentNotation $saferPayPaymentNotation */ - $saferPayPaymentNotation = $this->getModuleContainer() - ->get(\Invertus\SaferPay\Service\SaferPayPaymentNotation::class); + $saferPayPaymentNotation = $this->getService(\Invertus\SaferPay\Service\SaferPayPaymentNotation::class); $paymentMethodName = $saferPayPaymentNotation->getForDisplay($paymentMethod['paymentMethod']); $inputs = [ @@ -319,8 +285,7 @@ public function hookActionFrontControllerSetMedia() } /** @var \Invertus\SaferPay\Service\SaferPayErrorDisplayService $errorDisplayService */ - $errorDisplayService = $this->getModuleContainer() - ->get(\Invertus\SaferPay\Service\SaferPayErrorDisplayService::class); + $errorDisplayService = $this->getService(\Invertus\SaferPay\Service\SaferPayErrorDisplayService::class); $errorDisplayService->showCookieError('saferpay_payment_canceled_error'); } } @@ -411,18 +376,16 @@ public function hookDisplayPayment($params) } /** @var \Invertus\SaferPay\Service\SaferPayCartService $assertService */ - $cartService = $this->getModuleContainer()->get(\Invertus\SaferPay\Service\SaferPayCartService::class); + $cartService = $this->getService(\Invertus\SaferPay\Service\SaferPayCartService::class); if (!$cartService->isCurrencyAvailable($params['cart'])) { return; } /** @var \Invertus\SaferPay\Service\PaymentRestrictionValidation $paymentRestrictionValidation */ - $paymentRepository = $this->getModuleContainer() - ->get(\Invertus\SaferPay\Repository\SaferPayPaymentRepository::class); + $paymentRepository = $this->getService(\Invertus\SaferPay\Repository\SaferPayPaymentRepository::class); /** @var \Invertus\SaferPay\Service\SaferPayObtainPaymentMethods $obtainPaymentMethods */ - $obtainPaymentMethods = $this->getModuleContainer() - ->get(\Invertus\SaferPay\Service\SaferPayObtainPaymentMethods::class); + $obtainPaymentMethods = $this->getService(\Invertus\SaferPay\Service\SaferPayObtainPaymentMethods::class); try { $paymentMethods = $obtainPaymentMethods->obtainPaymentMethods(); } catch (\Invertus\SaferPay\Exception\Api\SaferPayApiException $exception) { @@ -431,7 +394,7 @@ public function hookDisplayPayment($params) $paymentOptions = []; - $paymentRestrictionValidation = $this->getModuleContainer()->get( + $paymentRestrictionValidation = $this->getService( \Invertus\SaferPay\Service\PaymentRestrictionValidation::class ); @@ -452,7 +415,7 @@ public function hookDisplayPayment($params) ); /** @var \Invertus\SaferPay\Repository\SaferPayCardAliasRepository $cardAliasRep */ - $cardAliasRep = $this->getModuleContainer()->get( + $cardAliasRep = $this->getService( \Invertus\SaferPay\Repository\SaferPayCardAliasRepository::class ); @@ -485,8 +448,7 @@ public function hookDisplayPayment($params) } /** @var \Invertus\SaferPay\Provider\PaymentRedirectionProvider $paymentRedirectionProvider */ - $paymentRedirectionProvider = $this->getModuleContainer() - ->get(\Invertus\SaferPay\Provider\PaymentRedirectionProvider::class); + $paymentRedirectionProvider = $this->getService(\Invertus\SaferPay\Provider\PaymentRedirectionProvider::class); /** @var \Invertus\SaferPay\Provider\PaymentTypeProvider $paymentTypeProvider */ $paymentTypeProvider = $this->getService(\Invertus\SaferPay\Provider\PaymentTypeProvider::class); @@ -519,7 +481,7 @@ public function hookPaymentReturn() } /** @var \Invertus\SaferPay\Builder\OrderConfirmationMessageTemplate $OrderConfirmationMessageTemplate */ - $OrderConfirmationMessageTemplate = $this->getModuleContainer()->get( + $OrderConfirmationMessageTemplate = $this->getService( \Invertus\SaferPay\Builder\OrderConfirmationMessageTemplate::class ); $OrderConfirmationMessageTemplate->setSmarty($this->context->smarty); @@ -603,7 +565,7 @@ public function hookActionOrderStatusUpdate($params = []) $saferPayAuthorizedStatus = (int) Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_PAYMENT_AUTHORIZED); if ($orderStatus->id === $saferPayAuthorizedStatus) { /** @var \Invertus\SaferPay\Service\SaferPayMailService $mailService */ - $mailService = $this->getModuleContainer()->get( + $mailService = $this->getService( \Invertus\SaferPay\Service\SaferPayMailService::class ); $mailService->sendNewOrderMail($order, $orderStatus->id); @@ -621,7 +583,7 @@ public function hookActionAdminControllerSetMedia() $order = new Order($orderId); /** @var \Invertus\SaferPay\Repository\SaferPayOrderRepository $orderRepo */ - $orderRepo = $this->getModuleContainer()->get(\Invertus\SaferPay\Repository\SaferPayOrderRepository::class); + $orderRepo = $this->getService(\Invertus\SaferPay\Repository\SaferPayOrderRepository::class); $saferPayOrderId = $orderRepo->getIdByOrderId($orderId); $saferPayOrder = new SaferPayOrder($saferPayOrderId); @@ -666,7 +628,7 @@ private function displayInAdminOrderPage(array $params) { $orderId = $params['id_order']; $order = new Order($orderId); - $orderRepo = $this->getModuleContainer()->get(\Invertus\SaferPay\Repository\SaferPayOrderRepository::class); + $orderRepo = $this->getService(\Invertus\SaferPay\Repository\SaferPayOrderRepository::class); $saferPayOrderId = $orderRepo->getIdByOrderId($orderId); $saferPayOrder = new SaferPayOrder($saferPayOrderId); diff --git a/src/Builder/OrderConfirmationMessageTemplate.php b/src/Builder/OrderConfirmationMessageTemplate.php index febf09e9e..ee1790b50 100755 --- a/src/Builder/OrderConfirmationMessageTemplate.php +++ b/src/Builder/OrderConfirmationMessageTemplate.php @@ -23,14 +23,12 @@ namespace Invertus\SaferPay\Builder; -use SaferPayOfficial; +use Invertus\SaferPay\Factory\ModuleFactory; class OrderConfirmationMessageTemplate { /** - * Module Main Class Variable Declaration. - * - * @var SaferPayOfficial + * @var ModuleFactory */ private $module; @@ -58,11 +56,11 @@ class OrderConfirmationMessageTemplate /** * TagScriptTemplate constructor. * - * @param SaferPayOfficial $module + * @param ModuleFactory $module */ - public function __construct(SaferPayOfficial $module) + public function __construct(ModuleFactory $module) { - $this->module = $module; + $this->module = $module->getModule(); } /** diff --git a/src/Factory/ModuleFactory.php b/src/Factory/ModuleFactory.php new file mode 100755 index 000000000..f7a572f92 --- /dev/null +++ b/src/Factory/ModuleFactory.php @@ -0,0 +1,22 @@ +module = $module; + $this->module = $module->getModule(); $this->context = $context; } @@ -51,7 +50,7 @@ public function register($controller) } Media::addJsDef([ - 'saferpay_official_ajax_url' => $this->context->link->getModuleLink('saferpayofficial', ControllerName::AJAX), + 'saferpay_official_ajax_url' => $this->context->getLink()->getModuleLink($this->module->name, ControllerName::AJAX), 'saferpay_payment_types' => [ 'hosted_iframe' => PaymentType::HOSTED_IFRAME, 'iframe' => PaymentType::IFRAME, diff --git a/src/Provider/PaymentRedirectionProvider.php b/src/Provider/PaymentRedirectionProvider.php index 46454d1c7..45a26a6ec 100755 --- a/src/Provider/PaymentRedirectionProvider.php +++ b/src/Provider/PaymentRedirectionProvider.php @@ -25,30 +25,32 @@ use Configuration; use Context; +use Invertus\SaferPay\Adapter\LegacyContext; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Enum\PaymentType; +use Invertus\SaferPay\Factory\ModuleFactory; use Invertus\SaferPay\Repository\SaferPayFieldRepository; class PaymentRedirectionProvider { /** - * @var Context + * @var LegacyContext */ private $context; /** - * @var string + * @var ModuleFactory */ - private $moduleName; + private $module; /** @var PaymentTypeProvider */ private $paymentTypeProvider; - public function __construct(Context $context, $moduleName, PaymentTypeProvider $paymentTypeProvider) + public function __construct(LegacyContext $context, ModuleFactory $moduleFactory, PaymentTypeProvider $paymentTypeProvider) { $this->context = $context; - $this->moduleName = $moduleName; + $this->module = $moduleFactory->getModule(); $this->paymentTypeProvider = $paymentTypeProvider; } @@ -62,8 +64,8 @@ public function provideRedirectionLinkByPaymentMethod($paymentMethod) $paymentType = $this->paymentTypeProvider->get($paymentMethod); if ($paymentType === PaymentType::HOSTED_IFRAME) { - return $this->context->link->getModuleLink( - $this->moduleName, + return $this->context->getLink()->getModuleLink( + $this->module->name, ControllerName::HOSTED_IFRAME, ['saved_card_method' => $paymentMethod, SaferPayConfig::IS_BUSINESS_LICENCE => true], true @@ -71,16 +73,16 @@ public function provideRedirectionLinkByPaymentMethod($paymentMethod) } if ($paymentType === PaymentType::IFRAME) { - return $this->context->link->getModuleLink( - $this->moduleName, + return $this->context->getLink()->getModuleLink( + $this->module->name, ControllerName::IFRAME, ['saved_card_method' => $paymentMethod, SaferPayConfig::IS_BUSINESS_LICENCE => true], true ); } - return $this->context->link->getModuleLink( - $this->moduleName, + return $this->context->getLink()->getModuleLink( + $this->module->name, ControllerName::VALIDATION, ['saved_card_method' => $paymentMethod, SaferPayConfig::IS_BUSINESS_LICENCE => false], true diff --git a/src/Service/LegacyTranslator.php b/src/Service/LegacyTranslator.php index adc3c4648..7146b2f62 100755 --- a/src/Service/LegacyTranslator.php +++ b/src/Service/LegacyTranslator.php @@ -24,16 +24,20 @@ namespace Invertus\SaferPay\Service; use Invertus\SaferPay\Config\SaferPayConfig; +use Invertus\SaferPay\Factory\ModuleFactory; class LegacyTranslator implements TranslatorInterface { const FILE_NAME = 'LegacyTranslator'; + /** + * @var ModuleFactory + */ private $module; - public function __construct(\SaferPayOfficial $module) + public function __construct(ModuleFactory $module) { - $this->module = $module; + $this->module = $module->getModule(); } public function translate($key) diff --git a/src/Service/SaferPayCartService.php b/src/Service/SaferPayCartService.php index 7f54280fb..cc11ffc0e 100755 --- a/src/Service/SaferPayCartService.php +++ b/src/Service/SaferPayCartService.php @@ -25,18 +25,19 @@ use Cart; use Currency; +use Invertus\SaferPay\Factory\ModuleFactory; use SaferPayOfficial; class SaferPayCartService { /** - * @var SaferPayOfficial + * @var ModuleFactory */ private $module; - public function __construct(SaferPayOfficial $module) + public function __construct(ModuleFactory $moduleFactory) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); } public function isCurrencyAvailable(Cart $cart) diff --git a/src/Service/SaferPayExceptionService.php b/src/Service/SaferPayExceptionService.php index 72417c907..4b665ed22 100755 --- a/src/Service/SaferPayExceptionService.php +++ b/src/Service/SaferPayExceptionService.php @@ -25,6 +25,7 @@ use Exception; use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\SaferPay\Factory\ModuleFactory; use SaferPayOfficial; class SaferPayExceptionService @@ -32,13 +33,13 @@ class SaferPayExceptionService const SHORT_CLASS_NAME = 'SaferPayExceptionService'; /** - * @var SaferPayOfficial + * @var ModuleFactory */ private $module; - public function __construct(SaferPayOfficial $module) + public function __construct(ModuleFactory $module) { - $this->module = $module; + $this->module = $module->getModule(); } public function getErrorMessages() diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index 522087e44..884915f33 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -23,24 +23,24 @@ namespace Invertus\SaferPay\Service; -use Context; use Exception; +use Invertus\SaferPay\Adapter\LegacyContext; use Invertus\SaferPay\Api\Request\InitializeService; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\SaferPay\Factory\ModuleFactory; use Invertus\SaferPay\Service\Request\InitializeRequestObjectCreator; use Order; -use SaferPayOfficial; class SaferPayInitialize { /** - * @var \SaferPayOfficial + * @var ModuleFactory */ private $module; /** - * @var Context + * @var LegacyContext */ private $context; @@ -55,13 +55,13 @@ class SaferPayInitialize private $requestObjectCreator; public function __construct( - SaferPayOfficial $module, - Context $context, + ModuleFactory $module, + LegacyContext $context, InitializeService $initializeService, InitializeRequestObjectCreator $requestObjectCreator ) { - $this->module = $module; - $this->context = $context; + $this->module = $module->getModule(); + $this->context = $context->getContext(); $this->initializeService = $initializeService; $this->requestObjectCreator = $requestObjectCreator; } diff --git a/src/Service/SaferPayOrderStatusService.php b/src/Service/SaferPayOrderStatusService.php index 3e035fc6d..88045bb31 100755 --- a/src/Service/SaferPayOrderStatusService.php +++ b/src/Service/SaferPayOrderStatusService.php @@ -24,7 +24,6 @@ namespace Invertus\SaferPay\Service; use Cart; -use Context; use Customer; use Exception; use Invertus\SaferPay\Adapter\LegacyContext; @@ -35,6 +34,7 @@ use Invertus\SaferPay\DTO\Request\PendingNotification; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\SaferPay\Factory\ModuleFactory; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\Request\CancelRequestObjectCreator; use Invertus\SaferPay\Service\Request\CaptureRequestObjectCreator; @@ -80,7 +80,7 @@ class SaferPayOrderStatusService private $context; /** - * @var \SaferPayOfficial + * @var ModuleFactory */ private $module; @@ -93,7 +93,7 @@ public function __construct( RefundService $refundService, RefundRequestObjectCreator $refundRequestObjectCreator, LegacyContext $context, - \SaferPayOfficial $module + ModuleFactory $module ) { $this->captureService = $captureService; $this->captureRequestObjectCreator = $captureRequestObjectCreator; @@ -103,7 +103,7 @@ public function __construct( $this->refundService = $refundService; $this->refundRequestObjectCreator = $refundRequestObjectCreator; $this->context = $context; - $this->module = $module; + $this->module = $module->getModule(); } /** diff --git a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php index 8f626b8dd..2fa0fe932 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php @@ -23,7 +23,7 @@ namespace Invertus\SaferPay\Service\TransactionFlow; -use Context; +use Invertus\SaferPay\Adapter\LegacyContext; use Invertus\SaferPay\Api\Request\AuthorizationService; use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\Repository\SaferPayOrderRepository; @@ -55,7 +55,7 @@ class SaferPayTransactionAuthorization private $orderStatusService; /** - * @var Context + * @var LegacyContext */ private $context; @@ -64,7 +64,7 @@ public function __construct( SaferPayOrderRepository $orderRepository, AuthorizationService $authorizationService, SaferPayOrderStatusService $orderStatusService, - Context $context + LegacyContext $context ) { $this->authRequestCreator = $authRequestCreator; $this->orderRepository = $orderRepository; diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php new file mode 100755 index 000000000..f1788bc9a --- /dev/null +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -0,0 +1,61 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +namespace Invertus\SaferPay\ServiceProvider; + +use Invertus\SaferPay\Provider\BasicIdempotencyProvider; +use Invertus\SaferPay\Provider\IdempotencyProviderInterface; +use Invertus\SaferPay\Repository\OrderRepository; +use Invertus\SaferPay\Repository\OrderRepositoryInterface; +use League\Container\Container; + +/** + * Load base services here which are usually required + */ +final class BaseServiceProvider +{ + private $extendedServices; + + public function __construct($extendedServices) + { + $this->extendedServices = $extendedServices; + } + + public function register(Container $container) + { + $this->addService($container, IdempotencyProviderInterface::class, $container->get(BasicIdempotencyProvider::class)); + $this->addService($container, OrderRepositoryInterface::class, $container->get(OrderRepository::class)); + } + + private function addService(Container $container, $className, $service) + { + return $container->add($className, $this->getService($className, $service)); + } + + //NOTE need to call this as extended services should be initialized everywhere. + public function getService($className, $service) + { + if (isset($this->extendedServices[$className])) { + return $this->extendedServices[$className]; + } + + return $service; + } +} \ No newline at end of file diff --git a/src/ServiceProvider/LeagueServiceContainerProvider.php b/src/ServiceProvider/LeagueServiceContainerProvider.php new file mode 100755 index 000000000..e208ae228 --- /dev/null +++ b/src/ServiceProvider/LeagueServiceContainerProvider.php @@ -0,0 +1,50 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +namespace Invertus\SaferPay\ServiceProvider; + +use League\Container\Container; +use League\Container\ReflectionContainer; + +class LeagueServiceContainerProvider implements ServiceContainerProviderInterface +{ + private $extendedServices = []; + + /** {@inheritDoc} */ + public function getService($serviceName) + { + $container = new Container(); + + $container->delegate( + new ReflectionContainer() + ); + + (new BaseServiceProvider($this->extendedServices))->register($container); + + return $container->get((string) $serviceName); + } + + public function extend($id, $concrete = null) + { + $this->extendedServices[$id] = $concrete; + + return $this; + } +} \ No newline at end of file diff --git a/src/ServiceProvider/ServiceContainerProviderInterface.php b/src/ServiceProvider/ServiceContainerProviderInterface.php new file mode 100755 index 000000000..807f6cbd3 --- /dev/null +++ b/src/ServiceProvider/ServiceContainerProviderInterface.php @@ -0,0 +1,34 @@ + + * @copyright Copyright (c) permanent, Square, Inc. + * @license Apache License + * + * @see /LICENSE + * + * International Registered Trademark & Property of Square, Inc. + */ + +namespace Invertus\SaferPay\ServiceProvider; + +interface ServiceContainerProviderInterface +{ + /** + * Gets service that is defined by module container. + * + * @param string $serviceName + */ + public function getService($serviceName); + + /** + * Extending the service. Useful for tests to dynamically change the implementations + * + * @param string $id + * @param string $concrete - a class name + * + * @return mixed + */ + public function extend($id, $concrete = null); +} \ No newline at end of file