configValueFactory = $configValueFactory; $this->encryptor = $encryptor; $this->configResource = $configResource; } private function getConfigKey($id) { return 'btcpay/keys/' . $id; } /** * @param KeyInterface $key */ public function persist(\BTCPayServer\KeyInterface $key) { $unencrypted = serialize($key); $encrypted = $this->encryptor->encrypt($unencrypted); $configKey = $this->getConfigKey($key->getId()); $this->configResource->saveConfig($configKey, $encrypted); } /** * @param string $id * * @return KeyInterface */ public function load($id) { $configKey = $this->getConfigKey($id); $encrypted = $this->getConfigWithoutCache($configKey); $decrypted = $this->encryptor->decrypt($encrypted); $key = unserialize($decrypted); return $key; } private function getConfigWithoutCache($path) { /* @var $dataCollection \Magento\Config\Model\ResourceModel\Config\Data\Collection */ $dataCollection = $this->configValueFactory->create()->getCollection(); $dataCollection->addFieldToFilter('path', ['eq' => $path]); $row = $dataCollection->getFirstItem(); if ($row->getId()) { return $row->getValue(); } else { return false; } } }