resultJsonFactory = $resultJsonFactory; $this->jsonHelper = $jsonHelper; $this->geoIPLookup = $geoIPLookup; } /** * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json * |\Magento\Framework\Controller\ResultInterface */ public function execute() { $resultJson = $this->resultJsonFactory->create(); $ip = $this->getRequest()->getParam('ip'); $result = $this->geoIPLookup->geoIpLookupTest($ip); return $resultJson->setData( $this->jsonHelper->jsonEncode($result) ); } }