3 declare(strict_types=1);
20 use GuzzleHttp\ClientInterface;
21 use GuzzleHttp\Exception\ClientException;
22 use GuzzleHttp\Exception\RequestException;
23 use GuzzleHttp\Exception\ServerException;
24 use GuzzleHttp\Promise\PromiseInterface;
26 use Psr\Http\Message\ResponseInterface;
40 public function __construct(
string $projectKey, $body =
null, array $headers = [], ClientInterface $client =
null)
42 $uri = str_replace([
'{projectKey}'], [$projectKey],
'{projectKey}/carts');
43 parent::__construct($client,
'HEAD', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
51 public function mapFromResponse(?ResponseInterface $response,
string $resultType =
null)
53 if (is_null($response)) {
56 if (is_null($resultType)) {
57 switch ($response->getStatusCode()) {
59 $resultType = ErrorResponseModel::class;
63 $resultType = ErrorResponseModel::class;
67 $resultType = ErrorResponseModel::class;
71 $resultType = ErrorResponseModel::class;
75 $resultType = ErrorResponseModel::class;
79 $resultType = ErrorResponseModel::class;
83 $resultType = JsonObjectModel::class;
98 public function execute(array $options = [],
string $resultType =
null)
101 $response = $this->
send($options);
102 }
catch (ServerException $e) {
103 $response = $e->getResponse();
106 }
catch (ClientException $e) {
107 $response = $e->getResponse();
121 public function executeAsync(array $options = [],
string $resultType =
null)
124 function (ResponseInterface $response) use ($resultType) {
127 function (RequestException $e) use ($resultType) {
128 $response = $e->getResponse();
129 if ($e instanceof ServerException) {
132 if ($e instanceof ClientException) {