productMetadata = $productMetadata; $this->resultJsonFactory = $resultJsonFactory; $this->configWriter = $configWriter; $this->getModuleVersion = $getModuleVersion; $this->getEnabledStoresUrls = $getEnabledStoresUrls; } /** * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\ResultInterface */ public function execute() { $data = $this->getRequest()->getPostValue(); $return = []; if (isset($data['order_id'], $data['account_email'], $data['module'])) { $moduleName = $data['module']; $postData = [ 'order' => $data['order_id'], 'email' => $data['account_email'], 'name_version' => $this->getModuleVersion->execute($moduleName), 'base_urls' => $this->getEnabledStoresUrls->execute(), 'name' => $moduleName, 'edition' => $this->productMetadata->getEdition(), 'platform' => 'm2', 'pixel' => 0, 'v' => 1, ]; $response = $this->call($postData); $response = (array)json_decode($response); if (!empty($response['hash'])) { $this->configWriter->save( $moduleName.'/module/data', $response['hash'], ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0 ); $return['hash'] = true; } else { $return['hash'] = false; } if (isset($response['data'])) { $return['data'] = $response['data']; } if (!empty($response['errors'])) { if (is_array($response['errors'])) { $error = implode('
', $response['errors']); } else { $error = $response['errors']; } $return['error'] = $error; } } $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData(json_encode($return)); } /** * @param $postData * @return bool|string */ private function call($postData) { $url = 'https://' . Urls::MARKETPLACE_PINGBACK_URL; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); if (is_array($postData)) { $postData = http_build_query($postData); } curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); $response = curl_exec($ch); curl_close($ch); return $response; } /** * @return bool */ public function _processUrlKeys() { return true; } /** * Check Permission. * * @return bool */ protected function _isAllowed() { return true; } }