<?php
/**
 * InstallmentPlanApi
 * PHP version 7.4
 *
 * @category Class
 * @package  Splitit
 * @author   Konfig
 * @link     https://konfigthis.com
 */

/**
 * splitit-web-api-v3
 *
 * Splitit's Web API
 *
 * The version of the OpenAPI document: 1.0.0
 * Generated by: https://konfigthis.com
 */


namespace Splitit\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 GuzzleHttp\BodySummarizer;
use GuzzleHttp\Middleware;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Utils;
use Splitit\ApiException;
use Splitit\Configuration;
use Splitit\HeaderSelector;
use Splitit\ObjectSerializer;

class InstallmentPlanApi extends \Splitit\CustomApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'cancel' => [
            'application/json',
        ],
        'checkEligibility' => [
            'application/json-patch+json',
            'application/json',
            'text/json',
            'application/*+json',
        ],
        'get' => [
            'application/json',
        ],
        'post' => [
            'application/json-patch+json',
            'application/json',
            'text/json',
            'application/*+json',
        ],
        'post2' => [
            'application/json-patch+json',
            'application/json',
            'text/json',
            'application/*+json',
        ],
        'refund' => [
            'application/json-patch+json',
            'application/json',
            'text/json',
            'application/*+json',
        ],
        'search' => [
            'application/json',
        ],
        'updateOrder' => [
            'application/json-patch+json',
            'application/json',
            'text/json',
            'application/*+json',
        ],
        'updateOrder2' => [
            'application/json-patch+json',
            'application/json',
            'text/json',
            'application/*+json',
        ],
        'verifyAuthorization' => [
            '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(
        Configuration $config = null,
        ClientInterface $client = null,
        HeaderSelector $selector = null,
        $hostIndex = 0
    ) {
        $clientOptions = [];
        if (!$config->getVerifySsl()) $clientOptions["verify"] = false;

        // Do not truncate error messages
        // https://github.com/guzzle/guzzle/issues/2185#issuecomment-800293420
        $stack = new HandlerStack(Utils::chooseHandler());
        $stack->push(Middleware::httpErrors(new BodySummarizer(10000)), 'http_errors');
        $stack->push(Middleware::redirect(), 'allow_redirects');
        $stack->push(Middleware::cookies(), 'cookies');
        $stack->push(Middleware::prepareBody(), 'prepare_body');
        $clientOptions["handler"] = $stack;

        $this->client = $client ?: new Client($clientOptions);
        $this->config = $config ?: new Configuration();
        $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;
    }

    /**
     * For initializing request body parameter
     */
    private function setRequestBodyProperty(&$body, $property, $value) {
        if ($body === null) $body = [];
        // user did not pass in a value for this parameter
        if ($value === SENTINEL_VALUE) return;
        $body[$property] = $value;
    }

    /**
     * Operation cancel
     *
     * @param  string $installment_plan_number installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['cancel'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\InstallmentPlanCancelResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function cancel(
        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,


        string $contentType = self::contentTypes['cancel'][0]

    )
    {

        list($response) = $this->cancelWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType);
        return $response;
    }

    /**
     * Operation cancelWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['cancel'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\InstallmentPlanCancelResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function cancelWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, string $contentType = self::contentTypes['cancel'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->cancelRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->cancelWithHttpInfo(
                        $installment_plan_number,
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\InstallmentPlanCancelResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\InstallmentPlanCancelResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\InstallmentPlanCancelResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\InstallmentPlanCancelResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\InstallmentPlanCancelResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation cancelAsync
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['cancel'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function cancelAsync(
        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,


        string $contentType = self::contentTypes['cancel'][0]

    )
    {

        return $this->cancelAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation cancelAsyncWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['cancel'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function cancelAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, string $contentType = self::contentTypes['cancel'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\InstallmentPlanCancelResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->cancelRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config);

        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 'cancel'
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['cancel'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function cancelRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, string $contentType = self::contentTypes['cancel'][0])
    {

        // Check if $installment_plan_number is a string
        if ($installment_plan_number !== SENTINEL_VALUE && !is_string($installment_plan_number)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($installment_plan_number, true), gettype($installment_plan_number)));
        }
        // verify the required parameter 'installment_plan_number' is set
        if ($installment_plan_number === SENTINEL_VALUE || (is_array($installment_plan_number) && count($installment_plan_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter installment_plan_number when calling cancel'
            );
        }
        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling cancel'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling cancel'
            );
        }


        $resourcePath = '/api/installmentplans/{installmentPlanNumber}/cancel';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }

        // path params
        if ($installment_plan_number !== SENTINEL_VALUE) {
            $resourcePath = str_replace(
                '{' . 'installmentPlanNumber' . '}',
                ObjectSerializer::toPathValue($installment_plan_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['text/plain', 'application/json', 'text/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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'POST';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

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

    /**
     * Operation checkEligibility
     *
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\CheckInstallmentsEligibilityRequest $check_installments_eligibility_request check_installments_eligibility_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['checkEligibility'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\InstallmentsEligibilityResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function checkEligibility(

        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $plan_data = SENTINEL_VALUE,
        $card_details = SENTINEL_VALUE,
        $billing_address = SENTINEL_VALUE,

        string $contentType = self::contentTypes['checkEligibility'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "plan_data", $plan_data);
        $this->setRequestBodyProperty($_body, "card_details", $card_details);
        $this->setRequestBodyProperty($_body, "billing_address", $billing_address);
        $check_installments_eligibility_request = $_body;

        list($response) = $this->checkEligibilityWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $check_installments_eligibility_request, $contentType);
        return $response;
    }

    /**
     * Operation checkEligibilityWithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\CheckInstallmentsEligibilityRequest $check_installments_eligibility_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['checkEligibility'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\InstallmentsEligibilityResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function checkEligibilityWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $check_installments_eligibility_request, string $contentType = self::contentTypes['checkEligibility'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->checkEligibilityRequest($x_splitit_idempotency_key, $x_splitit_touch_point, $check_installments_eligibility_request, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->checkEligibilityWithHttpInfo(
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $check_installments_eligibility_request,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\InstallmentsEligibilityResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\InstallmentsEligibilityResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\InstallmentsEligibilityResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\InstallmentsEligibilityResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\InstallmentsEligibilityResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation checkEligibilityAsync
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\CheckInstallmentsEligibilityRequest $check_installments_eligibility_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['checkEligibility'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function checkEligibilityAsync(

        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $plan_data = SENTINEL_VALUE,
        $card_details = SENTINEL_VALUE,
        $billing_address = SENTINEL_VALUE,

        string $contentType = self::contentTypes['checkEligibility'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "plan_data", $plan_data);
        $this->setRequestBodyProperty($_body, "card_details", $card_details);
        $this->setRequestBodyProperty($_body, "billing_address", $billing_address);
        $check_installments_eligibility_request = $_body;

        return $this->checkEligibilityAsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $check_installments_eligibility_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation checkEligibilityAsyncWithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\CheckInstallmentsEligibilityRequest $check_installments_eligibility_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['checkEligibility'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function checkEligibilityAsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $check_installments_eligibility_request, string $contentType = self::contentTypes['checkEligibility'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\InstallmentsEligibilityResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->checkEligibilityRequest($x_splitit_idempotency_key, $x_splitit_touch_point, $check_installments_eligibility_request, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        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 'checkEligibility'
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\CheckInstallmentsEligibilityRequest $check_installments_eligibility_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['checkEligibility'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function checkEligibilityRequest($x_splitit_idempotency_key, $x_splitit_touch_point, $check_installments_eligibility_request, string $contentType = self::contentTypes['checkEligibility'][0])
    {

        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling checkEligibility'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling checkEligibility'
            );
        }
        if ($check_installments_eligibility_request !== SENTINEL_VALUE) {
            if (!($check_installments_eligibility_request instanceof \Splitit\Model\CheckInstallmentsEligibilityRequest)) {
                if (!is_array($check_installments_eligibility_request))
                    throw new \InvalidArgumentException('"check_installments_eligibility_request" must be associative array or an instance of \Splitit\Model\CheckInstallmentsEligibilityRequest InstallmentPlanApi.checkEligibility.');
                else
                    $check_installments_eligibility_request = new \Splitit\Model\CheckInstallmentsEligibilityRequest($check_installments_eligibility_request);
            }
        }
        // verify the required parameter 'check_installments_eligibility_request' is set
        if ($check_installments_eligibility_request === SENTINEL_VALUE || (is_array($check_installments_eligibility_request) && count($check_installments_eligibility_request) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter check_installments_eligibility_request when calling checkEligibility'
            );
        }


        $resourcePath = '/api/installmentplans/check-eligibility';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }



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

        // for model (json/xml)
        if (isset($check_installments_eligibility_request)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($check_installments_eligibility_request));
            } else {
                $httpBody = $check_installments_eligibility_request;
            }
        } 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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'POST';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

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

    /**
     * Operation get
     *
     * @param  string $installment_plan_number installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\InstallmentPlanGetResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function get(
        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,


        string $contentType = self::contentTypes['get'][0]

    )
    {

        list($response) = $this->getWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType);
        return $response;
    }

    /**
     * Operation getWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\InstallmentPlanGetResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, string $contentType = self::contentTypes['get'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->getRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->getWithHttpInfo(
                        $installment_plan_number,
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\InstallmentPlanGetResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\InstallmentPlanGetResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\InstallmentPlanGetResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\InstallmentPlanGetResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\InstallmentPlanGetResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getAsync
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAsync(
        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,


        string $contentType = self::contentTypes['get'][0]

    )
    {

        return $this->getAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getAsyncWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, string $contentType = self::contentTypes['get'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\InstallmentPlanGetResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->getRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config);

        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 'get'
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, string $contentType = self::contentTypes['get'][0])
    {

        // Check if $installment_plan_number is a string
        if ($installment_plan_number !== SENTINEL_VALUE && !is_string($installment_plan_number)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($installment_plan_number, true), gettype($installment_plan_number)));
        }
        // verify the required parameter 'installment_plan_number' is set
        if ($installment_plan_number === SENTINEL_VALUE || (is_array($installment_plan_number) && count($installment_plan_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter installment_plan_number when calling get'
            );
        }
        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling get'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling get'
            );
        }


        $resourcePath = '/api/installmentplans/{installmentPlanNumber}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }

        // path params
        if ($installment_plan_number !== SENTINEL_VALUE) {
            $resourcePath = str_replace(
                '{' . 'installmentPlanNumber' . '}',
                ObjectSerializer::toPathValue($installment_plan_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['text/plain', 'application/json', 'text/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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'GET';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

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

    /**
     * Operation post
     *
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanInitiateRequest $installment_plan_initiate_request installment_plan_initiate_request (required)
     * @param  string $x_splitit_test_mode x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\InitiatePlanResponse|\Splitit\Model\PlanErrorResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function post(

        $auto_capture,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $attempt3d_secure = SENTINEL_VALUE,
        $shopper = SENTINEL_VALUE,
        $plan_data = SENTINEL_VALUE,
        $billing_address = SENTINEL_VALUE,
        $redirect_urls = SENTINEL_VALUE,
        $ux_settings = SENTINEL_VALUE,
        $events_endpoints = SENTINEL_VALUE,
        $processing_data = SENTINEL_VALUE,
        $x_splitit_test_mode = SENTINEL_VALUE,

        string $contentType = self::contentTypes['post'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "auto_capture", $auto_capture);
        $this->setRequestBodyProperty($_body, "attempt3d_secure", $attempt3d_secure);
        $this->setRequestBodyProperty($_body, "shopper", $shopper);
        $this->setRequestBodyProperty($_body, "plan_data", $plan_data);
        $this->setRequestBodyProperty($_body, "billing_address", $billing_address);
        $this->setRequestBodyProperty($_body, "redirect_urls", $redirect_urls);
        $this->setRequestBodyProperty($_body, "ux_settings", $ux_settings);
        $this->setRequestBodyProperty($_body, "events_endpoints", $events_endpoints);
        $this->setRequestBodyProperty($_body, "processing_data", $processing_data);
        $installment_plan_initiate_request = $_body;

        list($response) = $this->postWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_initiate_request, $x_splitit_test_mode, $contentType);
        return $response;
    }

    /**
     * Operation postWithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanInitiateRequest $installment_plan_initiate_request (required)
     * @param  string $x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\InitiatePlanResponse|\Splitit\Model\PlanErrorResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_initiate_request, $x_splitit_test_mode = null, string $contentType = self::contentTypes['post'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->postRequest($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_initiate_request, $x_splitit_test_mode, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->postWithHttpInfo(
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $installment_plan_initiate_request,
                        $x_splitit_test_mode,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\InitiatePlanResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\InitiatePlanResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\InitiatePlanResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\Splitit\Model\PlanErrorResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\PlanErrorResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\PlanErrorResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\InitiatePlanResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\InitiatePlanResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\PlanErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation postAsync
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanInitiateRequest $installment_plan_initiate_request (required)
     * @param  string $x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postAsync(

        $auto_capture,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $attempt3d_secure = SENTINEL_VALUE,
        $shopper = SENTINEL_VALUE,
        $plan_data = SENTINEL_VALUE,
        $billing_address = SENTINEL_VALUE,
        $redirect_urls = SENTINEL_VALUE,
        $ux_settings = SENTINEL_VALUE,
        $events_endpoints = SENTINEL_VALUE,
        $processing_data = SENTINEL_VALUE,
        $x_splitit_test_mode = SENTINEL_VALUE,

        string $contentType = self::contentTypes['post'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "auto_capture", $auto_capture);
        $this->setRequestBodyProperty($_body, "attempt3d_secure", $attempt3d_secure);
        $this->setRequestBodyProperty($_body, "shopper", $shopper);
        $this->setRequestBodyProperty($_body, "plan_data", $plan_data);
        $this->setRequestBodyProperty($_body, "billing_address", $billing_address);
        $this->setRequestBodyProperty($_body, "redirect_urls", $redirect_urls);
        $this->setRequestBodyProperty($_body, "ux_settings", $ux_settings);
        $this->setRequestBodyProperty($_body, "events_endpoints", $events_endpoints);
        $this->setRequestBodyProperty($_body, "processing_data", $processing_data);
        $installment_plan_initiate_request = $_body;

        return $this->postAsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_initiate_request, $x_splitit_test_mode, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postAsyncWithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanInitiateRequest $installment_plan_initiate_request (required)
     * @param  string $x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postAsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_initiate_request, $x_splitit_test_mode = null, string $contentType = self::contentTypes['post'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\InitiatePlanResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->postRequest($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_initiate_request, $x_splitit_test_mode, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        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 'post'
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanInitiateRequest $installment_plan_initiate_request (required)
     * @param  string $x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function postRequest($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_initiate_request, $x_splitit_test_mode = SENTINEL_VALUE, string $contentType = self::contentTypes['post'][0])
    {

        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling post'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling post'
            );
        }
        if ($installment_plan_initiate_request !== SENTINEL_VALUE) {
            if (!($installment_plan_initiate_request instanceof \Splitit\Model\InstallmentPlanInitiateRequest)) {
                if (!is_array($installment_plan_initiate_request))
                    throw new \InvalidArgumentException('"installment_plan_initiate_request" must be associative array or an instance of \Splitit\Model\InstallmentPlanInitiateRequest InstallmentPlanApi.post.');
                else
                    $installment_plan_initiate_request = new \Splitit\Model\InstallmentPlanInitiateRequest($installment_plan_initiate_request);
            }
        }
        // verify the required parameter 'installment_plan_initiate_request' is set
        if ($installment_plan_initiate_request === SENTINEL_VALUE || (is_array($installment_plan_initiate_request) && count($installment_plan_initiate_request) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter installment_plan_initiate_request when calling post'
            );
        }
        // Check if $x_splitit_test_mode is a string
        if ($x_splitit_test_mode !== SENTINEL_VALUE && !is_string($x_splitit_test_mode)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_test_mode, true), gettype($x_splitit_test_mode)));
        }


        $resourcePath = '/api/installmentplans/initiate';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // header params
        if ($x_splitit_test_mode !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TestMode'] = ObjectSerializer::toHeaderValue($x_splitit_test_mode);
        }
        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }



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

        // for model (json/xml)
        if (isset($installment_plan_initiate_request)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($installment_plan_initiate_request));
            } else {
                $httpBody = $installment_plan_initiate_request;
            }
        } 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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'POST';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

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

    /**
     * Operation post2
     *
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanCreateRequest $installment_plan_create_request installment_plan_create_request (required)
     * @param  string $x_splitit_test_mode x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post2'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\InstallmentPlanCreateResponse|\Splitit\Model\PlanErrorResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function post2(

        $auto_capture,
        $terms_and_conditions_accepted,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $attempt3d_secure = SENTINEL_VALUE,
        $shopper = SENTINEL_VALUE,
        $plan_data = SENTINEL_VALUE,
        $billing_address = SENTINEL_VALUE,
        $payment_method = SENTINEL_VALUE,
        $redirect_urls = SENTINEL_VALUE,
        $processing_data = SENTINEL_VALUE,
        $events_endpoints = SENTINEL_VALUE,
        $x_splitit_test_mode = SENTINEL_VALUE,

        string $contentType = self::contentTypes['post2'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "auto_capture", $auto_capture);
        $this->setRequestBodyProperty($_body, "attempt3d_secure", $attempt3d_secure);
        $this->setRequestBodyProperty($_body, "terms_and_conditions_accepted", $terms_and_conditions_accepted);
        $this->setRequestBodyProperty($_body, "shopper", $shopper);
        $this->setRequestBodyProperty($_body, "plan_data", $plan_data);
        $this->setRequestBodyProperty($_body, "billing_address", $billing_address);
        $this->setRequestBodyProperty($_body, "payment_method", $payment_method);
        $this->setRequestBodyProperty($_body, "redirect_urls", $redirect_urls);
        $this->setRequestBodyProperty($_body, "processing_data", $processing_data);
        $this->setRequestBodyProperty($_body, "events_endpoints", $events_endpoints);
        $installment_plan_create_request = $_body;

        list($response) = $this->post2WithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_create_request, $x_splitit_test_mode, $contentType);
        return $response;
    }

    /**
     * Operation post2WithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanCreateRequest $installment_plan_create_request (required)
     * @param  string $x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post2'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\InstallmentPlanCreateResponse|\Splitit\Model\PlanErrorResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function post2WithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_create_request, $x_splitit_test_mode = null, string $contentType = self::contentTypes['post2'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->post2Request($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_create_request, $x_splitit_test_mode, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->post2WithHttpInfo(
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $installment_plan_create_request,
                        $x_splitit_test_mode,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\InstallmentPlanCreateResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\InstallmentPlanCreateResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\InstallmentPlanCreateResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\Splitit\Model\PlanErrorResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\PlanErrorResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\PlanErrorResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\InstallmentPlanCreateResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\InstallmentPlanCreateResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\PlanErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation post2Async
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanCreateRequest $installment_plan_create_request (required)
     * @param  string $x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post2'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function post2Async(

        $auto_capture,
        $terms_and_conditions_accepted,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $attempt3d_secure = SENTINEL_VALUE,
        $shopper = SENTINEL_VALUE,
        $plan_data = SENTINEL_VALUE,
        $billing_address = SENTINEL_VALUE,
        $payment_method = SENTINEL_VALUE,
        $redirect_urls = SENTINEL_VALUE,
        $processing_data = SENTINEL_VALUE,
        $events_endpoints = SENTINEL_VALUE,
        $x_splitit_test_mode = SENTINEL_VALUE,

        string $contentType = self::contentTypes['post2'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "auto_capture", $auto_capture);
        $this->setRequestBodyProperty($_body, "attempt3d_secure", $attempt3d_secure);
        $this->setRequestBodyProperty($_body, "terms_and_conditions_accepted", $terms_and_conditions_accepted);
        $this->setRequestBodyProperty($_body, "shopper", $shopper);
        $this->setRequestBodyProperty($_body, "plan_data", $plan_data);
        $this->setRequestBodyProperty($_body, "billing_address", $billing_address);
        $this->setRequestBodyProperty($_body, "payment_method", $payment_method);
        $this->setRequestBodyProperty($_body, "redirect_urls", $redirect_urls);
        $this->setRequestBodyProperty($_body, "processing_data", $processing_data);
        $this->setRequestBodyProperty($_body, "events_endpoints", $events_endpoints);
        $installment_plan_create_request = $_body;

        return $this->post2AsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_create_request, $x_splitit_test_mode, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation post2AsyncWithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanCreateRequest $installment_plan_create_request (required)
     * @param  string $x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function post2AsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_create_request, $x_splitit_test_mode = null, string $contentType = self::contentTypes['post2'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\InstallmentPlanCreateResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->post2Request($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_create_request, $x_splitit_test_mode, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        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 'post2'
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanCreateRequest $installment_plan_create_request (required)
     * @param  string $x_splitit_test_mode (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['post2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function post2Request($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_create_request, $x_splitit_test_mode = SENTINEL_VALUE, string $contentType = self::contentTypes['post2'][0])
    {

        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling post2'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling post2'
            );
        }
        if ($installment_plan_create_request !== SENTINEL_VALUE) {
            if (!($installment_plan_create_request instanceof \Splitit\Model\InstallmentPlanCreateRequest)) {
                if (!is_array($installment_plan_create_request))
                    throw new \InvalidArgumentException('"installment_plan_create_request" must be associative array or an instance of \Splitit\Model\InstallmentPlanCreateRequest InstallmentPlanApi.post2.');
                else
                    $installment_plan_create_request = new \Splitit\Model\InstallmentPlanCreateRequest($installment_plan_create_request);
            }
        }
        // verify the required parameter 'installment_plan_create_request' is set
        if ($installment_plan_create_request === SENTINEL_VALUE || (is_array($installment_plan_create_request) && count($installment_plan_create_request) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter installment_plan_create_request when calling post2'
            );
        }
        // Check if $x_splitit_test_mode is a string
        if ($x_splitit_test_mode !== SENTINEL_VALUE && !is_string($x_splitit_test_mode)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_test_mode, true), gettype($x_splitit_test_mode)));
        }


        $resourcePath = '/api/installmentplans';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // header params
        if ($x_splitit_test_mode !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TestMode'] = ObjectSerializer::toHeaderValue($x_splitit_test_mode);
        }
        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }



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

        // for model (json/xml)
        if (isset($installment_plan_create_request)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($installment_plan_create_request));
            } else {
                $httpBody = $installment_plan_create_request;
            }
        } 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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'POST';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

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

    /**
     * Operation refund
     *
     * @param  string $installment_plan_number installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanRefundRequest $installment_plan_refund_request installment_plan_refund_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['refund'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\InstallmentPlanRefundResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function refund(

        $amount,
        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $refund_strategy = SENTINEL_VALUE,

        string $contentType = self::contentTypes['refund'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "amount", $amount);
        $this->setRequestBodyProperty($_body, "refund_strategy", $refund_strategy);
        $installment_plan_refund_request = $_body;

        list($response) = $this->refundWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_refund_request, $contentType);
        return $response;
    }

    /**
     * Operation refundWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanRefundRequest $installment_plan_refund_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['refund'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\InstallmentPlanRefundResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function refundWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_refund_request, string $contentType = self::contentTypes['refund'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->refundRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_refund_request, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->refundWithHttpInfo(
                        $installment_plan_number,
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $installment_plan_refund_request,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\InstallmentPlanRefundResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\InstallmentPlanRefundResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\InstallmentPlanRefundResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\InstallmentPlanRefundResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\InstallmentPlanRefundResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation refundAsync
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanRefundRequest $installment_plan_refund_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['refund'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function refundAsync(

        $amount,
        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $refund_strategy = SENTINEL_VALUE,

        string $contentType = self::contentTypes['refund'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "amount", $amount);
        $this->setRequestBodyProperty($_body, "refund_strategy", $refund_strategy);
        $installment_plan_refund_request = $_body;

        return $this->refundAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_refund_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation refundAsyncWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanRefundRequest $installment_plan_refund_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['refund'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function refundAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_refund_request, string $contentType = self::contentTypes['refund'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\InstallmentPlanRefundResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->refundRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_refund_request, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        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 'refund'
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanRefundRequest $installment_plan_refund_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['refund'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function refundRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_refund_request, string $contentType = self::contentTypes['refund'][0])
    {

        // Check if $installment_plan_number is a string
        if ($installment_plan_number !== SENTINEL_VALUE && !is_string($installment_plan_number)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($installment_plan_number, true), gettype($installment_plan_number)));
        }
        // verify the required parameter 'installment_plan_number' is set
        if ($installment_plan_number === SENTINEL_VALUE || (is_array($installment_plan_number) && count($installment_plan_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter installment_plan_number when calling refund'
            );
        }
        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling refund'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling refund'
            );
        }
        if ($installment_plan_refund_request !== SENTINEL_VALUE) {
            if (!($installment_plan_refund_request instanceof \Splitit\Model\InstallmentPlanRefundRequest)) {
                if (!is_array($installment_plan_refund_request))
                    throw new \InvalidArgumentException('"installment_plan_refund_request" must be associative array or an instance of \Splitit\Model\InstallmentPlanRefundRequest InstallmentPlanApi.refund.');
                else
                    $installment_plan_refund_request = new \Splitit\Model\InstallmentPlanRefundRequest($installment_plan_refund_request);
            }
        }
        // verify the required parameter 'installment_plan_refund_request' is set
        if ($installment_plan_refund_request === SENTINEL_VALUE || (is_array($installment_plan_refund_request) && count($installment_plan_refund_request) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter installment_plan_refund_request when calling refund'
            );
        }


        $resourcePath = '/api/installmentplans/{installmentPlanNumber}/refund';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }

        // path params
        if ($installment_plan_number !== SENTINEL_VALUE) {
            $resourcePath = str_replace(
                '{' . 'installmentPlanNumber' . '}',
                ObjectSerializer::toPathValue($installment_plan_number),
                $resourcePath
            );
        }


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

        // for model (json/xml)
        if (isset($installment_plan_refund_request)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($installment_plan_refund_request));
            } else {
                $httpBody = $installment_plan_refund_request;
            }
        } 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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'POST';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

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

    /**
     * Operation search
     *
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $installment_plan_number installment_plan_number (optional)
     * @param  string $ref_order_number ref_order_number (optional)
     * @param  array<string,string> $extended_params extended_params (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\InstallmentPlanSearchResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function search(
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $installment_plan_number = SENTINEL_VALUE,
        $ref_order_number = SENTINEL_VALUE,
        $extended_params = SENTINEL_VALUE,


        string $contentType = self::contentTypes['search'][0]

    )
    {

        list($response) = $this->searchWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_number, $ref_order_number, $extended_params, $contentType);
        return $response;
    }

    /**
     * Operation searchWithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $installment_plan_number (optional)
     * @param  string $ref_order_number (optional)
     * @param  array<string,string> $extended_params (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\InstallmentPlanSearchResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function searchWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_number = null, $ref_order_number = null, $extended_params = null, string $contentType = self::contentTypes['search'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->searchRequest($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_number, $ref_order_number, $extended_params, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->searchWithHttpInfo(
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $installment_plan_number,
                        $ref_order_number,
                        $extended_params,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\InstallmentPlanSearchResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\InstallmentPlanSearchResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\InstallmentPlanSearchResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\InstallmentPlanSearchResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\InstallmentPlanSearchResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation searchAsync
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $installment_plan_number (optional)
     * @param  string $ref_order_number (optional)
     * @param  array<string,string> $extended_params (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function searchAsync(
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $installment_plan_number = SENTINEL_VALUE,
        $ref_order_number = SENTINEL_VALUE,
        $extended_params = SENTINEL_VALUE,


        string $contentType = self::contentTypes['search'][0]

    )
    {

        return $this->searchAsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_number, $ref_order_number, $extended_params, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation searchAsyncWithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $installment_plan_number (optional)
     * @param  string $ref_order_number (optional)
     * @param  array<string,string> $extended_params (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function searchAsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_number = null, $ref_order_number = null, $extended_params = null, string $contentType = self::contentTypes['search'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\InstallmentPlanSearchResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->searchRequest($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_number, $ref_order_number, $extended_params, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config);

        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 'search'
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $installment_plan_number (optional)
     * @param  string $ref_order_number (optional)
     * @param  array<string,string> $extended_params (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['search'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function searchRequest($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_number = SENTINEL_VALUE, $ref_order_number = SENTINEL_VALUE, $extended_params = SENTINEL_VALUE, string $contentType = self::contentTypes['search'][0])
    {

        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling search'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling search'
            );
        }
        // Check if $installment_plan_number is a string
        if ($installment_plan_number !== SENTINEL_VALUE && !is_string($installment_plan_number)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($installment_plan_number, true), gettype($installment_plan_number)));
        }
        // Check if $ref_order_number is a string
        if ($ref_order_number !== SENTINEL_VALUE && !is_string($ref_order_number)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($ref_order_number, true), gettype($ref_order_number)));
        }


        $resourcePath = '/api/installmentplans/search';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        if ($installment_plan_number !== SENTINEL_VALUE) {
            // query params
            $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
                $installment_plan_number,
                'installmentPlanNumber', // param base name
                'string', // openApiType
                'form', // style
                true, // explode
                false // required
            ) ?? []);
        }
        if ($ref_order_number !== SENTINEL_VALUE) {
            // query params
            $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
                $ref_order_number,
                'refOrderNumber', // param base name
                'string', // openApiType
                'form', // style
                true, // explode
                false // required
            ) ?? []);
        }
        if ($extended_params !== SENTINEL_VALUE) {
            // query params
            $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
                $extended_params,
                'extendedParams', // param base name
                'object', // openApiType
                'form', // style
                true, // explode
                false // required
            ) ?? []);
        }

        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }



        $headers = $this->headerSelector->selectHeaders(
            ['text/plain', 'application/json', 'text/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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'GET';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

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

    /**
     * Operation updateOrder
     *
     * @param  string $installment_plan_number installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\UpdateOrderRequest $update_order_request update_order_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\InstallmentPlanUpdateResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function updateOrder(

        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $tracking_number = SENTINEL_VALUE,
        $ref_order_number = SENTINEL_VALUE,
        $shipping_status = SENTINEL_VALUE,
        $capture = SENTINEL_VALUE,

        string $contentType = self::contentTypes['updateOrder'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "tracking_number", $tracking_number);
        $this->setRequestBodyProperty($_body, "ref_order_number", $ref_order_number);
        $this->setRequestBodyProperty($_body, "shipping_status", $shipping_status);
        $this->setRequestBodyProperty($_body, "capture", $capture);
        $update_order_request = $_body;

        list($response) = $this->updateOrderWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $update_order_request, $contentType);
        return $response;
    }

    /**
     * Operation updateOrderWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\UpdateOrderRequest $update_order_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\InstallmentPlanUpdateResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateOrderWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $update_order_request, string $contentType = self::contentTypes['updateOrder'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->updateOrderRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $update_order_request, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->updateOrderWithHttpInfo(
                        $installment_plan_number,
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $update_order_request,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\InstallmentPlanUpdateResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\InstallmentPlanUpdateResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\InstallmentPlanUpdateResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\InstallmentPlanUpdateResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\InstallmentPlanUpdateResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation updateOrderAsync
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\UpdateOrderRequest $update_order_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateOrderAsync(

        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $tracking_number = SENTINEL_VALUE,
        $ref_order_number = SENTINEL_VALUE,
        $shipping_status = SENTINEL_VALUE,
        $capture = SENTINEL_VALUE,

        string $contentType = self::contentTypes['updateOrder'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "tracking_number", $tracking_number);
        $this->setRequestBodyProperty($_body, "ref_order_number", $ref_order_number);
        $this->setRequestBodyProperty($_body, "shipping_status", $shipping_status);
        $this->setRequestBodyProperty($_body, "capture", $capture);
        $update_order_request = $_body;

        return $this->updateOrderAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $update_order_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateOrderAsyncWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\UpdateOrderRequest $update_order_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateOrderAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $update_order_request, string $contentType = self::contentTypes['updateOrder'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\InstallmentPlanUpdateResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->updateOrderRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $update_order_request, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        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 'updateOrder'
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\UpdateOrderRequest $update_order_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updateOrderRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $update_order_request, string $contentType = self::contentTypes['updateOrder'][0])
    {

        // Check if $installment_plan_number is a string
        if ($installment_plan_number !== SENTINEL_VALUE && !is_string($installment_plan_number)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($installment_plan_number, true), gettype($installment_plan_number)));
        }
        // verify the required parameter 'installment_plan_number' is set
        if ($installment_plan_number === SENTINEL_VALUE || (is_array($installment_plan_number) && count($installment_plan_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter installment_plan_number when calling updateOrder'
            );
        }
        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling updateOrder'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling updateOrder'
            );
        }
        if ($update_order_request !== SENTINEL_VALUE) {
            if (!($update_order_request instanceof \Splitit\Model\UpdateOrderRequest)) {
                if (!is_array($update_order_request))
                    throw new \InvalidArgumentException('"update_order_request" must be associative array or an instance of \Splitit\Model\UpdateOrderRequest InstallmentPlanApi.updateOrder.');
                else
                    $update_order_request = new \Splitit\Model\UpdateOrderRequest($update_order_request);
            }
        }
        // verify the required parameter 'update_order_request' is set
        if ($update_order_request === SENTINEL_VALUE || (is_array($update_order_request) && count($update_order_request) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter update_order_request when calling updateOrder'
            );
        }


        $resourcePath = '/api/installmentplans/{installmentPlanNumber}/updateorder';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }

        // path params
        if ($installment_plan_number !== SENTINEL_VALUE) {
            $resourcePath = str_replace(
                '{' . 'installmentPlanNumber' . '}',
                ObjectSerializer::toPathValue($installment_plan_number),
                $resourcePath
            );
        }


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

        // for model (json/xml)
        if (isset($update_order_request)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($update_order_request));
            } else {
                $httpBody = $update_order_request;
            }
        } 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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'PUT';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

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

    /**
     * Operation updateOrder2
     *
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanUpdateRequestByIdentifier $installment_plan_update_request_by_identifier installment_plan_update_request_by_identifier (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder2'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\InstallmentPlanUpdateResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function updateOrder2(

        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $ref_order_number = SENTINEL_VALUE,
        $tracking_number = SENTINEL_VALUE,
        $capture = SENTINEL_VALUE,
        $shipping_status = SENTINEL_VALUE,
        $identifier = SENTINEL_VALUE,

        string $contentType = self::contentTypes['updateOrder2'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "ref_order_number", $ref_order_number);
        $this->setRequestBodyProperty($_body, "tracking_number", $tracking_number);
        $this->setRequestBodyProperty($_body, "capture", $capture);
        $this->setRequestBodyProperty($_body, "shipping_status", $shipping_status);
        $this->setRequestBodyProperty($_body, "identifier", $identifier);
        $installment_plan_update_request_by_identifier = $_body;

        list($response) = $this->updateOrder2WithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_update_request_by_identifier, $contentType);
        return $response;
    }

    /**
     * Operation updateOrder2WithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanUpdateRequestByIdentifier $installment_plan_update_request_by_identifier (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder2'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\InstallmentPlanUpdateResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateOrder2WithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_update_request_by_identifier, string $contentType = self::contentTypes['updateOrder2'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->updateOrder2Request($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_update_request_by_identifier, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->updateOrder2WithHttpInfo(
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $installment_plan_update_request_by_identifier,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\InstallmentPlanUpdateResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\InstallmentPlanUpdateResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\InstallmentPlanUpdateResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\InstallmentPlanUpdateResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\InstallmentPlanUpdateResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation updateOrder2Async
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanUpdateRequestByIdentifier $installment_plan_update_request_by_identifier (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder2'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateOrder2Async(

        $x_splitit_idempotency_key,
        $x_splitit_touch_point,
        $ref_order_number = SENTINEL_VALUE,
        $tracking_number = SENTINEL_VALUE,
        $capture = SENTINEL_VALUE,
        $shipping_status = SENTINEL_VALUE,
        $identifier = SENTINEL_VALUE,

        string $contentType = self::contentTypes['updateOrder2'][0]

    )
    {
        $_body = [];
        $this->setRequestBodyProperty($_body, "ref_order_number", $ref_order_number);
        $this->setRequestBodyProperty($_body, "tracking_number", $tracking_number);
        $this->setRequestBodyProperty($_body, "capture", $capture);
        $this->setRequestBodyProperty($_body, "shipping_status", $shipping_status);
        $this->setRequestBodyProperty($_body, "identifier", $identifier);
        $installment_plan_update_request_by_identifier = $_body;

        return $this->updateOrder2AsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_update_request_by_identifier, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateOrder2AsyncWithHttpInfo
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanUpdateRequestByIdentifier $installment_plan_update_request_by_identifier (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateOrder2AsyncWithHttpInfo($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_update_request_by_identifier, string $contentType = self::contentTypes['updateOrder2'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\InstallmentPlanUpdateResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->updateOrder2Request($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_update_request_by_identifier, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody);

        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 'updateOrder2'
     *
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  \Splitit\Model\InstallmentPlanUpdateRequestByIdentifier $installment_plan_update_request_by_identifier (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateOrder2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updateOrder2Request($x_splitit_idempotency_key, $x_splitit_touch_point, $installment_plan_update_request_by_identifier, string $contentType = self::contentTypes['updateOrder2'][0])
    {

        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling updateOrder2'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling updateOrder2'
            );
        }
        if ($installment_plan_update_request_by_identifier !== SENTINEL_VALUE) {
            if (!($installment_plan_update_request_by_identifier instanceof \Splitit\Model\InstallmentPlanUpdateRequestByIdentifier)) {
                if (!is_array($installment_plan_update_request_by_identifier))
                    throw new \InvalidArgumentException('"installment_plan_update_request_by_identifier" must be associative array or an instance of \Splitit\Model\InstallmentPlanUpdateRequestByIdentifier InstallmentPlanApi.updateOrder2.');
                else
                    $installment_plan_update_request_by_identifier = new \Splitit\Model\InstallmentPlanUpdateRequestByIdentifier($installment_plan_update_request_by_identifier);
            }
        }
        // verify the required parameter 'installment_plan_update_request_by_identifier' is set
        if ($installment_plan_update_request_by_identifier === SENTINEL_VALUE || (is_array($installment_plan_update_request_by_identifier) && count($installment_plan_update_request_by_identifier) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter installment_plan_update_request_by_identifier when calling updateOrder2'
            );
        }


        $resourcePath = '/api/installmentplans/updateorder';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }



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

        // for model (json/xml)
        if (isset($installment_plan_update_request_by_identifier)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($installment_plan_update_request_by_identifier));
            } else {
                $httpBody = $installment_plan_update_request_by_identifier;
            }
        } 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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'PUT';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

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

    /**
     * Operation verifyAuthorization
     *
     * @param  string $installment_plan_number installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['verifyAuthorization'] to see the possible values for this operation
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \Splitit\Model\VerifyAuthorizationResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse
     */
    public function verifyAuthorization(
        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,


        string $contentType = self::contentTypes['verifyAuthorization'][0]

    )
    {

        list($response) = $this->verifyAuthorizationWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType);
        return $response;
    }

    /**
     * Operation verifyAuthorizationWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['verifyAuthorization'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \Splitit\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \Splitit\Model\VerifyAuthorizationResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse|\Splitit\Model\FailedResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function verifyAuthorizationWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, string $contentType = self::contentTypes['verifyAuthorization'][0], \Splitit\RequestOptions $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        ["request" => $request, "serializedBody" => $serializedBody] = $this->verifyAuthorizationRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                if (
                    ($e->getCode() == 401 || $e->getCode() == 403) &&
                    !empty($this->getConfig()->getAccessToken()) &&
                    $requestOptions->shouldRetryOAuth()
                ) {
                    return $this->verifyAuthorizationWithHttpInfo(
                        $installment_plan_number,
                        $x_splitit_idempotency_key,
                        $x_splitit_touch_point,
                        $contentType,
                        $requestOptions->setRetryOAuth(false)
                    );
                }

                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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\Splitit\Model\VerifyAuthorizationResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\VerifyAuthorizationResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\VerifyAuthorizationResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 403:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\Splitit\Model\FailedResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\Splitit\Model\FailedResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\Splitit\Model\FailedResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\Splitit\Model\VerifyAuthorizationResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\VerifyAuthorizationResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Splitit\Model\FailedResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation verifyAuthorizationAsync
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['verifyAuthorization'] to see the possible values for this operation
     * @param  \Splitit\RequestOptions $requestOptions
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function verifyAuthorizationAsync(
        $installment_plan_number,
        $x_splitit_idempotency_key,
        $x_splitit_touch_point,


        string $contentType = self::contentTypes['verifyAuthorization'][0]

    )
    {

        return $this->verifyAuthorizationAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation verifyAuthorizationAsyncWithHttpInfo
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['verifyAuthorization'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function verifyAuthorizationAsyncWithHttpInfo($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, string $contentType = self::contentTypes['verifyAuthorization'][0], $requestOptions = null)
    {
        if ($requestOptions == null) $requestOptions = new \Splitit\RequestOptions();
        $returnType = '\Splitit\Model\VerifyAuthorizationResponse';
        ["request" => $request, "serializedBody" => $serializedBody] = $this->verifyAuthorizationRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, $contentType);

        // Customization hook
        $this->beforeSendHook($request, $requestOptions, $this->config);

        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 'verifyAuthorization'
     *
     * @param  string $installment_plan_number (required)
     * @param  string $x_splitit_idempotency_key (required)
     * @param  string $x_splitit_touch_point TouchPoint (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['verifyAuthorization'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function verifyAuthorizationRequest($installment_plan_number, $x_splitit_idempotency_key, $x_splitit_touch_point, string $contentType = self::contentTypes['verifyAuthorization'][0])
    {

        // Check if $installment_plan_number is a string
        if ($installment_plan_number !== SENTINEL_VALUE && !is_string($installment_plan_number)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($installment_plan_number, true), gettype($installment_plan_number)));
        }
        // verify the required parameter 'installment_plan_number' is set
        if ($installment_plan_number === SENTINEL_VALUE || (is_array($installment_plan_number) && count($installment_plan_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter installment_plan_number when calling verifyAuthorization'
            );
        }
        // Check if $x_splitit_idempotency_key is a string
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE && !is_string($x_splitit_idempotency_key)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_idempotency_key, true), gettype($x_splitit_idempotency_key)));
        }
        // verify the required parameter 'x_splitit_idempotency_key' is set
        if ($x_splitit_idempotency_key === SENTINEL_VALUE || (is_array($x_splitit_idempotency_key) && count($x_splitit_idempotency_key) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_idempotency_key when calling verifyAuthorization'
            );
        }
        // Check if $x_splitit_touch_point is a string
        if ($x_splitit_touch_point !== SENTINEL_VALUE && !is_string($x_splitit_touch_point)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($x_splitit_touch_point, true), gettype($x_splitit_touch_point)));
        }
        // verify the required parameter 'x_splitit_touch_point' is set
        if ($x_splitit_touch_point === SENTINEL_VALUE || (is_array($x_splitit_touch_point) && count($x_splitit_touch_point) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter x_splitit_touch_point when calling verifyAuthorization'
            );
        }


        $resourcePath = '/api/installmentplans/{installmentPlanNumber}/verifyauthorization';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // header params
        if ($x_splitit_idempotency_key !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-IdempotencyKey'] = ObjectSerializer::toHeaderValue($x_splitit_idempotency_key);
        }
        // header params
        if ($x_splitit_touch_point !== SENTINEL_VALUE) {
            $headerParams['X-Splitit-TouchPoint'] = ObjectSerializer::toHeaderValue($x_splitit_touch_point);
        }

        // path params
        if ($installment_plan_number !== SENTINEL_VALUE) {
            $resourcePath = str_replace(
                '{' . 'installmentPlanNumber' . '}',
                ObjectSerializer::toPathValue($installment_plan_number),
                $resourcePath
            );
        }


        $headers = $this->headerSelector->selectHeaders(
            ['text/plain', 'application/json', 'text/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\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        $this->config->refreshOAuthAccessToken();
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

        $method = 'GET';
        $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody);

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return [
            "request" => new Request(
                $method,
                $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
                $headers,
                $httpBody
            ),
            "serializedBody" => $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());
            }
        }

        return $options;
    }
}
