btcService = $btcService; $this->storeManager = $storeManager; $this->logger = $logger; $this->configResource = $configResource; $this->reinitableConfig = $reinitableConfig; $this->helper = $helper; } public function execute() { $magentoStoreId = 0; $apiKey = $this->getRequest()->getParam('apiKey'); $givenSecret = $this->getRequest()->getParam('secret'); $secret = $this->btcService->hashSecret($magentoStoreId); if ($givenSecret === $secret) { try { $baseUrl = $this->btcService->getBtcPayServerBaseUrl(); // Safety check $client = new \BTCPayServer\Client\ApiKey($baseUrl, $apiKey); $client->getCurrent(); // Save API key to config settings $this->configResource->saveConfig('payment/btcpay/api_key', $apiKey); // When only 1 BTCStore, save immediately $allBtcStores = $this->btcService->getAllBtcPayStores($baseUrl, $apiKey); if ($allBtcStores && count($allBtcStores) === 1) { $btcStoreId = $allBtcStores[0]['id']; if ($btcStoreId) { // Create webhook as well $allMagentoStoreViews = $this->helper->getAllMagentoStoreViewIds(); foreach ($allMagentoStoreViews as $magentoStoreView) { $this->configResource->saveConfig('payment/btcpay/btcpay_store_id', $btcStoreId, 'stores', $magentoStoreView); $this->helper->installWebhookIfNeeded((int)$magentoStoreView, true); } } } //Clear config cache. $this->reinitableConfig->reinit(); echo ___('exact_online.connection_succeeded_close_window', 'Success! You can now close this window.'); } catch (\Exception $e) { $this->logger->error($e); echo ___('exact_online.connection_failed_close_window', 'Something went wrong. Please try again.'); } } else { echo ___('exact_online.connection_access_denied_close_window', 'Forbidden.'); } } public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException { return null; } public function validateForCsrf(RequestInterface $request): ?bool { return true; } }