authorization(); } private function authorization() { $headers = apache_request_headers(); $apiKey = \IpSupply\SyncOrder\Helper::API_KEY; foreach ($headers as $key => $value) { $key = strtolower($key); if ('api_key' === $key && $value === $apiKey) { return true; } } header('HTTP/1.1 401 Unauthorized'); header('Accept: application/json'); header('Content-Type: application/json'); die(json_encode(['message' => 'unauthorized'])); } private function _responseOk(array $data) { header('HTTP/1.1 200 Ok'); header('Accept: application/json'); header('Content-Type: application/json'); die(json_encode($data)); } private function _responseFail(array $data) { header('HTTP/1.1 400 Bad request'); header('Accept: application/json'); header('Content-Type: application/json'); die(json_encode($data)); } private function _responseMethodFail() { header('HTTP/1.1 400 bad request'); header('Accept: application/json'); header('Content-Type: application/json'); die(json_encode([ 'status' => false, 'message' => 'Param ?method=... not exist!' ])); } public function getData() { return $this->_responseOk([ 'status' => true, 'data' => [] ]); // return $this->_responseMethodFail(); } public function postData() { parse_str( string: file_get_contents('php://input'), result: $payload ); return $this->_responseOk([ 'status' => true, 'data' => [], // TODO 'payload' => $payload ]); // return $this->_responseMethodFail(); } }