3 declare(strict_types=1);
22 use GuzzleHttp\ClientInterface;
23 use GuzzleHttp\Exception\ClientException;
24 use GuzzleHttp\Exception\RequestException;
25 use GuzzleHttp\Exception\ServerException;
26 use GuzzleHttp\Promise\PromiseInterface;
28 use Psr\Http\Message\ResponseInterface;
43 public function __construct(
string $projectKey, $body =
null, array $headers = [], ClientInterface $client =
null)
45 $uri = str_replace([
'{projectKey}'], [$projectKey],
'{projectKey}/carts');
46 parent::__construct($client,
'POST', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
54 public function mapFromResponse(?ResponseInterface $response,
string $resultType =
null)
56 if (is_null($response)) {
59 if (is_null($resultType)) {
60 switch ($response->getStatusCode()) {
62 $resultType = CartModel::class;
66 $resultType = ErrorResponseModel::class;
70 $resultType = ErrorResponseModel::class;
74 $resultType = ErrorResponseModel::class;
78 $resultType = ErrorResponseModel::class;
82 $resultType = ErrorResponseModel::class;
86 $resultType = ErrorResponseModel::class;
90 $resultType = JsonObjectModel::class;
105 public function execute(array $options = [],
string $resultType =
null)
108 $response = $this->
send($options);
109 }
catch (ServerException $e) {
110 $response = $e->getResponse();
113 }
catch (ClientException $e) {
114 $response = $e->getResponse();
128 public function executeAsync(array $options = [],
string $resultType =
null)
131 function (ResponseInterface $response) use ($resultType) {
134 function (RequestException $e) use ($resultType) {
135 $response = $e->getResponse();
136 if ($e instanceof ServerException) {
139 if ($e instanceof ClientException) {
executeAsync(array $options=[], string $resultType=null)
execute(array $options=[], string $resultType=null)
__construct(string $projectKey, $body=null, array $headers=[], ClientInterface $client=null)
mapFromResponse(?ResponseInterface $response, string $resultType=null)