/**
  * @param string $url
  * @param mixed[]|null $body
  * @return \SlevomatZboziApi\Response\ZboziApiResponse
  */
 public function sendPostRequest($url, array $body = null)
 {
     TypeValidator::checkString($url);
     $options = ['allow_redirects' => false, 'verify' => true, 'decode_content' => true, 'expect' => false, 'timeout' => $this->timeoutInSeconds];
     $request = $this->client->createRequest('POST', $url, $options);
     $request->setHeaders([static::HEADER_PARTNER_TOKEN => $this->partnerToken, static::HEADER_API_SECRET => $this->apiSecret]);
     if ($body !== null) {
         $request->setBody(\GuzzleHttp\Stream\Stream::factory(json_encode($body)));
     }
     try {
         try {
             $response = $this->client->send($request);
             $this->log($request, $response);
             return $this->getZboziApiResponse($response);
         } catch (\GuzzleHttp\Exception\RequestException $e) {
             $response = $e->getResponse();
             $this->log($request, $response);
             if ($response !== null) {
                 return $this->getZboziApiResponse($response);
             }
             throw new \SlevomatZboziApi\Request\ConnectionErrorException('Connection to Slevomat API failed.', $e->getCode(), $e);
         }
     } catch (\GuzzleHttp\Exception\ParseException $e) {
         $this->log($request, isset($response) ? $response : null, true);
         throw new \SlevomatZboziApi\Response\ResponseErrorException('Slevomat API invalid response: invalid JSON data.', $e->getCode(), $e);
     }
 }
 /**
  * @param string $headerName
  * @return mixed|null
  */
 public function getHeader($headerName)
 {
     TypeValidator::checkString($headerName);
     if (isset($this->headers[$headerName])) {
         return is_array($this->headers[$headerName]) ? $this->headers[$headerName][0] : $this->headers[$headerName];
     }
     return null;
 }
 /**
  * @param string $partnerToken
  * @param string $apiSecret
  * @param integer $timeoutInSeconds
  * @param \SlevomatZboziApi\ZboziApiLogger $logger
  * @return \SlevomatZboziApi\Request\RequestMaker
  */
 public static function create($partnerToken, $apiSecret, $timeoutInSeconds, ZboziApiLogger $logger = null)
 {
     TypeValidator::checkString($partnerToken);
     TypeValidator::checkString($apiSecret);
     TypeValidator::checkInteger($timeoutInSeconds);
     $client = new \GuzzleHttp\Client();
     return new RequestMaker($client, $partnerToken, $apiSecret, $timeoutInSeconds, $logger);
 }
 /**
  * @param string $partnerToken
  * @param string $apiSecret
  * @param string $apiUrl
  * @param integer $timeoutInSeconds (0 = unlimited)
  * @param \SlevomatZboziApi\ZboziApiLogger $logger
  * @return \SlevomatZboziApi\ZboziApiClient
  */
 public static function create($partnerToken, $apiSecret, $apiUrl, $timeoutInSeconds = 30, ZboziApiLogger $logger = null)
 {
     TypeValidator::checkString($partnerToken);
     TypeValidator::checkString($apiSecret);
     TypeValidator::checkString($apiUrl);
     TypeValidator::checkInteger($timeoutInSeconds);
     $responseValidator = new ResponseValidator();
     $requestMaker = RequestMakerFactory::create($partnerToken, $apiSecret, $timeoutInSeconds, $logger);
     return new ZboziApiClient($requestMaker, $responseValidator, $apiUrl);
 }
 /**
  * @param string $url
  * @param mixed[]|null $body
  * @return \SlevomatZboziApi\Response\ZboziApiResponse
  */
 public function sendPostRequest($url, array $body = null)
 {
     TypeValidator::checkString($url);
     $request = new \GuzzleHttp\Psr7\Request('POST', $url, [static::HEADER_PARTNER_TOKEN => $this->partnerToken, static::HEADER_API_SECRET => $this->apiSecret, static::HEADER_USER_AGENT => sprintf('SlevomatZboziApiClient/PHP %s', PHP_VERSION)], $body === null ? null : \GuzzleHttp\Psr7\stream_for(json_encode($body)));
     $options = ['allow_redirects' => false, 'verify' => true, 'decode_content' => true, 'expect' => false, 'timeout' => $this->timeoutInSeconds];
     try {
         try {
             $response = $this->client->send($request, $options);
             $this->log($request, $response);
             return $this->getZboziApiResponse($response);
         } catch (\GuzzleHttp\Exception\RequestException $e) {
             $response = $e->getResponse();
             $this->log($request, $response);
             if ($response !== null) {
                 return $this->getZboziApiResponse($response);
             }
             throw new \SlevomatZboziApi\Request\ConnectionErrorException('Connection to Slevomat API failed.', $e->getCode(), $e);
         }
     } catch (\SlevomatZboziApi\Response\ResponseParsingErrorException $e) {
         $this->log($request, isset($response) ? $response : null, true);
         throw new \SlevomatZboziApi\Response\ResponseErrorException('Slevomat API invalid response: invalid JSON data.', $e->getCode(), $e);
     }
 }
 /**
  * @param string $orderId
  * @param string $name
  * @param string $street
  * @param string $city
  * @param string  $state
  * @param string $phone
  * @param string $postalCode
  * @param string|null $company
  */
 public function updateShippingAddress($orderId, $name, $street, $city, $state, $phone, $postalCode, $company = null)
 {
     TypeValidator::checkString($orderId);
     TypeValidator::checkString($name);
     TypeValidator::checkString($street);
     TypeValidator::checkString($city);
     TypeValidator::checkString($state);
     TypeValidator::checkString($phone);
     TypeValidator::checkString($postalCode);
     if ($company !== null) {
         TypeValidator::checkString($company);
     }
     $body = ['name' => $name, 'street' => $street, 'city' => $city, 'state' => $state, 'phone' => $phone, 'postalCode' => $postalCode, 'company' => $company];
     $endpoint = $this->getEndpoint($orderId, 'update-shipping-address');
     $response = $this->requestMaker->sendPostRequest($endpoint, $body);
     $this->responseValidator->validateResponse($response);
 }
 /**
  * @param string $slevomatId
  */
 private function setSlevomatId($slevomatId)
 {
     TypeValidator::checkString($slevomatId);
     $this->slevomatId = $slevomatId;
 }
 /**
  * @param string $orderId
  */
 public function markDelivered($orderId)
 {
     TypeValidator::checkString($orderId);
     $endpoint = $this->getEndpoint($orderId, 'mark-delivered');
     $response = $this->requestMaker->sendPostRequest($endpoint);
     $this->responseValidator->validateResponse($response);
 }