<?php
/**
 * ResourcesApi
 * PHP version 5
 *
 * @category Class
 * @package  USPS\Labels
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */

/**
 * Labels
 *
 * Contact Us: [USPS API Support](https://emailus.usps.com/s/usps-APIs) | [Terms of Service](https://about.usps.com/termsofuse.htm)  The USPS&#174; Labels API allows you to digitally create mailing labels for the following mail classes: USPS Ground Advantage&#8482;, Parcel Select&#174; Destination Entry, Parcel Select Lightweight&#174;, USPS Connect&#174; Local, USPS Connect&#174; Regional, Priority  Mail&#174;, Priority Mail Express&#174;, Bound Printed Matter, Library Mail, and Media Mail&#174;.  * Use the [Getting Started guide](https://developers.usps.com/getting-started) to get started with the Labels API. * The USPS&#174; Labels API uses a token to authorize the use of an [Enterprise Payment](https://postalpro.usps.com/EPS) or Permit account. The specification to generate the token is in the [Payments 3.0 - Set Payment Account Information](https://developers.usps.com/paymentsv3#tag/Resources/operation/post-payments-payment-authorization).  **Manifest Scheduling**   The following table outlines the Domestic Label manifesting schedule for specific conditions listed below.   | Condition                   | Scheduling | | ----------------------------| -------- | | **Customs Forms labels**    | 12:30am CT on the day after label creation. | | **Return labels**    | 12:30am CT on the day after label creation. | | **Smart Locker labels**     | Electronic data is sent to Postal systems within 15 minutes of label creation. | | **Value of `true` provided for `immediateManifest` field**| Electronic data is sent to Postal systems within 15 minutes of label creation.  | | **Label is added to a [SCAN Form](https://developers.usps.com/scanv3#tag/Resources/operation/post-scan-form)**| Electronic data is sent to Postal systems within 15 minutes of SCAN Form creation.  | | **All other conditions**    | 12:30am CT after the `mailingDate` value provided by the user |
 *
 * OpenAPI spec version: 3.9.9
 * 
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 * Swagger Codegen version: 3.0.71
 */
/**
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */

namespace USPS\Labels\Api;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use USPS\Labels\ApiException;
use USPS\Labels\Configuration;
use USPS\Labels\HeaderSelector;
use USPS\Labels\ObjectSerializer;

/**
 * ResourcesApi Class Doc Comment
 *
 * @category Class
 * @package  USPS\Labels
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */
class ResourcesApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

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

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

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     */
    public function __construct(
        ClientInterface $client = null,
        Configuration $config = null,
        HeaderSelector $selector = null
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: new Configuration();
        $this->headerSelector = $selector ?: new HeaderSelector();
    }

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

    /**
     * Operation deleteIndiciaImb
     *
     * Cancel a previously requested Intelligent Mail Barcode (IMB) label for First-Class letters, flats, and cards.
     *
     * @param  string $imb The Intelligent Mail Barcode (IMB) for First-Class letters, flats, and cards. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\IMBCancelResponse
     */
    public function deleteIndiciaImb($imb, $x_payment_authorization_token)
    {
        list($response) = $this->deleteIndiciaImbWithHttpInfo($imb, $x_payment_authorization_token);
        return $response;
    }

    /**
     * Operation deleteIndiciaImbWithHttpInfo
     *
     * Cancel a previously requested Intelligent Mail Barcode (IMB) label for First-Class letters, flats, and cards.
     *
     * @param  string $imb The Intelligent Mail Barcode (IMB) for First-Class letters, flats, and cards. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\IMBCancelResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function deleteIndiciaImbWithHttpInfo($imb, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\IMBCancelResponse';
        $request = $this->deleteIndiciaImbRequest($imb, $x_payment_authorization_token);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\IMBCancelResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation deleteIndiciaImbAsync
     *
     * Cancel a previously requested Intelligent Mail Barcode (IMB) label for First-Class letters, flats, and cards.
     *
     * @param  string $imb The Intelligent Mail Barcode (IMB) for First-Class letters, flats, and cards. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteIndiciaImbAsync($imb, $x_payment_authorization_token)
    {
        return $this->deleteIndiciaImbAsyncWithHttpInfo($imb, $x_payment_authorization_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteIndiciaImbAsyncWithHttpInfo
     *
     * Cancel a previously requested Intelligent Mail Barcode (IMB) label for First-Class letters, flats, and cards.
     *
     * @param  string $imb The Intelligent Mail Barcode (IMB) for First-Class letters, flats, and cards. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteIndiciaImbAsyncWithHttpInfo($imb, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\IMBCancelResponse';
        $request = $this->deleteIndiciaImbRequest($imb, $x_payment_authorization_token);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'deleteIndiciaImb'
     *
     * @param  string $imb The Intelligent Mail Barcode (IMB) for First-Class letters, flats, and cards. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function deleteIndiciaImbRequest($imb, $x_payment_authorization_token)
    {
        // verify the required parameter 'imb' is set
        if ($imb === null || (is_array($imb) && count($imb) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $imb when calling deleteIndiciaImb'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling deleteIndiciaImb'
            );
        }

        $resourcePath = '/indicia/imb/{imb}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }

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

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json', 'application/xml'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'DELETE',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation deleteLabel
     *
     * Cancel a previously requested label or request a refund on label
     *
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\CancelResponse
     */
    public function deleteLabel($tracking_number, $x_payment_authorization_token)
    {
        list($response) = $this->deleteLabelWithHttpInfo($tracking_number, $x_payment_authorization_token);
        return $response;
    }

    /**
     * Operation deleteLabelWithHttpInfo
     *
     * Cancel a previously requested label or request a refund on label
     *
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\CancelResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function deleteLabelWithHttpInfo($tracking_number, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\CancelResponse';
        $request = $this->deleteLabelRequest($tracking_number, $x_payment_authorization_token);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\CancelResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation deleteLabelAsync
     *
     * Cancel a previously requested label or request a refund on label
     *
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteLabelAsync($tracking_number, $x_payment_authorization_token)
    {
        return $this->deleteLabelAsyncWithHttpInfo($tracking_number, $x_payment_authorization_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteLabelAsyncWithHttpInfo
     *
     * Cancel a previously requested label or request a refund on label
     *
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteLabelAsyncWithHttpInfo($tracking_number, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\CancelResponse';
        $request = $this->deleteLabelRequest($tracking_number, $x_payment_authorization_token);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'deleteLabel'
     *
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function deleteLabelRequest($tracking_number, $x_payment_authorization_token)
    {
        // verify the required parameter 'tracking_number' is set
        if ($tracking_number === null || (is_array($tracking_number) && count($tracking_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $tracking_number when calling deleteLabel'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling deleteLabel'
            );
        }

        $resourcePath = '/label/{trackingNumber}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }

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

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json', 'application/xml'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'DELETE',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation deleteLabelBranding
     *
     * Delete a previously uploaded label branding image by imageUUID.
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\LabelBrandingDeleteResponse
     */
    public function deleteLabelBranding($image_uuid, $x_payment_authorization_token)
    {
        list($response) = $this->deleteLabelBrandingWithHttpInfo($image_uuid, $x_payment_authorization_token);
        return $response;
    }

    /**
     * Operation deleteLabelBrandingWithHttpInfo
     *
     * Delete a previously uploaded label branding image by imageUUID.
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\LabelBrandingDeleteResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function deleteLabelBrandingWithHttpInfo($image_uuid, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingDeleteResponse';
        $request = $this->deleteLabelBrandingRequest($image_uuid, $x_payment_authorization_token);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\LabelBrandingDeleteResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation deleteLabelBrandingAsync
     *
     * Delete a previously uploaded label branding image by imageUUID.
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteLabelBrandingAsync($image_uuid, $x_payment_authorization_token)
    {
        return $this->deleteLabelBrandingAsyncWithHttpInfo($image_uuid, $x_payment_authorization_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteLabelBrandingAsyncWithHttpInfo
     *
     * Delete a previously uploaded label branding image by imageUUID.
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteLabelBrandingAsyncWithHttpInfo($image_uuid, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingDeleteResponse';
        $request = $this->deleteLabelBrandingRequest($image_uuid, $x_payment_authorization_token);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'deleteLabelBranding'
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function deleteLabelBrandingRequest($image_uuid, $x_payment_authorization_token)
    {
        // verify the required parameter 'image_uuid' is set
        if ($image_uuid === null || (is_array($image_uuid) && count($image_uuid) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $image_uuid when calling deleteLabelBranding'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling deleteLabelBranding'
            );
        }

        $resourcePath = '/branding/{imageUUID}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }

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

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json', 'application/xml'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'DELETE',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getListLabelBranding
     *
     * Retrieve a paginated list of label branding images associated with your customer reference ID (CRID). You can sort the response using a query parameter.
     *
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  int $limit The number of items to return. (optional, default to 10)
     * @param  int $offset The number of items to skip before returning the results. (optional, default to 0)
     * @param  string $order_by Sort results in ascending or descending order. (optional, default to desc)
     * @param  string $sort_by Sort by field, e.g., &#x60;imageName&#x60; or &#x60;createdDateTime&#x60;. (optional, default to createdDateTime)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\LabelBrandingGetListResponse
     */
    public function getListLabelBranding($x_payment_authorization_token, $limit = '10', $offset = '0', $order_by = 'desc', $sort_by = 'createdDateTime')
    {
        list($response) = $this->getListLabelBrandingWithHttpInfo($x_payment_authorization_token, $limit, $offset, $order_by, $sort_by);
        return $response;
    }

    /**
     * Operation getListLabelBrandingWithHttpInfo
     *
     * Retrieve a paginated list of label branding images associated with your customer reference ID (CRID). You can sort the response using a query parameter.
     *
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  int $limit The number of items to return. (optional, default to 10)
     * @param  int $offset The number of items to skip before returning the results. (optional, default to 0)
     * @param  string $order_by Sort results in ascending or descending order. (optional, default to desc)
     * @param  string $sort_by Sort by field, e.g., &#x60;imageName&#x60; or &#x60;createdDateTime&#x60;. (optional, default to createdDateTime)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\LabelBrandingGetListResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getListLabelBrandingWithHttpInfo($x_payment_authorization_token, $limit = '10', $offset = '0', $order_by = 'desc', $sort_by = 'createdDateTime')
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingGetListResponse';
        $request = $this->getListLabelBrandingRequest($x_payment_authorization_token, $limit, $offset, $order_by, $sort_by);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\LabelBrandingGetListResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getListLabelBrandingAsync
     *
     * Retrieve a paginated list of label branding images associated with your customer reference ID (CRID). You can sort the response using a query parameter.
     *
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  int $limit The number of items to return. (optional, default to 10)
     * @param  int $offset The number of items to skip before returning the results. (optional, default to 0)
     * @param  string $order_by Sort results in ascending or descending order. (optional, default to desc)
     * @param  string $sort_by Sort by field, e.g., &#x60;imageName&#x60; or &#x60;createdDateTime&#x60;. (optional, default to createdDateTime)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getListLabelBrandingAsync($x_payment_authorization_token, $limit = '10', $offset = '0', $order_by = 'desc', $sort_by = 'createdDateTime')
    {
        return $this->getListLabelBrandingAsyncWithHttpInfo($x_payment_authorization_token, $limit, $offset, $order_by, $sort_by)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getListLabelBrandingAsyncWithHttpInfo
     *
     * Retrieve a paginated list of label branding images associated with your customer reference ID (CRID). You can sort the response using a query parameter.
     *
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  int $limit The number of items to return. (optional, default to 10)
     * @param  int $offset The number of items to skip before returning the results. (optional, default to 0)
     * @param  string $order_by Sort results in ascending or descending order. (optional, default to desc)
     * @param  string $sort_by Sort by field, e.g., &#x60;imageName&#x60; or &#x60;createdDateTime&#x60;. (optional, default to createdDateTime)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getListLabelBrandingAsyncWithHttpInfo($x_payment_authorization_token, $limit = '10', $offset = '0', $order_by = 'desc', $sort_by = 'createdDateTime')
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingGetListResponse';
        $request = $this->getListLabelBrandingRequest($x_payment_authorization_token, $limit, $offset, $order_by, $sort_by);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getListLabelBranding'
     *
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  int $limit The number of items to return. (optional, default to 10)
     * @param  int $offset The number of items to skip before returning the results. (optional, default to 0)
     * @param  string $order_by Sort results in ascending or descending order. (optional, default to desc)
     * @param  string $sort_by Sort by field, e.g., &#x60;imageName&#x60; or &#x60;createdDateTime&#x60;. (optional, default to createdDateTime)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getListLabelBrandingRequest($x_payment_authorization_token, $limit = '10', $offset = '0', $order_by = 'desc', $sort_by = 'createdDateTime')
    {
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling getListLabelBranding'
            );
        }

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

        // query params
        if ($limit !== null) {
            $queryParams['limit'] = ObjectSerializer::toQueryValue($limit, null);
        }
        // query params
        if ($offset !== null) {
            $queryParams['offset'] = ObjectSerializer::toQueryValue($offset, null);
        }
        // query params
        if ($order_by !== null) {
            $queryParams['orderBy'] = ObjectSerializer::toQueryValue($order_by, null);
        }
        // query params
        if ($sort_by !== null) {
            $queryParams['sortBy'] = ObjectSerializer::toQueryValue($sort_by, null);
        }
        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }


        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json', 'application/xml'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getSingleLabelBranding
     *
     * Retrieve a label branding image associated with your customer reference ID (CRID).
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\LabelBrandingGetImageResponse
     */
    public function getSingleLabelBranding($image_uuid, $x_payment_authorization_token)
    {
        list($response) = $this->getSingleLabelBrandingWithHttpInfo($image_uuid, $x_payment_authorization_token);
        return $response;
    }

    /**
     * Operation getSingleLabelBrandingWithHttpInfo
     *
     * Retrieve a label branding image associated with your customer reference ID (CRID).
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\LabelBrandingGetImageResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getSingleLabelBrandingWithHttpInfo($image_uuid, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingGetImageResponse';
        $request = $this->getSingleLabelBrandingRequest($image_uuid, $x_payment_authorization_token);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\LabelBrandingGetImageResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getSingleLabelBrandingAsync
     *
     * Retrieve a label branding image associated with your customer reference ID (CRID).
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getSingleLabelBrandingAsync($image_uuid, $x_payment_authorization_token)
    {
        return $this->getSingleLabelBrandingAsyncWithHttpInfo($image_uuid, $x_payment_authorization_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getSingleLabelBrandingAsyncWithHttpInfo
     *
     * Retrieve a label branding image associated with your customer reference ID (CRID).
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getSingleLabelBrandingAsyncWithHttpInfo($image_uuid, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingGetImageResponse';
        $request = $this->getSingleLabelBrandingRequest($image_uuid, $x_payment_authorization_token);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getSingleLabelBranding'
     *
     * @param  string $image_uuid The UUID of a label branding image (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getSingleLabelBrandingRequest($image_uuid, $x_payment_authorization_token)
    {
        // verify the required parameter 'image_uuid' is set
        if ($image_uuid === null || (is_array($image_uuid) && count($image_uuid) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $image_uuid when calling getSingleLabelBranding'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling getSingleLabelBranding'
            );
        }

        $resourcePath = '/branding/{imageUUID}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }

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

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json', 'application/xml'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation patchLabelBranding
     *
     * Rename the previously uploaded Label Branding Image by imageUUID.
     *
     * @param  \USPS\Labels\Model\BrandingPatchRequestInner[] $body body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $image_uuid The UUID of a label branding image (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\LabelBrandingPatchResponse
     */
    public function patchLabelBranding($body, $x_payment_authorization_token, $image_uuid)
    {
        list($response) = $this->patchLabelBrandingWithHttpInfo($body, $x_payment_authorization_token, $image_uuid);
        return $response;
    }

    /**
     * Operation patchLabelBrandingWithHttpInfo
     *
     * Rename the previously uploaded Label Branding Image by imageUUID.
     *
     * @param  \USPS\Labels\Model\BrandingPatchRequestInner[] $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $image_uuid The UUID of a label branding image (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\LabelBrandingPatchResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function patchLabelBrandingWithHttpInfo($body, $x_payment_authorization_token, $image_uuid)
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingPatchResponse';
        $request = $this->patchLabelBrandingRequest($body, $x_payment_authorization_token, $image_uuid);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\LabelBrandingPatchResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation patchLabelBrandingAsync
     *
     * Rename the previously uploaded Label Branding Image by imageUUID.
     *
     * @param  \USPS\Labels\Model\BrandingPatchRequestInner[] $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $image_uuid The UUID of a label branding image (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function patchLabelBrandingAsync($body, $x_payment_authorization_token, $image_uuid)
    {
        return $this->patchLabelBrandingAsyncWithHttpInfo($body, $x_payment_authorization_token, $image_uuid)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation patchLabelBrandingAsyncWithHttpInfo
     *
     * Rename the previously uploaded Label Branding Image by imageUUID.
     *
     * @param  \USPS\Labels\Model\BrandingPatchRequestInner[] $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $image_uuid The UUID of a label branding image (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function patchLabelBrandingAsyncWithHttpInfo($body, $x_payment_authorization_token, $image_uuid)
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingPatchResponse';
        $request = $this->patchLabelBrandingRequest($body, $x_payment_authorization_token, $image_uuid);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'patchLabelBranding'
     *
     * @param  \USPS\Labels\Model\BrandingPatchRequestInner[] $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $image_uuid The UUID of a label branding image (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function patchLabelBrandingRequest($body, $x_payment_authorization_token, $image_uuid)
    {
        // verify the required parameter 'body' is set
        if ($body === null || (is_array($body) && count($body) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling patchLabelBranding'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling patchLabelBranding'
            );
        }
        // verify the required parameter 'image_uuid' is set
        if ($image_uuid === null || (is_array($image_uuid) && count($image_uuid) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $image_uuid when calling patchLabelBranding'
            );
        }

        $resourcePath = '/branding/{imageUUID}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }

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

        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json', 'application/xml'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'PATCH',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation patchLabelEdit
     *
     * Edit label attributes.
     *
     * @param  \USPS\Labels\Model\PatchRequestInner[] $body body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\LabelMetadata
     */
    public function patchLabelEdit($body, $x_payment_authorization_token, $tracking_number)
    {
        list($response) = $this->patchLabelEditWithHttpInfo($body, $x_payment_authorization_token, $tracking_number);
        return $response;
    }

    /**
     * Operation patchLabelEditWithHttpInfo
     *
     * Edit label attributes.
     *
     * @param  \USPS\Labels\Model\PatchRequestInner[] $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\LabelMetadata, HTTP status code, HTTP response headers (array of strings)
     */
    public function patchLabelEditWithHttpInfo($body, $x_payment_authorization_token, $tracking_number)
    {
        $returnType = '\USPS\Labels\Model\LabelMetadata';
        $request = $this->patchLabelEditRequest($body, $x_payment_authorization_token, $tracking_number);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\LabelMetadata',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation patchLabelEditAsync
     *
     * Edit label attributes.
     *
     * @param  \USPS\Labels\Model\PatchRequestInner[] $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function patchLabelEditAsync($body, $x_payment_authorization_token, $tracking_number)
    {
        return $this->patchLabelEditAsyncWithHttpInfo($body, $x_payment_authorization_token, $tracking_number)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation patchLabelEditAsyncWithHttpInfo
     *
     * Edit label attributes.
     *
     * @param  \USPS\Labels\Model\PatchRequestInner[] $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function patchLabelEditAsyncWithHttpInfo($body, $x_payment_authorization_token, $tracking_number)
    {
        $returnType = '\USPS\Labels\Model\LabelMetadata';
        $request = $this->patchLabelEditRequest($body, $x_payment_authorization_token, $tracking_number);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'patchLabelEdit'
     *
     * @param  \USPS\Labels\Model\PatchRequestInner[] $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function patchLabelEditRequest($body, $x_payment_authorization_token, $tracking_number)
    {
        // verify the required parameter 'body' is set
        if ($body === null || (is_array($body) && count($body) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling patchLabelEdit'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling patchLabelEdit'
            );
        }
        // verify the required parameter 'tracking_number' is set
        if ($tracking_number === null || (is_array($tracking_number) && count($tracking_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $tracking_number when calling patchLabelEdit'
            );
        }

        $resourcePath = '/label/{trackingNumber}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }

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

        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json', 'application/xml'],
                ['application/json', 'application/xml']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'PATCH',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation postIndiciaImb
     *
     * Create an Intelligent Mail Barcode (IMB) label for First-Class letters, flats, and cards.
     *
     * @param  \USPS\Labels\Model\IndiciaImbRequest $body body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\IndiciaImbResponse
     */
    public function postIndiciaImb($body, $x_payment_authorization_token)
    {
        list($response) = $this->postIndiciaImbWithHttpInfo($body, $x_payment_authorization_token);
        return $response;
    }

    /**
     * Operation postIndiciaImbWithHttpInfo
     *
     * Create an Intelligent Mail Barcode (IMB) label for First-Class letters, flats, and cards.
     *
     * @param  \USPS\Labels\Model\IndiciaImbRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\IndiciaImbResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postIndiciaImbWithHttpInfo($body, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\IndiciaImbResponse';
        $request = $this->postIndiciaImbRequest($body, $x_payment_authorization_token);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

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

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\IndiciaImbResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation postIndiciaImbAsync
     *
     * Create an Intelligent Mail Barcode (IMB) label for First-Class letters, flats, and cards.
     *
     * @param  \USPS\Labels\Model\IndiciaImbRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postIndiciaImbAsync($body, $x_payment_authorization_token)
    {
        return $this->postIndiciaImbAsyncWithHttpInfo($body, $x_payment_authorization_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postIndiciaImbAsyncWithHttpInfo
     *
     * Create an Intelligent Mail Barcode (IMB) label for First-Class letters, flats, and cards.
     *
     * @param  \USPS\Labels\Model\IndiciaImbRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postIndiciaImbAsyncWithHttpInfo($body, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\IndiciaImbResponse';
        $request = $this->postIndiciaImbRequest($body, $x_payment_authorization_token);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'postIndiciaImb'
     *
     * @param  \USPS\Labels\Model\IndiciaImbRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function postIndiciaImbRequest($body, $x_payment_authorization_token)
    {
        // verify the required parameter 'body' is set
        if ($body === null || (is_array($body) && count($body) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling postIndiciaImb'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling postIndiciaImb'
            );
        }

        $resourcePath = '/indicia/imb';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }


        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['multipart/form-data', 'application/json', 'application/xml', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['multipart/form-data', 'application/json', 'application/xml', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml'],
                ['application/json', 'application/xml']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation postLabel
     *
     * Create a domestic shipping label.
     *
     * @param  \USPS\Labels\Model\LabelRequest $body body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\LabelMultiPartResponse
     */
    public function postLabel($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        list($response) = $this->postLabelWithHttpInfo($body, $x_payment_authorization_token, $x_idempotency_key);
        return $response;
    }

    /**
     * Operation postLabelWithHttpInfo
     *
     * Create a domestic shipping label.
     *
     * @param  \USPS\Labels\Model\LabelRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\LabelMultiPartResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postLabelWithHttpInfo($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        $returnType = '\USPS\Labels\Model\LabelMultiPartResponse';
        $request = $this->postLabelRequest($body, $x_payment_authorization_token, $x_idempotency_key);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\LabelMultiPartResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation postLabelAsync
     *
     * Create a domestic shipping label.
     *
     * @param  \USPS\Labels\Model\LabelRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postLabelAsync($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        return $this->postLabelAsyncWithHttpInfo($body, $x_payment_authorization_token, $x_idempotency_key)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postLabelAsyncWithHttpInfo
     *
     * Create a domestic shipping label.
     *
     * @param  \USPS\Labels\Model\LabelRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postLabelAsyncWithHttpInfo($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        $returnType = '\USPS\Labels\Model\LabelMultiPartResponse';
        $request = $this->postLabelRequest($body, $x_payment_authorization_token, $x_idempotency_key);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'postLabel'
     *
     * @param  \USPS\Labels\Model\LabelRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function postLabelRequest($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        // verify the required parameter 'body' is set
        if ($body === null || (is_array($body) && count($body) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling postLabel'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling postLabel'
            );
        }

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

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }
        // header params
        if ($x_idempotency_key !== null) {
            $headerParams['X-Idempotency-Key'] = ObjectSerializer::toHeaderValue($x_idempotency_key);
        }


        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['multipart/form-data', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml', 'application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['multipart/form-data', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml', 'application/json', 'application/xml'],
                ['application/json', 'application/xml']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation postLabelBranding
     *
     * Upload an SVG image to be used as a label branding image.
     *
     * @param  \USPS\Labels\Model\LabelBrandingUploadRequest $body body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\LabelBrandingUploadResponse
     */
    public function postLabelBranding($body, $x_payment_authorization_token)
    {
        list($response) = $this->postLabelBrandingWithHttpInfo($body, $x_payment_authorization_token);
        return $response;
    }

    /**
     * Operation postLabelBrandingWithHttpInfo
     *
     * Upload an SVG image to be used as a label branding image.
     *
     * @param  \USPS\Labels\Model\LabelBrandingUploadRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\LabelBrandingUploadResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postLabelBrandingWithHttpInfo($body, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingUploadResponse';
        $request = $this->postLabelBrandingRequest($body, $x_payment_authorization_token);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

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

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\LabelBrandingUploadResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation postLabelBrandingAsync
     *
     * Upload an SVG image to be used as a label branding image.
     *
     * @param  \USPS\Labels\Model\LabelBrandingUploadRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postLabelBrandingAsync($body, $x_payment_authorization_token)
    {
        return $this->postLabelBrandingAsyncWithHttpInfo($body, $x_payment_authorization_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postLabelBrandingAsyncWithHttpInfo
     *
     * Upload an SVG image to be used as a label branding image.
     *
     * @param  \USPS\Labels\Model\LabelBrandingUploadRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postLabelBrandingAsyncWithHttpInfo($body, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\LabelBrandingUploadResponse';
        $request = $this->postLabelBrandingRequest($body, $x_payment_authorization_token);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'postLabelBranding'
     *
     * @param  \USPS\Labels\Model\LabelBrandingUploadRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function postLabelBrandingRequest($body, $x_payment_authorization_token)
    {
        // verify the required parameter 'body' is set
        if ($body === null || (is_array($body) && count($body) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling postLabelBranding'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling postLabelBranding'
            );
        }

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

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }


        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json', 'application/xml'],
                ['application/json', 'application/xml']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation postLabelIndicia
     *
     * Create a First-Class letter, flat, or card indicia.
     *
     * @param  map[string,object] $body Indicia request payload containing necessary data for generating a First-Class indicia. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\IndiciaResponse
     */
    public function postLabelIndicia($body, $x_payment_authorization_token)
    {
        list($response) = $this->postLabelIndiciaWithHttpInfo($body, $x_payment_authorization_token);
        return $response;
    }

    /**
     * Operation postLabelIndiciaWithHttpInfo
     *
     * Create a First-Class letter, flat, or card indicia.
     *
     * @param  map[string,object] $body Indicia request payload containing necessary data for generating a First-Class indicia. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\IndiciaResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postLabelIndiciaWithHttpInfo($body, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\IndiciaResponse';
        $request = $this->postLabelIndiciaRequest($body, $x_payment_authorization_token);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

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

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\IndiciaResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation postLabelIndiciaAsync
     *
     * Create a First-Class letter, flat, or card indicia.
     *
     * @param  map[string,object] $body Indicia request payload containing necessary data for generating a First-Class indicia. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postLabelIndiciaAsync($body, $x_payment_authorization_token)
    {
        return $this->postLabelIndiciaAsyncWithHttpInfo($body, $x_payment_authorization_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postLabelIndiciaAsyncWithHttpInfo
     *
     * Create a First-Class letter, flat, or card indicia.
     *
     * @param  map[string,object] $body Indicia request payload containing necessary data for generating a First-Class indicia. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postLabelIndiciaAsyncWithHttpInfo($body, $x_payment_authorization_token)
    {
        $returnType = '\USPS\Labels\Model\IndiciaResponse';
        $request = $this->postLabelIndiciaRequest($body, $x_payment_authorization_token);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'postLabelIndicia'
     *
     * @param  map[string,object] $body Indicia request payload containing necessary data for generating a First-Class indicia. (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function postLabelIndiciaRequest($body, $x_payment_authorization_token)
    {
        // verify the required parameter 'body' is set
        if ($body === null || (is_array($body) && count($body) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling postLabelIndicia'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling postLabelIndicia'
            );
        }

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

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }


        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['multipart/form-data', 'application/json', 'application/xml', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['multipart/form-data', 'application/json', 'application/xml', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml'],
                ['application/json', 'application/xml']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation postLabelReprint
     *
     * Reprint a domestic shipping label.
     *
     * @param  \USPS\Labels\Model\LabelReprintRequest $body body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\LabelReprintMultiPartResponse
     */
    public function postLabelReprint($body, $x_payment_authorization_token, $tracking_number)
    {
        list($response) = $this->postLabelReprintWithHttpInfo($body, $x_payment_authorization_token, $tracking_number);
        return $response;
    }

    /**
     * Operation postLabelReprintWithHttpInfo
     *
     * Reprint a domestic shipping label.
     *
     * @param  \USPS\Labels\Model\LabelReprintRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\LabelReprintMultiPartResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postLabelReprintWithHttpInfo($body, $x_payment_authorization_token, $tracking_number)
    {
        $returnType = '\USPS\Labels\Model\LabelReprintMultiPartResponse';
        $request = $this->postLabelReprintRequest($body, $x_payment_authorization_token, $tracking_number);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\LabelReprintMultiPartResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation postLabelReprintAsync
     *
     * Reprint a domestic shipping label.
     *
     * @param  \USPS\Labels\Model\LabelReprintRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postLabelReprintAsync($body, $x_payment_authorization_token, $tracking_number)
    {
        return $this->postLabelReprintAsyncWithHttpInfo($body, $x_payment_authorization_token, $tracking_number)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postLabelReprintAsyncWithHttpInfo
     *
     * Reprint a domestic shipping label.
     *
     * @param  \USPS\Labels\Model\LabelReprintRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postLabelReprintAsyncWithHttpInfo($body, $x_payment_authorization_token, $tracking_number)
    {
        $returnType = '\USPS\Labels\Model\LabelReprintMultiPartResponse';
        $request = $this->postLabelReprintRequest($body, $x_payment_authorization_token, $tracking_number);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'postLabelReprint'
     *
     * @param  \USPS\Labels\Model\LabelReprintRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $tracking_number The tracking number of the domestic label. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function postLabelReprintRequest($body, $x_payment_authorization_token, $tracking_number)
    {
        // verify the required parameter 'body' is set
        if ($body === null || (is_array($body) && count($body) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling postLabelReprint'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling postLabelReprint'
            );
        }
        // verify the required parameter 'tracking_number' is set
        if ($tracking_number === null || (is_array($tracking_number) && count($tracking_number) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $tracking_number when calling postLabelReprint'
            );
        }

        $resourcePath = '/label-reprint/{trackingNumber}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }

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

        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['multipart/form-data', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml', 'application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['multipart/form-data', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml', 'application/json', 'application/xml'],
                ['application/json', 'application/xml']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation postReturnLabel
     *
     * Create a domestic returns shipping label.
     *
     * @param  \USPS\Labels\Model\ReturnLabelRequest $body body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \USPS\Labels\Model\ReturnLabelMultiPartResponse
     */
    public function postReturnLabel($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        list($response) = $this->postReturnLabelWithHttpInfo($body, $x_payment_authorization_token, $x_idempotency_key);
        return $response;
    }

    /**
     * Operation postReturnLabelWithHttpInfo
     *
     * Create a domestic returns shipping label.
     *
     * @param  \USPS\Labels\Model\ReturnLabelRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \USPS\Labels\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \USPS\Labels\Model\ReturnLabelMultiPartResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postReturnLabelWithHttpInfo($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        $returnType = '\USPS\Labels\Model\ReturnLabelMultiPartResponse';
        $request = $this->postReturnLabelRequest($body, $x_payment_authorization_token, $x_idempotency_key);

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

            $statusCode = $response->getStatusCode();

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

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $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(),
                        '\USPS\Labels\Model\ReturnLabelMultiPartResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 503:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\USPS\Labels\Model\ErrorMessage',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation postReturnLabelAsync
     *
     * Create a domestic returns shipping label.
     *
     * @param  \USPS\Labels\Model\ReturnLabelRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postReturnLabelAsync($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        return $this->postReturnLabelAsyncWithHttpInfo($body, $x_payment_authorization_token, $x_idempotency_key)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postReturnLabelAsyncWithHttpInfo
     *
     * Create a domestic returns shipping label.
     *
     * @param  \USPS\Labels\Model\ReturnLabelRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postReturnLabelAsyncWithHttpInfo($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        $returnType = '\USPS\Labels\Model\ReturnLabelMultiPartResponse';
        $request = $this->postReturnLabelRequest($body, $x_payment_authorization_token, $x_idempotency_key);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        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(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'postReturnLabel'
     *
     * @param  \USPS\Labels\Model\ReturnLabelRequest $body (required)
     * @param  string $x_payment_authorization_token Payment Authorization Token from the payments API Call. (required)
     * @param  string $x_idempotency_key A unique UUID that serves as an idempotency key for safe request retries and duplicate charge prevention during label creation. This value must be a randomly generated UUID and unique per customer (CRID) across all label creation requests. When the same idempotency key is resubmitted with an identical request payload, the API will return the existing label without creating a duplicate or charging additional postage. The UUID will be included in the electronic manifest data (Shipping Services File D5 field) sent to Postal systems. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function postReturnLabelRequest($body, $x_payment_authorization_token, $x_idempotency_key = null)
    {
        // verify the required parameter 'body' is set
        if ($body === null || (is_array($body) && count($body) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling postReturnLabel'
            );
        }
        // verify the required parameter 'x_payment_authorization_token' is set
        if ($x_payment_authorization_token === null || (is_array($x_payment_authorization_token) && count($x_payment_authorization_token) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $x_payment_authorization_token when calling postReturnLabel'
            );
        }

        $resourcePath = '/return-label';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($x_payment_authorization_token !== null) {
            $headerParams['X-Payment-Authorization-Token'] = ObjectSerializer::toHeaderValue($x_payment_authorization_token);
        }
        // header params
        if ($x_idempotency_key !== null) {
            $headerParams['X-Idempotency-Key'] = ObjectSerializer::toHeaderValue($x_idempotency_key);
        }


        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['multipart/form-data', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml', 'application/json', 'application/xml']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['multipart/form-data', 'application/vnd.usps.labels+json', 'application/vnd.usps.labels+xml', 'application/json', 'application/xml'],
                ['application/json', 'application/xml']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

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

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

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

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

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

        return $options;
    }
}
