client = new \GuzzleHttp\Client(); $this->storeId = (int) $storeId; $this->headers = [ 'authorization' => 'Bearer '.$accessToken, 'accept' => 'application/json', 'content-type' => 'application/json', ]; } public function getUrlAuthorizeCode(string $clientId = null, string $redirectUri = null): string { if($clientId && $redirectUri) { return "https://oauth.api.tiller.systems/oauth2/authorize?client_id=$clientId&response_type=code&scope=&redirect_uri=$redirectUri"; } return '#'; } public function isAuthenticated(): bool { return $this->getOrders(date('Y-m-d')) !== false; } public function getOrders($date) { try { $response = $this->client->request('POST', $this->urlApi.'orders/v3/orders/search', [ 'body' => json_encode([ 'storeIds' => [$this->storeId], 'openDate' => [ 'from' => date('Y-m-d H:i:s', strtotime($date)), 'to' => date('Y-m-d H:i:s', strtotime($date) + 24 * 60 * 60 - 1) ] ]), 'headers' => $this->headers ]); return $response->getBody()->getContents(); } catch (RequestException $exception) { return false; } } public function postOrder($params) { try { $response = $this->client->request('POST', $this->urlApi.'purchase-requests/v1/requests?storeId='.$this->storeId, [ 'body' => json_encode($params), 'headers' => $this->headers ]); } catch (RequestException $exception) { print_r($exception); die(); } return $response->getBody()->getContents(); } }