<?php
/**
 * FortnoxOrdersApi
 * PHP version 8.1
 *
 * @category Class
 * @package  Fortnox
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * Fortnox API
 *
 * # Documentation   The Fortnox API is organized around REST. This means that we’ve designed it to have resource-oriented URLs and be as predictable as possible for you as developer.  It also means that we use HTTP status codes when something goes wrong and HTTP verbs understod by many API clients around the web.  We use a modified version of OAuth2 for authentication to offer a secure way for both you and our users to interact.  The API is generally built to support both XML and JSON but in this documentation all the examples will be in JSON.  We encourage you to read all the articles in the [Guides & Good to Know section](https://www.fortnox.se/developer/guides-and-good-to-know/)</a> first, before going forward and learning about the different resources.  This to ensure you get an understanding of some of the shared components of the API such as parameters and error handling.  ## Rate limits  The limit per access-token is 25 requests per 5 seconds. This equals to 300 requests per minute.  [Read more about this here.](https://www.fortnox.se/developer/guides-and-good-to-know/rate-limits-for-fortnox-api/)  ## Query parameters  Use query parameters with the ?-character and separate parameters with the &-character.   **Example:**  GET - https://api.fortnox.se/3/invoices?accountnumberfrom=3000&accountnumberto=4000 Read more about our parameters [here](https://www.fortnox.se/developer/guides-and-good-to-know/parameters/)   Search the documentation using the search field in the top left corner.
 *
 * The version of the OpenAPI document: 
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.19.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace Fortnox\Api;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Fortnox\ApiException;
use Fortnox\Configuration;
use Fortnox\FormDataProcessor;
use Fortnox\HeaderSelector;
use Fortnox\ObjectSerializer;

/**
 * FortnoxOrdersApi Class Doc Comment
 *
 * @category Class
 * @package  Fortnox
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */
class FortnoxOrdersApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var Configuration
     */
    protected $config;

    /**
     * @var HeaderSelector
     */
    protected $headerSelector;

    /**
     * @var int Host index
     */
    protected $hostIndex;

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'orderControllerDoCreate' => [
            'application/json',
        ],
        'orderControllerDoIndex' => [
            'application/json',
        ],
        'orderControllerDoShow' => [
            'application/json',
        ],
        'orderControllerDoShowAndEmail' => [
            'application/json',
        ],
        'orderControllerDoShowAndPreview' => [
            'application/json',
        ],
        'orderControllerDoShowAndPrint' => [
            'application/json',
        ],
        'orderControllerDoUpdate' => [
            'application/json',
        ],
        'orderControllerDoUpdateAndCancel' => [
            'application/json',
        ],
        'orderControllerDoUpdateAndCreateOrder' => [
            'application/json',
        ],
        'orderControllerDoUpdateAndExternalPrint' => [
            'application/json',
        ],
    ];

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     * @param int             $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
     */
    public function __construct(
        ?ClientInterface $client = null,
        ?Configuration $config = null,
        ?HeaderSelector $selector = null,
        int $hostIndex = 0
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: Configuration::getDefaultConfiguration();
        $this->headerSelector = $selector ?: new HeaderSelector();
        $this->hostIndex = $hostIndex;
    }

    /**
     * Set the host index
     *
     * @param int $hostIndex Host index (required)
     */
    public function setHostIndex($hostIndex): void
    {
        $this->hostIndex = $hostIndex;
    }

    /**
     * Get the host index
     *
     * @return int Host index
     */
    public function getHostIndex()
    {
        return $this->hostIndex;
    }

    /**
     * @return Configuration
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * Operation orderControllerDoCreate
     *
     * Create a new order
     *
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for create order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoCreate($order = null, string $contentType = self::contentTypes['orderControllerDoCreate'][0])
    {
        list($response) = $this->orderControllerDoCreateWithHttpInfo($order, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoCreateWithHttpInfo
     *
     * Create a new order
     *
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for create order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoCreateWithHttpInfo($order = null, string $contentType = self::contentTypes['orderControllerDoCreate'][0])
    {
        $request = $this->orderControllerDoCreateRequest($order, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 201:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoCreateAsync
     *
     * Create a new order
     *
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for create order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoCreateAsync($order = null, string $contentType = self::contentTypes['orderControllerDoCreate'][0])
    {
        return $this->orderControllerDoCreateAsyncWithHttpInfo($order, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoCreateAsyncWithHttpInfo
     *
     * Create a new order
     *
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for create order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoCreateAsyncWithHttpInfo($order = null, string $contentType = self::contentTypes['orderControllerDoCreate'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderResponseWrap';
        $request = $this->orderControllerDoCreateRequest($order, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoCreate'
     *
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for create order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoCreateRequest($order = null, string $contentType = self::contentTypes['orderControllerDoCreate'][0])
    {



        $resourcePath = '/3/orders';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;





        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (isset($order)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($order));
            } else {
                $httpBody = $order;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'POST',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation orderControllerDoIndex
     *
     * Retrieve a list of orders
     *
     * @param  string|null $todate filter by to date (optional)
     * @param  string|null $fromdate filter by from date (optional)
     * @param  string|null $filter possibility to filter orders (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customername filter by customer name (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $label filter by label (optional)
     * @param  string|null $documentnumber filter by document number (optional)
     * @param  string|null $externalinvoicereference1 filter by external invoice reference 1 (optional)
     * @param  string|null $externalinvoicereference2 filter by external invoice reference 2 (optional)
     * @param  string|null $costcenter filter by cost center (optional)
     * @param  string|null $project filter by project (optional)
     * @param  bool|null $sent filter by sent (optional)
     * @param  bool|null $notcompleted filter by not completed (optional)
     * @param  string|null $ourreference filter by ourreference (optional)
     * @param  string|null $yourreference filter by your reference (optional)
     * @param  string|null $lastmodified filter by lastmodified (optional)
     * @param  string|null $ordertype filter by order type (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderListResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoIndex($todate = null, $fromdate = null, $filter = null, $sortby = null, $customername = null, $customernumber = null, $label = null, $documentnumber = null, $externalinvoicereference1 = null, $externalinvoicereference2 = null, $costcenter = null, $project = null, $sent = null, $notcompleted = null, $ourreference = null, $yourreference = null, $lastmodified = null, $ordertype = null, string $contentType = self::contentTypes['orderControllerDoIndex'][0])
    {
        list($response) = $this->orderControllerDoIndexWithHttpInfo($todate, $fromdate, $filter, $sortby, $customername, $customernumber, $label, $documentnumber, $externalinvoicereference1, $externalinvoicereference2, $costcenter, $project, $sent, $notcompleted, $ourreference, $yourreference, $lastmodified, $ordertype, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoIndexWithHttpInfo
     *
     * Retrieve a list of orders
     *
     * @param  string|null $todate filter by to date (optional)
     * @param  string|null $fromdate filter by from date (optional)
     * @param  string|null $filter possibility to filter orders (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customername filter by customer name (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $label filter by label (optional)
     * @param  string|null $documentnumber filter by document number (optional)
     * @param  string|null $externalinvoicereference1 filter by external invoice reference 1 (optional)
     * @param  string|null $externalinvoicereference2 filter by external invoice reference 2 (optional)
     * @param  string|null $costcenter filter by cost center (optional)
     * @param  string|null $project filter by project (optional)
     * @param  bool|null $sent filter by sent (optional)
     * @param  bool|null $notcompleted filter by not completed (optional)
     * @param  string|null $ourreference filter by ourreference (optional)
     * @param  string|null $yourreference filter by your reference (optional)
     * @param  string|null $lastmodified filter by lastmodified (optional)
     * @param  string|null $ordertype filter by order type (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderListResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoIndexWithHttpInfo($todate = null, $fromdate = null, $filter = null, $sortby = null, $customername = null, $customernumber = null, $label = null, $documentnumber = null, $externalinvoicereference1 = null, $externalinvoicereference2 = null, $costcenter = null, $project = null, $sent = null, $notcompleted = null, $ourreference = null, $yourreference = null, $lastmodified = null, $ordertype = null, string $contentType = self::contentTypes['orderControllerDoIndex'][0])
    {
        $request = $this->orderControllerDoIndexRequest($todate, $fromdate, $filter, $sortby, $customername, $customernumber, $label, $documentnumber, $externalinvoicereference1, $externalinvoicereference2, $costcenter, $project, $sent, $notcompleted, $ourreference, $yourreference, $lastmodified, $ordertype, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderListResponseWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderListResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderListResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoIndexAsync
     *
     * Retrieve a list of orders
     *
     * @param  string|null $todate filter by to date (optional)
     * @param  string|null $fromdate filter by from date (optional)
     * @param  string|null $filter possibility to filter orders (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customername filter by customer name (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $label filter by label (optional)
     * @param  string|null $documentnumber filter by document number (optional)
     * @param  string|null $externalinvoicereference1 filter by external invoice reference 1 (optional)
     * @param  string|null $externalinvoicereference2 filter by external invoice reference 2 (optional)
     * @param  string|null $costcenter filter by cost center (optional)
     * @param  string|null $project filter by project (optional)
     * @param  bool|null $sent filter by sent (optional)
     * @param  bool|null $notcompleted filter by not completed (optional)
     * @param  string|null $ourreference filter by ourreference (optional)
     * @param  string|null $yourreference filter by your reference (optional)
     * @param  string|null $lastmodified filter by lastmodified (optional)
     * @param  string|null $ordertype filter by order type (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoIndexAsync($todate = null, $fromdate = null, $filter = null, $sortby = null, $customername = null, $customernumber = null, $label = null, $documentnumber = null, $externalinvoicereference1 = null, $externalinvoicereference2 = null, $costcenter = null, $project = null, $sent = null, $notcompleted = null, $ourreference = null, $yourreference = null, $lastmodified = null, $ordertype = null, string $contentType = self::contentTypes['orderControllerDoIndex'][0])
    {
        return $this->orderControllerDoIndexAsyncWithHttpInfo($todate, $fromdate, $filter, $sortby, $customername, $customernumber, $label, $documentnumber, $externalinvoicereference1, $externalinvoicereference2, $costcenter, $project, $sent, $notcompleted, $ourreference, $yourreference, $lastmodified, $ordertype, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoIndexAsyncWithHttpInfo
     *
     * Retrieve a list of orders
     *
     * @param  string|null $todate filter by to date (optional)
     * @param  string|null $fromdate filter by from date (optional)
     * @param  string|null $filter possibility to filter orders (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customername filter by customer name (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $label filter by label (optional)
     * @param  string|null $documentnumber filter by document number (optional)
     * @param  string|null $externalinvoicereference1 filter by external invoice reference 1 (optional)
     * @param  string|null $externalinvoicereference2 filter by external invoice reference 2 (optional)
     * @param  string|null $costcenter filter by cost center (optional)
     * @param  string|null $project filter by project (optional)
     * @param  bool|null $sent filter by sent (optional)
     * @param  bool|null $notcompleted filter by not completed (optional)
     * @param  string|null $ourreference filter by ourreference (optional)
     * @param  string|null $yourreference filter by your reference (optional)
     * @param  string|null $lastmodified filter by lastmodified (optional)
     * @param  string|null $ordertype filter by order type (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoIndexAsyncWithHttpInfo($todate = null, $fromdate = null, $filter = null, $sortby = null, $customername = null, $customernumber = null, $label = null, $documentnumber = null, $externalinvoicereference1 = null, $externalinvoicereference2 = null, $costcenter = null, $project = null, $sent = null, $notcompleted = null, $ourreference = null, $yourreference = null, $lastmodified = null, $ordertype = null, string $contentType = self::contentTypes['orderControllerDoIndex'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderListResponseWrap';
        $request = $this->orderControllerDoIndexRequest($todate, $fromdate, $filter, $sortby, $customername, $customernumber, $label, $documentnumber, $externalinvoicereference1, $externalinvoicereference2, $costcenter, $project, $sent, $notcompleted, $ourreference, $yourreference, $lastmodified, $ordertype, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoIndex'
     *
     * @param  string|null $todate filter by to date (optional)
     * @param  string|null $fromdate filter by from date (optional)
     * @param  string|null $filter possibility to filter orders (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customername filter by customer name (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $label filter by label (optional)
     * @param  string|null $documentnumber filter by document number (optional)
     * @param  string|null $externalinvoicereference1 filter by external invoice reference 1 (optional)
     * @param  string|null $externalinvoicereference2 filter by external invoice reference 2 (optional)
     * @param  string|null $costcenter filter by cost center (optional)
     * @param  string|null $project filter by project (optional)
     * @param  bool|null $sent filter by sent (optional)
     * @param  bool|null $notcompleted filter by not completed (optional)
     * @param  string|null $ourreference filter by ourreference (optional)
     * @param  string|null $yourreference filter by your reference (optional)
     * @param  string|null $lastmodified filter by lastmodified (optional)
     * @param  string|null $ordertype filter by order type (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoIndexRequest($todate = null, $fromdate = null, $filter = null, $sortby = null, $customername = null, $customernumber = null, $label = null, $documentnumber = null, $externalinvoicereference1 = null, $externalinvoicereference2 = null, $costcenter = null, $project = null, $sent = null, $notcompleted = null, $ourreference = null, $yourreference = null, $lastmodified = null, $ordertype = null, string $contentType = self::contentTypes['orderControllerDoIndex'][0])
    {




















        $resourcePath = '/3/orders';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $todate,
            'todate', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fromdate,
            'fromdate', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $filter,
            'filter', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $sortby,
            'sortby', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $customername,
            'customername', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $customernumber,
            'customernumber', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $label,
            'label', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $documentnumber,
            'documentnumber', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $externalinvoicereference1,
            'externalinvoicereference1', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $externalinvoicereference2,
            'externalinvoicereference2', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $costcenter,
            'costcenter', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $project,
            'project', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $sent,
            'sent', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $notcompleted,
            'notcompleted', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $ourreference,
            'ourreference', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $yourreference,
            'yourreference', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $lastmodified,
            'lastmodified', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $ordertype,
            'ordertype', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);




        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation orderControllerDoShow
     *
     * Retrieve a single order
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShow'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoShow($document_number, string $contentType = self::contentTypes['orderControllerDoShow'][0])
    {
        list($response) = $this->orderControllerDoShowWithHttpInfo($document_number, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoShowWithHttpInfo
     *
     * Retrieve a single order
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShow'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoShowWithHttpInfo($document_number, string $contentType = self::contentTypes['orderControllerDoShow'][0])
    {
        $request = $this->orderControllerDoShowRequest($document_number, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoShowAsync
     *
     * Retrieve a single order
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoShowAsync($document_number, string $contentType = self::contentTypes['orderControllerDoShow'][0])
    {
        return $this->orderControllerDoShowAsyncWithHttpInfo($document_number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoShowAsyncWithHttpInfo
     *
     * Retrieve a single order
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoShowAsyncWithHttpInfo($document_number, string $contentType = self::contentTypes['orderControllerDoShow'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderResponseWrap';
        $request = $this->orderControllerDoShowRequest($document_number, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoShow'
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoShowRequest($document_number, string $contentType = self::contentTypes['orderControllerDoShow'][0])
    {

        // verify the required parameter 'document_number' is set
        if ($document_number === null || (is_array($document_number) && count($document_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $document_number when calling orderControllerDoShow'
            );
        }


        $resourcePath = '/3/orders/{DocumentNumber}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($document_number !== null) {
            $resourcePath = str_replace(
                '{' . 'DocumentNumber' . '}',
                ObjectSerializer::toPathValue($document_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation orderControllerDoShowAndEmail
     *
     * Send given order as email
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndEmail'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoShowAndEmail($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndEmail'][0])
    {
        list($response) = $this->orderControllerDoShowAndEmailWithHttpInfo($document_number, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoShowAndEmailWithHttpInfo
     *
     * Send given order as email
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndEmail'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoShowAndEmailWithHttpInfo($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndEmail'][0])
    {
        $request = $this->orderControllerDoShowAndEmailRequest($document_number, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoShowAndEmailAsync
     *
     * Send given order as email
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndEmail'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoShowAndEmailAsync($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndEmail'][0])
    {
        return $this->orderControllerDoShowAndEmailAsyncWithHttpInfo($document_number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoShowAndEmailAsyncWithHttpInfo
     *
     * Send given order as email
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndEmail'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoShowAndEmailAsyncWithHttpInfo($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndEmail'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderResponseWrap';
        $request = $this->orderControllerDoShowAndEmailRequest($document_number, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoShowAndEmail'
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndEmail'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoShowAndEmailRequest($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndEmail'][0])
    {

        // verify the required parameter 'document_number' is set
        if ($document_number === null || (is_array($document_number) && count($document_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $document_number when calling orderControllerDoShowAndEmail'
            );
        }


        $resourcePath = '/3/orders/{DocumentNumber}/email';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($document_number !== null) {
            $resourcePath = str_replace(
                '{' . 'DocumentNumber' . '}',
                ObjectSerializer::toPathValue($document_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation orderControllerDoShowAndPreview
     *
     * Preview given offer
     *
     * @param  string $document_number identifies the offer (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPreview'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoShowAndPreview($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPreview'][0])
    {
        list($response) = $this->orderControllerDoShowAndPreviewWithHttpInfo($document_number, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoShowAndPreviewWithHttpInfo
     *
     * Preview given offer
     *
     * @param  string $document_number identifies the offer (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPreview'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoShowAndPreviewWithHttpInfo($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPreview'][0])
    {
        $request = $this->orderControllerDoShowAndPreviewRequest($document_number, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoShowAndPreviewAsync
     *
     * Preview given offer
     *
     * @param  string $document_number identifies the offer (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPreview'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoShowAndPreviewAsync($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPreview'][0])
    {
        return $this->orderControllerDoShowAndPreviewAsyncWithHttpInfo($document_number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoShowAndPreviewAsyncWithHttpInfo
     *
     * Preview given offer
     *
     * @param  string $document_number identifies the offer (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPreview'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoShowAndPreviewAsyncWithHttpInfo($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPreview'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderResponseWrap';
        $request = $this->orderControllerDoShowAndPreviewRequest($document_number, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoShowAndPreview'
     *
     * @param  string $document_number identifies the offer (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPreview'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoShowAndPreviewRequest($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPreview'][0])
    {

        // verify the required parameter 'document_number' is set
        if ($document_number === null || (is_array($document_number) && count($document_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $document_number when calling orderControllerDoShowAndPreview'
            );
        }


        $resourcePath = '/3/orders/{DocumentNumber}/preview';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($document_number !== null) {
            $resourcePath = str_replace(
                '{' . 'DocumentNumber' . '}',
                ObjectSerializer::toPathValue($document_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['application/pdf', 'application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation orderControllerDoShowAndPrint
     *
     * Print given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPrint'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoShowAndPrint($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPrint'][0])
    {
        list($response) = $this->orderControllerDoShowAndPrintWithHttpInfo($document_number, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoShowAndPrintWithHttpInfo
     *
     * Print given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPrint'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoShowAndPrintWithHttpInfo($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPrint'][0])
    {
        $request = $this->orderControllerDoShowAndPrintRequest($document_number, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoShowAndPrintAsync
     *
     * Print given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPrint'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoShowAndPrintAsync($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPrint'][0])
    {
        return $this->orderControllerDoShowAndPrintAsyncWithHttpInfo($document_number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoShowAndPrintAsyncWithHttpInfo
     *
     * Print given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPrint'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoShowAndPrintAsyncWithHttpInfo($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPrint'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderResponseWrap';
        $request = $this->orderControllerDoShowAndPrintRequest($document_number, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoShowAndPrint'
     *
     * @param  string $document_number identifies the order (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoShowAndPrint'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoShowAndPrintRequest($document_number, string $contentType = self::contentTypes['orderControllerDoShowAndPrint'][0])
    {

        // verify the required parameter 'document_number' is set
        if ($document_number === null || (is_array($document_number) && count($document_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $document_number when calling orderControllerDoShowAndPrint'
            );
        }


        $resourcePath = '/3/orders/{DocumentNumber}/print';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($document_number !== null) {
            $resourcePath = str_replace(
                '{' . 'DocumentNumber' . '}',
                ObjectSerializer::toPathValue($document_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['application/pdf', 'application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation orderControllerDoUpdate
     *
     * Update an order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoUpdate($document_number, $order = null, string $contentType = self::contentTypes['orderControllerDoUpdate'][0])
    {
        list($response) = $this->orderControllerDoUpdateWithHttpInfo($document_number, $order, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoUpdateWithHttpInfo
     *
     * Update an order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoUpdateWithHttpInfo($document_number, $order = null, string $contentType = self::contentTypes['orderControllerDoUpdate'][0])
    {
        $request = $this->orderControllerDoUpdateRequest($document_number, $order, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoUpdateAsync
     *
     * Update an order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoUpdateAsync($document_number, $order = null, string $contentType = self::contentTypes['orderControllerDoUpdate'][0])
    {
        return $this->orderControllerDoUpdateAsyncWithHttpInfo($document_number, $order, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoUpdateAsyncWithHttpInfo
     *
     * Update an order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoUpdateAsyncWithHttpInfo($document_number, $order = null, string $contentType = self::contentTypes['orderControllerDoUpdate'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderResponseWrap';
        $request = $this->orderControllerDoUpdateRequest($document_number, $order, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoUpdate'
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $order Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoUpdateRequest($document_number, $order = null, string $contentType = self::contentTypes['orderControllerDoUpdate'][0])
    {

        // verify the required parameter 'document_number' is set
        if ($document_number === null || (is_array($document_number) && count($document_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $document_number when calling orderControllerDoUpdate'
            );
        }



        $resourcePath = '/3/orders/{DocumentNumber}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($document_number !== null) {
            $resourcePath = str_replace(
                '{' . 'DocumentNumber' . '}',
                ObjectSerializer::toPathValue($document_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (isset($order)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($order));
            } else {
                $httpBody = $order;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'PUT',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation orderControllerDoUpdateAndCancel
     *
     * Cancels given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCancel'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoUpdateAndCancel($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCancel'][0])
    {
        list($response) = $this->orderControllerDoUpdateAndCancelWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoUpdateAndCancelWithHttpInfo
     *
     * Cancels given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCancel'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoUpdateAndCancelWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCancel'][0])
    {
        $request = $this->orderControllerDoUpdateAndCancelRequest($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoUpdateAndCancelAsync
     *
     * Cancels given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCancel'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoUpdateAndCancelAsync($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCancel'][0])
    {
        return $this->orderControllerDoUpdateAndCancelAsyncWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoUpdateAndCancelAsyncWithHttpInfo
     *
     * Cancels given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCancel'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoUpdateAndCancelAsyncWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCancel'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderResponseWrap';
        $request = $this->orderControllerDoUpdateAndCancelRequest($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoUpdateAndCancel'
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCancel'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoUpdateAndCancelRequest($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCancel'][0])
    {

        // verify the required parameter 'document_number' is set
        if ($document_number === null || (is_array($document_number) && count($document_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $document_number when calling orderControllerDoUpdateAndCancel'
            );
        }



        $resourcePath = '/3/orders/{DocumentNumber}/cancel';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($document_number !== null) {
            $resourcePath = str_replace(
                '{' . 'DocumentNumber' . '}',
                ObjectSerializer::toPathValue($document_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (isset($fortnox_order_order_single_payload_item_wrap)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($fortnox_order_order_single_payload_item_wrap));
            } else {
                $httpBody = $fortnox_order_order_single_payload_item_wrap;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'PUT',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation orderControllerDoUpdateAndCreateOrder
     *
     * Create invoice out of given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCreateOrder'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoUpdateAndCreateOrder($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCreateOrder'][0])
    {
        list($response) = $this->orderControllerDoUpdateAndCreateOrderWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoUpdateAndCreateOrderWithHttpInfo
     *
     * Create invoice out of given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCreateOrder'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoUpdateAndCreateOrderWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCreateOrder'][0])
    {
        $request = $this->orderControllerDoUpdateAndCreateOrderRequest($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoUpdateAndCreateOrderAsync
     *
     * Create invoice out of given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCreateOrder'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoUpdateAndCreateOrderAsync($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCreateOrder'][0])
    {
        return $this->orderControllerDoUpdateAndCreateOrderAsyncWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoUpdateAndCreateOrderAsyncWithHttpInfo
     *
     * Create invoice out of given order
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCreateOrder'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoUpdateAndCreateOrderAsyncWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCreateOrder'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderResponseWrap';
        $request = $this->orderControllerDoUpdateAndCreateOrderRequest($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoUpdateAndCreateOrder'
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndCreateOrder'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoUpdateAndCreateOrderRequest($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndCreateOrder'][0])
    {

        // verify the required parameter 'document_number' is set
        if ($document_number === null || (is_array($document_number) && count($document_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $document_number when calling orderControllerDoUpdateAndCreateOrder'
            );
        }



        $resourcePath = '/3/orders/{DocumentNumber}/createinvoice';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($document_number !== null) {
            $resourcePath = str_replace(
                '{' . 'DocumentNumber' . '}',
                ObjectSerializer::toPathValue($document_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (isset($fortnox_order_order_single_payload_item_wrap)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($fortnox_order_order_single_payload_item_wrap));
            } else {
                $httpBody = $fortnox_order_order_single_payload_item_wrap;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'PUT',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation orderControllerDoUpdateAndExternalPrint
     *
     * Set given order as sent
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndExternalPrint'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function orderControllerDoUpdateAndExternalPrint($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndExternalPrint'][0])
    {
        list($response) = $this->orderControllerDoUpdateAndExternalPrintWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType);
        return $response;
    }

    /**
     * Operation orderControllerDoUpdateAndExternalPrintWithHttpInfo
     *
     * Set given order as sent
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndExternalPrint'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\FortnoxOrderOrderResponseWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function orderControllerDoUpdateAndExternalPrintWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndExternalPrint'][0])
    {
        $request = $this->orderControllerDoUpdateAndExternalPrintRequest($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxOrderOrderResponseWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation orderControllerDoUpdateAndExternalPrintAsync
     *
     * Set given order as sent
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndExternalPrint'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoUpdateAndExternalPrintAsync($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndExternalPrint'][0])
    {
        return $this->orderControllerDoUpdateAndExternalPrintAsyncWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation orderControllerDoUpdateAndExternalPrintAsyncWithHttpInfo
     *
     * Set given order as sent
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndExternalPrint'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function orderControllerDoUpdateAndExternalPrintAsyncWithHttpInfo($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndExternalPrint'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxOrderOrderResponseWrap';
        $request = $this->orderControllerDoUpdateAndExternalPrintRequest($document_number, $fortnox_order_order_single_payload_item_wrap, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'orderControllerDoUpdateAndExternalPrint'
     *
     * @param  string $document_number identifies the order (required)
     * @param  \Fortnox\Model\FortnoxOrderOrderSinglePayloadItemWrap|null $fortnox_order_order_single_payload_item_wrap Request body for update order (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['orderControllerDoUpdateAndExternalPrint'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function orderControllerDoUpdateAndExternalPrintRequest($document_number, $fortnox_order_order_single_payload_item_wrap = null, string $contentType = self::contentTypes['orderControllerDoUpdateAndExternalPrint'][0])
    {

        // verify the required parameter 'document_number' is set
        if ($document_number === null || (is_array($document_number) && count($document_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $document_number when calling orderControllerDoUpdateAndExternalPrint'
            );
        }



        $resourcePath = '/3/orders/{DocumentNumber}/externalprint';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($document_number !== null) {
            $resourcePath = str_replace(
                '{' . 'DocumentNumber' . '}',
                ObjectSerializer::toPathValue($document_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (isset($fortnox_order_order_single_payload_item_wrap)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($fortnox_order_order_single_payload_item_wrap));
            } else {
                $httpBody = $fortnox_order_order_single_payload_item_wrap;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'PUT',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option
     *
     * @throws \RuntimeException on file opening failure
     * @return array of http client options
     */
    protected function createHttpClientOption()
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
            }
        }

        if ($this->config->getCertFile()) {
            $options[RequestOptions::CERT] = $this->config->getCertFile();
        }

        if ($this->config->getKeyFile()) {
            $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
        }

        return $options;
    }

    private function handleResponseWithDataType(
        string $dataType,
        RequestInterface $request,
        ResponseInterface $response
    ): array {
        if ($dataType === '\SplFileObject') {
            $content = $response->getBody(); //stream goes to serializer
        } else {
            $content = (string) $response->getBody();
            if ($dataType !== 'string') {
                try {
                    $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
                } catch (\JsonException $exception) {
                    throw new ApiException(
                        sprintf(
                            'Error JSON decoding server response (%s)',
                            $request->getUri()
                        ),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                        $content
                    );
                }
            }
        }

        return [
            ObjectSerializer::deserialize($content, $dataType, []),
            $response->getStatusCode(),
            $response->getHeaders()
        ];
    }

    private function responseWithinRangeCode(
        string $rangeCode,
        int $statusCode
    ): bool {
        $left = (int) ($rangeCode[0].'00');
        $right = (int) ($rangeCode[0].'99');

        return $statusCode >= $left && $statusCode <= $right;
    }
}
