sessInitFactory = $sessInitFactory; $this->config = $config; } /** * Ensure payment methods are initialized before first getting * list of available payment methods * * @param MethodList $subject * @param CartInterface|null $quote * @SuppressWarnings(PMD.UnusedFormalParameter) * @return array */ public function beforeGetAvailableMethods(MethodList $subject, CartInterface $quote = null) { if ($this->isEnabled($quote)) { $this->getSessionInitiator()->checkAvailable($quote, Kp::METHOD_CODE); } return [$quote]; } /** * Check to see if we should run or not * * @param CartInterface $quote * @return bool */ private function isEnabled(CartInterface $quote = null) { if (!$quote) { return false; } $store = $quote->getStore(); $scope = ($store === null ? ScopeConfigInterface::SCOPE_TYPE_DEFAULT : ScopeInterface::SCOPE_STORES); if (!$this->config->isSetFlag('payment/' . Kp::METHOD_CODE . '/active', $scope, $store)) { return false; } return true; } /** * Get SessionInitiator instance * * @return SessionInitiatorInterface */ private function getSessionInitiator() { return $this->sessInitFactory->create(); } }