<?php
/**
 * FortnoxSupplierInvoicePaymentsApi
 * 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;

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'supplierInvoicePaymentControllerDoCreate' => [
            'application/json',
        ],
        'supplierInvoicePaymentControllerDoDelete' => [
            'application/json',
        ],
        'supplierInvoicePaymentControllerDoIndex' => [
            'application/json',
        ],
        'supplierInvoicePaymentControllerDoShow' => [
            'application/json',
        ],
        'supplierInvoicePaymentControllerDoUpdate' => [
            'application/json',
        ],
        'supplierInvoicePaymentControllerDoUpdateAndBookkeep' => [
            '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 supplierInvoicePaymentControllerDoCreate
     *
     * Create a supplier invoice payment
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for create supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoCreate'] 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\FortnoxLfSupplierInvoicePaymentSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoicePaymentControllerDoCreate($supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoCreate'][0])
    {
        list($response) = $this->supplierInvoicePaymentControllerDoCreateWithHttpInfo($supplier_invoice_payment, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoicePaymentControllerDoCreateWithHttpInfo
     *
     * Create a supplier invoice payment
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for create supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoCreate'] 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\FortnoxLfSupplierInvoicePaymentSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoicePaymentControllerDoCreateWithHttpInfo($supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoCreate'][0])
    {
        $request = $this->supplierInvoicePaymentControllerDoCreateRequest($supplier_invoice_payment, $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\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                        $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\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                        $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 supplierInvoicePaymentControllerDoCreateAsync
     *
     * Create a supplier invoice payment
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for create supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoCreateAsync($supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoCreate'][0])
    {
        return $this->supplierInvoicePaymentControllerDoCreateAsyncWithHttpInfo($supplier_invoice_payment, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoicePaymentControllerDoCreateAsyncWithHttpInfo
     *
     * Create a supplier invoice payment
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for create supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoCreateAsyncWithHttpInfo($supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoCreate'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentSingleItemWrap';
        $request = $this->supplierInvoicePaymentControllerDoCreateRequest($supplier_invoice_payment, $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 'supplierInvoicePaymentControllerDoCreate'
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for create supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoicePaymentControllerDoCreateRequest($supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoCreate'][0])
    {



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





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

        // for model (json/xml)
        if (isset($supplier_invoice_payment)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($supplier_invoice_payment));
            } else {
                $httpBody = $supplier_invoice_payment;
            }
        } 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 supplierInvoicePaymentControllerDoDelete
     *
     * Remove a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoDelete'] 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 void
     */
    public function supplierInvoicePaymentControllerDoDelete($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoDelete'][0])
    {
        $this->supplierInvoicePaymentControllerDoDeleteWithHttpInfo($number, $contentType);
    }

    /**
     * Operation supplierInvoicePaymentControllerDoDeleteWithHttpInfo
     *
     * Remove a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoDelete'] 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 null, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoicePaymentControllerDoDeleteWithHttpInfo($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoDelete'][0])
    {
        $request = $this->supplierInvoicePaymentControllerDoDeleteRequest($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();


            return [null, $statusCode, $response->getHeaders()];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                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 supplierInvoicePaymentControllerDoDeleteAsync
     *
     * Remove a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoDelete'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoDeleteAsync($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoDelete'][0])
    {
        return $this->supplierInvoicePaymentControllerDoDeleteAsyncWithHttpInfo($number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoicePaymentControllerDoDeleteAsyncWithHttpInfo
     *
     * Remove a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoDelete'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoDeleteAsyncWithHttpInfo($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoDelete'][0])
    {
        $returnType = '';
        $request = $this->supplierInvoicePaymentControllerDoDeleteRequest($number, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $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 'supplierInvoicePaymentControllerDoDelete'
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoDelete'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoicePaymentControllerDoDeleteRequest($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoDelete'][0])
    {

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


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



        // path params
        if ($number !== null) {
            $resourcePath = str_replace(
                '{' . 'Number' . '}',
                ObjectSerializer::toPathValue($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(
            'DELETE',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation supplierInvoicePaymentControllerDoIndex
     *
     * Retrieve a list of supplier invoice payments
     *
     * @param  int|null $invoicenumber Filter payments by invoice number (optional)
     * @param  \DateTime|null $lastmodified Filter payments by last modified date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoIndex'] 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\FortnoxLfSupplierInvoicePaymentListItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoicePaymentControllerDoIndex($invoicenumber = null, $lastmodified = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoIndex'][0])
    {
        list($response) = $this->supplierInvoicePaymentControllerDoIndexWithHttpInfo($invoicenumber, $lastmodified, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoicePaymentControllerDoIndexWithHttpInfo
     *
     * Retrieve a list of supplier invoice payments
     *
     * @param  int|null $invoicenumber Filter payments by invoice number (optional)
     * @param  \DateTime|null $lastmodified Filter payments by last modified date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoIndex'] 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\FortnoxLfSupplierInvoicePaymentListItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoicePaymentControllerDoIndexWithHttpInfo($invoicenumber = null, $lastmodified = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoIndex'][0])
    {
        $request = $this->supplierInvoicePaymentControllerDoIndexRequest($invoicenumber, $lastmodified, $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\FortnoxLfSupplierInvoicePaymentListItemWrap',
                        $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\FortnoxLfSupplierInvoicePaymentListItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentListItemWrap',
                        $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 supplierInvoicePaymentControllerDoIndexAsync
     *
     * Retrieve a list of supplier invoice payments
     *
     * @param  int|null $invoicenumber Filter payments by invoice number (optional)
     * @param  \DateTime|null $lastmodified Filter payments by last modified date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoIndexAsync($invoicenumber = null, $lastmodified = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoIndex'][0])
    {
        return $this->supplierInvoicePaymentControllerDoIndexAsyncWithHttpInfo($invoicenumber, $lastmodified, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoicePaymentControllerDoIndexAsyncWithHttpInfo
     *
     * Retrieve a list of supplier invoice payments
     *
     * @param  int|null $invoicenumber Filter payments by invoice number (optional)
     * @param  \DateTime|null $lastmodified Filter payments by last modified date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoIndexAsyncWithHttpInfo($invoicenumber = null, $lastmodified = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoIndex'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentListItemWrap';
        $request = $this->supplierInvoicePaymentControllerDoIndexRequest($invoicenumber, $lastmodified, $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 'supplierInvoicePaymentControllerDoIndex'
     *
     * @param  int|null $invoicenumber Filter payments by invoice number (optional)
     * @param  \DateTime|null $lastmodified Filter payments by last modified date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoicePaymentControllerDoIndexRequest($invoicenumber = null, $lastmodified = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoIndex'][0])
    {




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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $invoicenumber,
            'invoicenumber', // param base name
            'integer', // 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
        ) ?? []);




        $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 supplierInvoicePaymentControllerDoShow
     *
     * Retrieve a single supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoShow'] 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\FortnoxLfSupplierInvoicePaymentSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoicePaymentControllerDoShow($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoShow'][0])
    {
        list($response) = $this->supplierInvoicePaymentControllerDoShowWithHttpInfo($number, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoicePaymentControllerDoShowWithHttpInfo
     *
     * Retrieve a single supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoShow'] 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\FortnoxLfSupplierInvoicePaymentSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoicePaymentControllerDoShowWithHttpInfo($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoShow'][0])
    {
        $request = $this->supplierInvoicePaymentControllerDoShowRequest($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\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                        $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\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                        $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 supplierInvoicePaymentControllerDoShowAsync
     *
     * Retrieve a single supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoShowAsync($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoShow'][0])
    {
        return $this->supplierInvoicePaymentControllerDoShowAsyncWithHttpInfo($number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoicePaymentControllerDoShowAsyncWithHttpInfo
     *
     * Retrieve a single supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoShowAsyncWithHttpInfo($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoShow'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentSingleItemWrap';
        $request = $this->supplierInvoicePaymentControllerDoShowRequest($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 'supplierInvoicePaymentControllerDoShow'
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoicePaymentControllerDoShowRequest($number, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoShow'][0])
    {

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


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



        // path params
        if ($number !== null) {
            $resourcePath = str_replace(
                '{' . 'Number' . '}',
                ObjectSerializer::toPathValue($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 supplierInvoicePaymentControllerDoUpdate
     *
     * Update a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdate'] 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\FortnoxLfSupplierInvoicePaymentSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoicePaymentControllerDoUpdate($number, $supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdate'][0])
    {
        list($response) = $this->supplierInvoicePaymentControllerDoUpdateWithHttpInfo($number, $supplier_invoice_payment, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoicePaymentControllerDoUpdateWithHttpInfo
     *
     * Update a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdate'] 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\FortnoxLfSupplierInvoicePaymentSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoicePaymentControllerDoUpdateWithHttpInfo($number, $supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdate'][0])
    {
        $request = $this->supplierInvoicePaymentControllerDoUpdateRequest($number, $supplier_invoice_payment, $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\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                        $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\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                        $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 supplierInvoicePaymentControllerDoUpdateAsync
     *
     * Update a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoUpdateAsync($number, $supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdate'][0])
    {
        return $this->supplierInvoicePaymentControllerDoUpdateAsyncWithHttpInfo($number, $supplier_invoice_payment, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoicePaymentControllerDoUpdateAsyncWithHttpInfo
     *
     * Update a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoUpdateAsyncWithHttpInfo($number, $supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdate'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentSingleItemWrap';
        $request = $this->supplierInvoicePaymentControllerDoUpdateRequest($number, $supplier_invoice_payment, $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 'supplierInvoicePaymentControllerDoUpdate'
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $supplier_invoice_payment Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoicePaymentControllerDoUpdateRequest($number, $supplier_invoice_payment = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdate'][0])
    {

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



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



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


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

        // for model (json/xml)
        if (isset($supplier_invoice_payment)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($supplier_invoice_payment));
            } else {
                $httpBody = $supplier_invoice_payment;
            }
        } 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 supplierInvoicePaymentControllerDoUpdateAndBookkeep
     *
     * Bookkeep a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'] 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\FortnoxLfSupplierInvoicePaymentSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoicePaymentControllerDoUpdateAndBookkeep($number, $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'][0])
    {
        list($response) = $this->supplierInvoicePaymentControllerDoUpdateAndBookkeepWithHttpInfo($number, $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoicePaymentControllerDoUpdateAndBookkeepWithHttpInfo
     *
     * Bookkeep a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'] 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\FortnoxLfSupplierInvoicePaymentSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoicePaymentControllerDoUpdateAndBookkeepWithHttpInfo($number, $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'][0])
    {
        $request = $this->supplierInvoicePaymentControllerDoUpdateAndBookkeepRequest($number, $fortnox_lf_supplier_invoice_payment_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\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                        $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\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentSingleItemWrap',
                        $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 supplierInvoicePaymentControllerDoUpdateAndBookkeepAsync
     *
     * Bookkeep a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoUpdateAndBookkeepAsync($number, $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'][0])
    {
        return $this->supplierInvoicePaymentControllerDoUpdateAndBookkeepAsyncWithHttpInfo($number, $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoicePaymentControllerDoUpdateAndBookkeepAsyncWithHttpInfo
     *
     * Bookkeep a supplier invoice payment
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoicePaymentControllerDoUpdateAndBookkeepAsyncWithHttpInfo($number, $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoicePaymentSingleItemWrap';
        $request = $this->supplierInvoicePaymentControllerDoUpdateAndBookkeepRequest($number, $fortnox_lf_supplier_invoice_payment_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 'supplierInvoicePaymentControllerDoUpdateAndBookkeep'
     *
     * @param  int $number identifies the supplier invoice payment (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoicePaymentSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap Request body for update supplier invoice payment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoicePaymentControllerDoUpdateAndBookkeepRequest($number, $fortnox_lf_supplier_invoice_payment_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoicePaymentControllerDoUpdateAndBookkeep'][0])
    {

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



        $resourcePath = '/3/supplierinvoicepayments/{Number}/bookkeep';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($fortnox_lf_supplier_invoice_payment_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_lf_supplier_invoice_payment_single_payload_item_wrap));
            } else {
                $httpBody = $fortnox_lf_supplier_invoice_payment_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;
    }
}
