_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'])); } static function getForm() { $data = [ 'url' => '', ]; $config = \IpSupply\SyncOrder\Config\Getter::get('config'); if ($config) { $data = json_decode($config, true); } return [ [ 'label' => 'API', 'name' => 'url', 'value' => $data['url'] ?? '' ] ]; } public function getData() { return \IpSupply\SyncOrder\Helper::responseOk([ 'status' => true, 'data' => [] ]); } public function postData() { parse_str( string: file_get_contents('php://input'), result: $payload, ); unset($payload['form_key']); \IpSupply\SyncOrder\Config\Setter::set( path: 'config', value: json_encode($payload), ); return \IpSupply\SyncOrder\Helper::responseOk([ 'status' => true, ]); } }