diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..d9844a7 Binary files /dev/null and b/.DS_Store differ diff --git a/Controller/.DS_Store b/Controller/.DS_Store new file mode 100644 index 0000000..f0286dc Binary files /dev/null and b/Controller/.DS_Store differ diff --git a/Controller/Settings/Index.php b/Controller/Settings/Index.php deleted file mode 100644 index 15523bb..0000000 --- a/Controller/Settings/Index.php +++ /dev/null @@ -1,125 +0,0 @@ -response = $response; - $this->configWriter = $configWriter; - $this->request = $request; - $this->cache = $cache; - $this->configuration = $configuration; - $this->cacheManager = $cacheManager; - } - - /** - * @return ResponseHttp - * @throws Exception - */ - public function execute(): ResponseHttp - { - $data = json_decode($this->request->getContent(), true); - $tokenFromCache = $this->cache->load(SetUpdateSettingsMessage::CACHE_NAME); - $this->cache->remove(SetUpdateSettingsMessage::CACHE_NAME); - - $signature = $this->request->getHeader('x-signature'); - if (!$signature) { - return $this->error('Signature id is required.'); - } - $ts = $this->request->getHeader('x-timestamp') . $this->request->getContent(); - if (hash_hmac('sha256', $ts, $tokenFromCache) !== $signature) { - return $this->error('Signature id is invalid.'); - } - - $clientId = $data['client_id']; - $apiKey = $data['api_key']; - $webhookKey = $data['webhook_secret']; - $accountId = $data['account_id']; - $accountName = $data['account_name']; - if (empty($clientId)) { - return $this->error('Client ID is required.'); - } - if (empty($apiKey)) { - return $this->error('API Key is required.'); - } - if (empty($webhookKey)) { - return $this->error('Webhook Key is required.'); - } - if (empty($accountId)) { - return $this->error('Account id is required.'); - } - if (empty($accountName)) { - return $this->error('Account name is required.'); - } - $encryptor = ObjectManager::getInstance()->get(EncryptorInterface::class); - $mode = substr($tokenFromCache, 0, 4) === 'demo' ? 'demo' : 'prod'; - $account = $this->configuration->getAccount(); - $arrAccount = $account ? json_decode($account, true) : []; - $arrAccount[$mode . '_account_id'] = $accountId; - $arrAccount[$mode . '_account_name'] = $accountName; - $this->configWriter->save('airwallex/general/' . 'account', json_encode($arrAccount)); - $this->configWriter->save('airwallex/general/' . $mode . '_account_name', $accountName); - $this->configWriter->save('airwallex/general/' . $mode . '_client_id', $clientId); - $this->configWriter->save('airwallex/general/' . $mode . '_api_key', $encryptor->encrypt($apiKey)); - $this->configWriter->save('airwallex/general/webhook_' . $mode . '_secret_key', $encryptor->encrypt($webhookKey)); - $this->configWriter->save('airwallex/general/mode', $mode); - $this->cacheManager->flush(['config']); - $this->response->setBody(json_encode(['success' => true])); - return $this->response->setStatusCode(self::HTTP_OK); - } - - /** - * @throws Exception - */ - public function error(string $message) - { - throw new Exception($message); - } - - public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException - { - return null; - } - - /** - * @param RequestInterface $request - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * - * @return bool|null - */ - public function validateForCsrf(RequestInterface $request): ?bool - { - return true; - } -} diff --git a/etc/adminhtml/system/basic.xml b/etc/adminhtml/system/basic.xml index 5f5dfc9..2a02748 100644 --- a/etc/adminhtml/system/basic.xml +++ b/etc/adminhtml/system/basic.xml @@ -7,9 +7,9 @@ Airwallex\Payments\Model\Config\Source\Mode airwallex/general/mode - + airwallex/general/demo_client_id