diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 000000000..aab32754f --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":[],"times":{"SellingPartnerApi\\Tests\\AuthenticationTest::testItUsesInjectedAuthorizationSigner":0.009,"SellingPartnerApi\\Tests\\AuthenticationTest::testItUsesDefaultAuthorizationSigner":0.002,"SellingPartnerApi\\Tests\\AuthorizationSignerTest::testItSingsRequests":0,"SellingPartnerApi\\Tests\\RequestSignerTest::testItUsesInjectedRequestSigner":0.001,"SellingPartnerApi\\Tests\\RequestSignerTest::testItUsesDefaultRequestSigner":0,"SellingPartnerApi\\Tests\\RequestSignerTest::testItSingsRequestsWithDefaultRequestSigner":0}} \ No newline at end of file diff --git a/composer.json b/composer.json index d43ee55b4..bb5b0d9ad 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "jlevers/selling-partner-api", + "version": "5.10.3", "description": "PHP client for Amazon's Selling Partner API", "keywords": [ "api", @@ -20,54 +21,25 @@ } ], "require": { - "php": ">=8.2", + "php": ">=7.3", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", "guzzlehttp/guzzle": "^6.0|^7.0", - "saloonphp/saloon": "^3.4", - "openspout/openspout": "^4.23", - "illuminate/support": "^11.5" + "phpoffice/phpspreadsheet": "1.25.2" }, "require-dev": { - "composer/semver": "^3.4", - "highsidelabs/saloon-sdk-generator": "^2.1.0", - "symfony/console": "^7.0", - "psy/psysh": "^0.12.0", - "voku/simple_html_dom": "^4.8", - "laravel/pint": "^1.13", - "phpcompatibility/php-compatibility": "dev-develop", - "phpunit/phpunit": "^11.2", - "fakerphp/faker": "^1.23" + "phpunit/phpunit": "^8.0 || ^9.0", + "friendsofphp/php-cs-fixer": "^3.4" }, - "prefer-stable": true, "autoload": { - "psr-4": { - "SellingPartnerApi\\": "src/" - }, - "files": [ - "src/Generator/constants.php" - ] + "psr-4": { "SellingPartnerApi\\" : "lib/" } }, "autoload-dev": { - "psr-4": { - "SellingPartnerApi\\Tests\\": "tests/" - } + "psr-4": { "SellingPartnerApi\\Tests\\" : "test/" } }, "scripts": { - "lint": [ - "@pint", - "@php-compatibility-check" - ], - "pint": "php vendor/bin/pint", - "php-compatibility-check": "./vendor/bin/phpcs -p ./src ./bin --standard=PHPCompatibility --runtime-set testVersion 8.2-", - "post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility", - "post-update-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility", - "test": "vendor/bin/phpunit" - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } + "test": "vendor/bin/phpunit", + "lint": "vendor/bin/php-cs-fixer fix" } } diff --git a/lib/Api/BaseApi.php b/lib/Api/BaseApi.php new file mode 100644 index 000000000..3dfd03089 --- /dev/null +++ b/lib/Api/BaseApi.php @@ -0,0 +1,106 @@ +config = $config; + $this->client = $client ?: new Client(); + $this->headerSelector = $selector ?: new HeaderSelector($this->config); + } + + /** + * @return SellingPartnerApi\Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * @param SellingPartnerApi\Configuration $config + * @return $this + */ + public function setConfig(Configuration $config) + { + $this->config = $config; + $this->headerSelector = new HeaderSelector($config); + return $this; + } + + /** + * 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; + } + + /** + * Writes to the debug log file + * + * @param any $data + * @return void + */ + protected function writeDebug($data) + { + if ($this->config->getDebug()) { + if ($data instanceof Throwable) { + $data = "$data"; + } else if ($data instanceof GuzzleHttp\Psr7\Request) { + $data = "{$data->getMethod()} {$data->getUri()}\n" . implode("\n", $data->getHeaders()); + } else if ($data instanceof GuzzleHttp\Psr7\Response) { + $data = "{$data->getStatusCode()} {$data->getReasonPhrase()}\n" . implode("\n", $data->getHeaders()); + } else { + $data = print_r($data, true); + } + file_put_contents( + $this->config->getDebugFile(), + '[' . date('Y-m-d H:i:s') . ']: ' . $data . "\n", + FILE_APPEND + ); + } + } +} diff --git a/lib/Api/CatalogItemsV20220401Api.php b/lib/Api/CatalogItemsV20220401Api.php new file mode 100644 index 000000000..020989103 --- /dev/null +++ b/lib/Api/CatalogItemsV20220401Api.php @@ -0,0 +1,1043 @@ +getCatalogItemWithHttpInfo($asin, $marketplace_ids, $included_data, $locale); + return $response; + } + + /** + * Operation getCatalogItemWithHttpInfo + * + * @param string $asin The Amazon Standard Identification Number (ASIN) of the item. (required) + * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers. Data sets in the response contain data only for the specified marketplaces. (required) + * @param string[] $included_data A comma-delimited list of data sets to include in the response. Default: `summaries`. (optional) + * @param string $locale Locale for retrieving localized summaries. Defaults to the primary locale of the marketplace. (optional) + * + * @throws \SellingPartnerApi\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \SellingPartnerApi\Model\CatalogItemsV20220401\Item, HTTP status code, HTTP response headers (array of strings) + */ + public function getCatalogItemWithHttpInfo($asin, $marketplace_ids, $included_data = null, $locale = null) + { + $request = $this->getCatalogItemRequest($asin, $marketplace_ids, $included_data, $locale); + $signedRequest = $this->config->signRequest( + $request + ); + + $this->writeDebug($signedRequest); + $this->writeDebug((string) $signedRequest->getBody()); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($signedRequest, $options); + $this->writeDebug($response); + $this->writeDebug((string) $response->getBody()); + } catch (RequestException $e) { + $hasResponse = !empty($e->hasResponse()); + $body = (string) ($hasResponse ? $e->getResponse()->getBody() : '[NULL response]'); + $this->writeDebug($e->getResponse()); + $this->writeDebug($body); + throw new ApiException( + "[{$e->getCode()}] {$body}", + $e->getCode(), + $hasResponse ? $e->getResponse()->getHeaders() : [], + $body + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $signedRequest->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody()->getContents() + ); + } + + $responseBody = $response->getBody(); + switch($statusCode) { + case 200: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\Item' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\Item', $response->getHeaders()); + case 400: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 403: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 404: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 413: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 415: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 429: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 500: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 503: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + } + + $returnType = '\SellingPartnerApi\Model\CatalogItemsV20220401\Item'; + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\Item', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 413: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 415: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 500: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 503: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + $this->writeDebug($e); + throw $e; + } + } + + /** + * Operation getCatalogItemAsync + * + * + * + * @param string $asin The Amazon Standard Identification Number (ASIN) of the item. (required) + * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers. Data sets in the response contain data only for the specified marketplaces. (required) + * @param string[] $included_data A comma-delimited list of data sets to include in the response. Default: `summaries`. (optional) + * @param string $locale Locale for retrieving localized summaries. Defaults to the primary locale of the marketplace. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCatalogItemAsync($asin, $marketplace_ids, $included_data = null, $locale = null) + { + return $this->getCatalogItemAsyncWithHttpInfo($asin, $marketplace_ids, $included_data, $locale); + } + + /** + * Operation getCatalogItemAsyncWithHttpInfo + * + * + * + * @param string $asin The Amazon Standard Identification Number (ASIN) of the item. (required) + * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers. Data sets in the response contain data only for the specified marketplaces. (required) + * @param string[] $included_data A comma-delimited list of data sets to include in the response. Default: `summaries`. (optional) + * @param string $locale Locale for retrieving localized summaries. Defaults to the primary locale of the marketplace. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCatalogItemAsyncWithHttpInfo($asin, $marketplace_ids, $included_data = null, $locale = null) + { + $returnType = '\SellingPartnerApi\Model\CatalogItemsV20220401\Item'; + $request = $this->getCatalogItemRequest($asin, $marketplace_ids, $included_data, $locale); + $signedRequest = $this->config->signRequest( + $request + ); + + $this->writeDebug($signedRequest); + $this->writeDebug((string) $signedRequest->getBody()); + + return $this->client + ->sendAsync($signedRequest, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + $this->writeDebug($response); + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); + }, + function ($exception) { + $response = $exception->getResponse(); + $hasResponse = !empty($response); + $body = (string) ($hasResponse ? $response->getBody() : '[NULL response]'); + $this->writeDebug($response); + $statusCode = $hasResponse ? $response->getStatusCode() : $exception->getCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $hasResponse ? $response->getHeaders() : [], + $body + ); + } + ); + } + + /** + * Create request for operation 'getCatalogItem' + * + * @param string $asin The Amazon Standard Identification Number (ASIN) of the item. (required) + * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers. Data sets in the response contain data only for the specified marketplaces. (required) + * @param string[] $included_data A comma-delimited list of data sets to include in the response. Default: `summaries`. (optional) + * @param string $locale Locale for retrieving localized summaries. Defaults to the primary locale of the marketplace. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getCatalogItemRequest($asin, $marketplace_ids, $included_data = null, $locale = null) + { + // verify the required parameter 'asin' is set + if ($asin === null || (is_array($asin) && count($asin) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $asin when calling getCatalogItem' + ); + } + // verify the required parameter 'marketplace_ids' is set + if ($marketplace_ids === null || (is_array($marketplace_ids) && count($marketplace_ids) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $marketplace_ids when calling getCatalogItem' + ); + } + + $resourcePath = '/catalog/2022-04-01/items/{asin}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if (is_array($marketplace_ids)) { + $marketplace_ids = ObjectSerializer::serializeCollection($marketplace_ids, 'form', true); + } + if ($marketplace_ids !== null) { + $queryParams['marketplaceIds'] = $marketplace_ids; + } + + // query params + if (is_array($included_data)) { + $included_data = ObjectSerializer::serializeCollection($included_data, 'form', true); + } + if ($included_data !== null) { + $queryParams['includedData'] = $included_data; + } + + // query params + if (is_array($locale)) { + $locale = ObjectSerializer::serializeCollection($locale, '', true); + } + if ($locale !== null) { + $queryParams['locale'] = $locale; + } + + // path params + if ($asin !== null) { + $resourcePath = str_replace( + '{' . 'asin' . '}', + ObjectSerializer::toPathValue($asin), + $resourcePath + ); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + $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 searchCatalogItems + * + * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers for the request. (required) + * @param string[] $identifiers A comma-delimited list of product identifiers to search the Amazon catalog for. **Note:** Cannot be used with `keywords`. (optional) + * @param string $identifiers_type Type of product identifiers to search the Amazon catalog for. **Note:** Required when `identifiers` are provided. (optional) + * @param string[] $included_data A comma-delimited list of data sets to include in the response. Default: `summaries`. (optional) + * @param string $locale Locale for retrieving localized summaries. Defaults to the primary locale of the marketplace. (optional) + * @param string $seller_id A selling partner identifier, such as a seller account or vendor code. **Note:** Required when `identifiersType` is `SKU`. (optional) + * @param string[] $keywords A comma-delimited list of words to search the Amazon catalog for. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $brand_names A comma-delimited list of brand names to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $classification_ids A comma-delimited list of classification identifiers to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param int $page_size Number of results to be returned per page. (optional, default to 10) + * @param string $page_token A token to fetch a certain page when there are multiple pages worth of results. (optional) + * @param string $keywords_locale The language of the keywords provided for `keywords`-based queries. Defaults to the primary locale of the marketplace. **Note:** Cannot be used with `identifiers`. (optional) + * + * @throws \SellingPartnerApi\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \SellingPartnerApi\Model\CatalogItemsV20220401\ItemSearchResults + */ + public function searchCatalogItems($marketplace_ids, $identifiers = null, $identifiers_type = null, $included_data = null, $locale = null, $seller_id = null, $keywords = null, $brand_names = null, $classification_ids = null, $page_size = 10, $page_token = null, $keywords_locale = null) + { + $response = $this->searchCatalogItemsWithHttpInfo($marketplace_ids, $identifiers, $identifiers_type, $included_data, $locale, $seller_id, $keywords, $brand_names, $classification_ids, $page_size, $page_token, $keywords_locale); + return $response; + } + + /** + * Operation searchCatalogItemsWithHttpInfo + * + * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers for the request. (required) + * @param string[] $identifiers A comma-delimited list of product identifiers to search the Amazon catalog for. **Note:** Cannot be used with `keywords`. (optional) + * @param string $identifiers_type Type of product identifiers to search the Amazon catalog for. **Note:** Required when `identifiers` are provided. (optional) + * @param string[] $included_data A comma-delimited list of data sets to include in the response. Default: `summaries`. (optional) + * @param string $locale Locale for retrieving localized summaries. Defaults to the primary locale of the marketplace. (optional) + * @param string $seller_id A selling partner identifier, such as a seller account or vendor code. **Note:** Required when `identifiersType` is `SKU`. (optional) + * @param string[] $keywords A comma-delimited list of words to search the Amazon catalog for. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $brand_names A comma-delimited list of brand names to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $classification_ids A comma-delimited list of classification identifiers to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param int $page_size Number of results to be returned per page. (optional, default to 10) + * @param string $page_token A token to fetch a certain page when there are multiple pages worth of results. (optional) + * @param string $keywords_locale The language of the keywords provided for `keywords`-based queries. Defaults to the primary locale of the marketplace. **Note:** Cannot be used with `identifiers`. (optional) + * + * @throws \SellingPartnerApi\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \SellingPartnerApi\Model\CatalogItemsV20220401\ItemSearchResults, HTTP status code, HTTP response headers (array of strings) + */ + public function searchCatalogItemsWithHttpInfo($marketplace_ids, $identifiers = null, $identifiers_type = null, $included_data = null, $locale = null, $seller_id = null, $keywords = null, $brand_names = null, $classification_ids = null, $page_size = 10, $page_token = null, $keywords_locale = null) + { + $request = $this->searchCatalogItemsRequest($marketplace_ids, $identifiers, $identifiers_type, $included_data, $locale, $seller_id, $keywords, $brand_names, $classification_ids, $page_size, $page_token, $keywords_locale); + $signedRequest = $this->config->signRequest( + $request + ); + + $this->writeDebug($signedRequest); + $this->writeDebug((string) $signedRequest->getBody()); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($signedRequest, $options); + $this->writeDebug($response); + $this->writeDebug((string) $response->getBody()); + } catch (RequestException $e) { + $hasResponse = !empty($e->hasResponse()); + $body = (string) ($hasResponse ? $e->getResponse()->getBody() : '[NULL response]'); + $this->writeDebug($e->getResponse()); + $this->writeDebug($body); + throw new ApiException( + "[{$e->getCode()}] {$body}", + $e->getCode(), + $hasResponse ? $e->getResponse()->getHeaders() : [], + $body + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $signedRequest->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody()->getContents() + ); + } + + $responseBody = $response->getBody(); + switch($statusCode) { + case 200: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ItemSearchResults' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ItemSearchResults', $response->getHeaders()); + case 400: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 403: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 404: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 413: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 415: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 429: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 500: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + case 503: + if ('\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList' === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', $response->getHeaders()); + } + + $returnType = '\SellingPartnerApi\Model\CatalogItemsV20220401\ItemSearchResults'; + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ItemSearchResults', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 413: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 415: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 500: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 503: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SellingPartnerApi\Model\CatalogItemsV20220401\ErrorList', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + $this->writeDebug($e); + throw $e; + } + } + + /** + * Operation searchCatalogItemsAsync + * + * + * + * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers for the request. (required) + * @param string[] $identifiers A comma-delimited list of product identifiers to search the Amazon catalog for. **Note:** Cannot be used with `keywords`. (optional) + * @param string $identifiers_type Type of product identifiers to search the Amazon catalog for. **Note:** Required when `identifiers` are provided. (optional) + * @param string[] $included_data A comma-delimited list of data sets to include in the response. Default: `summaries`. (optional) + * @param string $locale Locale for retrieving localized summaries. Defaults to the primary locale of the marketplace. (optional) + * @param string $seller_id A selling partner identifier, such as a seller account or vendor code. **Note:** Required when `identifiersType` is `SKU`. (optional) + * @param string[] $keywords A comma-delimited list of words to search the Amazon catalog for. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $brand_names A comma-delimited list of brand names to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $classification_ids A comma-delimited list of classification identifiers to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param int $page_size Number of results to be returned per page. (optional, default to 10) + * @param string $page_token A token to fetch a certain page when there are multiple pages worth of results. (optional) + * @param string $keywords_locale The language of the keywords provided for `keywords`-based queries. Defaults to the primary locale of the marketplace. **Note:** Cannot be used with `identifiers`. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function searchCatalogItemsAsync($marketplace_ids, $identifiers = null, $identifiers_type = null, $included_data = null, $locale = null, $seller_id = null, $keywords = null, $brand_names = null, $classification_ids = null, $page_size = 10, $page_token = null, $keywords_locale = null) + { + return $this->searchCatalogItemsAsyncWithHttpInfo($marketplace_ids, $identifiers, $identifiers_type, $included_data, $locale, $seller_id, $keywords, $brand_names, $classification_ids, $page_size, $page_token, $keywords_locale); + } + + /** + * Operation searchCatalogItemsAsyncWithHttpInfo + * + * + * + * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers for the request. (required) + * @param string[] $identifiers A comma-delimited list of product identifiers to search the Amazon catalog for. **Note:** Cannot be used with `keywords`. (optional) + * @param string $identifiers_type Type of product identifiers to search the Amazon catalog for. **Note:** Required when `identifiers` are provided. (optional) + * @param string[] $included_data A comma-delimited list of data sets to include in the response. Default: `summaries`. (optional) + * @param string $locale Locale for retrieving localized summaries. Defaults to the primary locale of the marketplace. (optional) + * @param string $seller_id A selling partner identifier, such as a seller account or vendor code. **Note:** Required when `identifiersType` is `SKU`. (optional) + * @param string[] $keywords A comma-delimited list of words to search the Amazon catalog for. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $brand_names A comma-delimited list of brand names to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $classification_ids A comma-delimited list of classification identifiers to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param int $page_size Number of results to be returned per page. (optional, default to 10) + * @param string $page_token A token to fetch a certain page when there are multiple pages worth of results. (optional) + * @param string $keywords_locale The language of the keywords provided for `keywords`-based queries. Defaults to the primary locale of the marketplace. **Note:** Cannot be used with `identifiers`. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function searchCatalogItemsAsyncWithHttpInfo($marketplace_ids, $identifiers = null, $identifiers_type = null, $included_data = null, $locale = null, $seller_id = null, $keywords = null, $brand_names = null, $classification_ids = null, $page_size = 10, $page_token = null, $keywords_locale = null) + { + $returnType = '\SellingPartnerApi\Model\CatalogItemsV20220401\ItemSearchResults'; + $request = $this->searchCatalogItemsRequest($marketplace_ids, $identifiers, $identifiers_type, $included_data, $locale, $seller_id, $keywords, $brand_names, $classification_ids, $page_size, $page_token, $keywords_locale); + $signedRequest = $this->config->signRequest( + $request + ); + + $this->writeDebug($signedRequest); + $this->writeDebug((string) $signedRequest->getBody()); + + return $this->client + ->sendAsync($signedRequest, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + $this->writeDebug($response); + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = (string) $responseBody; + } + + return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); + }, + function ($exception) { + $response = $exception->getResponse(); + $hasResponse = !empty($response); + $body = (string) ($hasResponse ? $response->getBody() : '[NULL response]'); + $this->writeDebug($response); + $statusCode = $hasResponse ? $response->getStatusCode() : $exception->getCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $hasResponse ? $response->getHeaders() : [], + $body + ); + } + ); + } + + /** + * Create request for operation 'searchCatalogItems' + * + * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers for the request. (required) + * @param string[] $identifiers A comma-delimited list of product identifiers to search the Amazon catalog for. **Note:** Cannot be used with `keywords`. (optional) + * @param string $identifiers_type Type of product identifiers to search the Amazon catalog for. **Note:** Required when `identifiers` are provided. (optional) + * @param string[] $included_data A comma-delimited list of data sets to include in the response. Default: `summaries`. (optional) + * @param string $locale Locale for retrieving localized summaries. Defaults to the primary locale of the marketplace. (optional) + * @param string $seller_id A selling partner identifier, such as a seller account or vendor code. **Note:** Required when `identifiersType` is `SKU`. (optional) + * @param string[] $keywords A comma-delimited list of words to search the Amazon catalog for. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $brand_names A comma-delimited list of brand names to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param string[] $classification_ids A comma-delimited list of classification identifiers to limit the search for `keywords`-based queries. **Note:** Cannot be used with `identifiers`. (optional) + * @param int $page_size Number of results to be returned per page. (optional, default to 10) + * @param string $page_token A token to fetch a certain page when there are multiple pages worth of results. (optional) + * @param string $keywords_locale The language of the keywords provided for `keywords`-based queries. Defaults to the primary locale of the marketplace. **Note:** Cannot be used with `identifiers`. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function searchCatalogItemsRequest($marketplace_ids, $identifiers = null, $identifiers_type = null, $included_data = null, $locale = null, $seller_id = null, $keywords = null, $brand_names = null, $classification_ids = null, $page_size = 10, $page_token = null, $keywords_locale = null) + { + // verify the required parameter 'marketplace_ids' is set + if ($marketplace_ids === null || (is_array($marketplace_ids) && count($marketplace_ids) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $marketplace_ids when calling searchCatalogItems' + ); + } + + if ($this->getMarketplaceCount($marketplace_ids) > 1) { + throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling CatalogItemsV20220401Api.searchCatalogItems, number of items must be less than or equal to 1.'); + } + + if ($identifiers !== null && $this->getMarketplaceCount($identifiers) > 20) { + throw new \InvalidArgumentException('invalid value for "$identifiers" when calling CatalogItemsV20220401Api.searchCatalogItems, number of items must be less than or equal to 20.'); + } + + if ($keywords !== null && $this->getMarketplaceCount($keywords) > 20) { + throw new \InvalidArgumentException('invalid value for "$keywords" when calling CatalogItemsV20220401Api.searchCatalogItems, number of items must be less than or equal to 20.'); + } + + if ($page_size !== null && $page_size > 20) { + throw new \InvalidArgumentException('invalid value for "$page_size" when calling CatalogItemsV20220401Api.searchCatalogItems, must be smaller than or equal to 20.'); + } + + + $resourcePath = '/catalog/2022-04-01/items'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if (is_array($identifiers)) { + $identifiers = ObjectSerializer::serializeCollection($identifiers, 'form', true); + } + if ($identifiers !== null) { + $queryParams['identifiers'] = $identifiers; + } + + // query params + if (is_array($identifiers_type)) { + $identifiers_type = ObjectSerializer::serializeCollection($identifiers_type, '', true); + } + if ($identifiers_type !== null) { + $queryParams['identifiersType'] = $identifiers_type; + } + + // query params + if (is_array($marketplace_ids)) { + $marketplace_ids = ObjectSerializer::serializeCollection($marketplace_ids, 'form', true); + } + if ($marketplace_ids !== null) { + $queryParams['marketplaceIds'] = $marketplace_ids; + } + + // query params + if (is_array($included_data)) { + $included_data = ObjectSerializer::serializeCollection($included_data, 'form', true); + } + if ($included_data !== null) { + $queryParams['includedData'] = $included_data; + } + + // query params + if (is_array($locale)) { + $locale = ObjectSerializer::serializeCollection($locale, '', true); + } + if ($locale !== null) { + $queryParams['locale'] = $locale; + } + + // query params + if (is_array($seller_id)) { + $seller_id = ObjectSerializer::serializeCollection($seller_id, '', true); + } + if ($seller_id !== null) { + $queryParams['sellerId'] = $seller_id; + } + + // query params + if (is_array($keywords)) { + $keywords = ObjectSerializer::serializeCollection($keywords, 'form', true); + } + if ($keywords !== null) { + $queryParams['keywords'] = $keywords; + } + + // query params + if (is_array($brand_names)) { + $brand_names = ObjectSerializer::serializeCollection($brand_names, 'form', true); + } + if ($brand_names !== null) { + $queryParams['brandNames'] = $brand_names; + } + + // query params + if (is_array($classification_ids)) { + $classification_ids = ObjectSerializer::serializeCollection($classification_ids, 'form', true); + } + if ($classification_ids !== null) { + $queryParams['classificationIds'] = $classification_ids; + } + + // query params + if (is_array($page_size)) { + $page_size = ObjectSerializer::serializeCollection($page_size, '', true); + } + if ($page_size !== null) { + $queryParams['pageSize'] = $page_size; + } + + // query params + if (is_array($page_token)) { + $page_token = ObjectSerializer::serializeCollection($page_token, '', true); + } + if ($page_token !== null) { + $queryParams['pageToken'] = $page_token; + } + + // query params + if (is_array($keywords_locale)) { + $keywords_locale = ObjectSerializer::serializeCollection($keywords_locale, '', true); + } + if ($keywords_locale !== null) { + $queryParams['keywordsLocale'] = $keywords_locale; + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + $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 + ); + } + + /** + * Get the marketplace count demanded by the value type + * + * @param $value + * @return int + */ + private function getMarketplaceCount($value): int + { + return is_array($value) ? count($value) : count(explode(",", (string)$value)); + } +} diff --git a/lib/Configuration.php b/lib/Configuration.php new file mode 100644 index 000000000..5e2c4eede --- /dev/null +++ b/lib/Configuration.php @@ -0,0 +1,492 @@ + 0) { + throw new RuntimeException("Required configuration values were missing: " . implode(", ", $missingKeys)); + } + + if ( + (isset($configurationOptions["accessToken"]) && !isset($configurationOptions["accessTokenExpiration"])) || + (!isset($configurationOptions["accessToken"]) && isset($configurationOptions["accessTokenExpiration"])) + ) { + throw new RuntimeException('If one of the `accessToken` or `accessTokenExpiration` configuration options is provided, the other must be provided as well'); + } + + $options = array_merge( + $configurationOptions, + [ + "accessToken" => $configurationOptions["accessToken"] ?? null, + "accessTokenExpiration" => $configurationOptions["accessTokenExpiration"] ?? null, + "onUpdateCredentials" => $configurationOptions["onUpdateCredentials"] ?? null, + "roleArn" => $configurationOptions["roleArn"] ?? null, + ] + ); + + $this->endpoint = $options["endpoint"]; + $this->auth = new Authentication($options); + + $this->setRequestSigner($options["requestSigner"] ?? $this->auth); + } + + public function getRequestSigner(): RequestSignerContract + { + return $this->requestSigner; + } + + public function setRequestSigner(RequestSignerContract $requestSigner): void + { + $this->requestSigner = $requestSigner; + } + + /** + * Gets the host + * + * @return string Host + */ + public function getHost() + { + return $this->endpoint["url"]; + } + + /** + * Gets the stripped-down host (no protocol or trailing slash) + * + * @return string Host + */ + public function getBareHost() + { + $host = $this->getHost(); + $noProtocol = preg_replace("/.+\:\/\//", " ", $host); + return trim($noProtocol, "/"); + } + + /** + * Sets the user agent of the api client + * + * @param string $userAgent the user agent of the api client + * + * @throws InvalidArgumentException + * @return $this + */ + public function setUserAgent($userAgent) + { + if (!is_string($userAgent)) { + throw new InvalidArgumentException("User-agent must be a string."); + } + + $this->userAgent = $userAgent; + return $this; + } + + /** + * Gets the user agent of the api client + * + * @return string user agent + */ + public function getUserAgent() + { + return $this->userAgent; + } + + /** + * Sets debug flag + * + * @param bool $debug Debug flag + * + * @return $this + */ + public function setDebug($debug) + { + $this->debug = $debug; + return $this; + } + + /** + * Gets the debug flag + * + * @return bool + */ + public function getDebug() + { + return $this->debug; + } + + /** + * Sets the debug file + * + * @param string $debugFile Debug file + * + * @return $this + */ + public function setDebugFile($debugFile) + { + $this->debugFile = $debugFile; + return $this; + } + + /** + * Gets the debug file + * + * @return string + */ + public function getDebugFile() + { + return $this->debugFile; + } + + /** + * Sets the temp folder path + * + * @param ?string $tempFolderPath Temp folder path + * @return void + */ + public static function setTempFolderPath(?string $tempFolderPath = null): void + { + if ($tempFolderPath === null) { + static::$tempFolderPath = sys_get_temp_dir(); + } else { + static::$tempFolderPath = $tempFolderPath; + } + } + + /** + * Gets the temp folder path + * + * @return string Temp folder path + */ + public static function getTempFolderPath() + { + if (isset(static::$tempFolderPath) || static::$tempFolderPath === null) { + static::setTempFolderPath(); + } + return static::$tempFolderPath; + } + + /** + * Get the datetime string that was used to sign the most recently signed Selling Partner API request + * + * @return \DateTime The current time + */ + public function getRequestDatetime() + { + return $this->auth->formattedRequestTime(); + } + + /** + * Get LWA client ID. + * + * @return string + */ + public function getLwaClientId(): ?string + { + return $this->auth->getLwaClientId(); + } + + /** + * Set LWA client ID. + * + * @param string $lwaClientId + * @return void + */ + public function setLwaClientId(string $lwaClientId): void + { + $this->auth->setLwaClientId($lwaClientId); + } + + /** + * Get LWA client secret. + * + * @return string + */ + public function getLwaClientSecret(): ?string + { + return $this->auth->getLwaClientSecret(); + } + + /** + * Set LWA client secret. + * + * @param string $lwaClientSecret + * @return void + */ + public function setLwaClientSecret(string $lwaClientSecret): void + { + $this->auth->setLwaClientSecret($lwaClientSecret); + } + + /** + * Get LWA refresh token. + * + * @return string + */ + public function getLwaRefreshToken(): ?string + { + return $this->auth->getLwaRefreshToken(); + } + + /** + * Set LWA refresh token. + * + * @param string|null $lwaRefreshToken + * @return void + */ + public function setLwaRefreshToken(?string $lwaRefreshToken = null): void + { + $this->auth->setLwaRefreshToken($lwaRefreshToken); + } + + /** + * Get AWS access key ID. + * + * @return string + */ + public function getAwsAccessKeyId(): ?string + { + return $this->auth->getAwsAccessKeyId(); + } + + /** + * Set AWS access key ID. + * + * @param string $awsAccessKeyId + * @return void + */ + public function setAwsAccessKeyId(string $awsAccessKeyId): void + { + $this->auth->setAwsAccessKeyId($awsAccessKeyId); + } + + /** + * Get AWS secret access key. + * + * @return string|null + */ + public function getAwsSecretAccessKey(): ?string + { + return $this->auth->getAwsSecretAccessKey(); + } + + /** + * Set AWS secret access key. + * + * @param string $awsSecretAccessKey + * @return void + */ + public function setAwsSecretAccessKey(string $awsSecretAccessKey): void + { + $this->auth->setAwsSecretAccessKey($awsSecretAccessKey); + } + + /** + * Get current SP API endpoint. + * + * @return array + */ + public function getEndpoint(): array + { + return $this->endpoint; + } + + /** + * Set SP API endpoint. $endpoint should be one of the constants from Endpoint.php. + * + * @param array $endpoint + * @throws RuntimeException + * @return void + */ + public function setEndpoint(array $endpoint): void + { + if (!array_key_exists('url', $endpoint) || !array_key_exists('region', $endpoint)) { + throw new RuntimeException('$endpoint must contain `url` and `region` keys'); + } + + $this->endpoint = $endpoint; + $this->auth->setEndpoint($endpoint); + } + + /** + * Sign a request to the Selling Partner API using the AWS Signature V4 protocol. + * + * @param Request $request The request to sign + * @param string $scope The scope of the request, if it's grantless + * + * @return Request The signed request + */ + public function signRequest($request, $scope = null, $restrictedPath = null, $operation = null) + { + return $this->requestSigner->signRequest($request, $scope, $restrictedPath, $operation); + } + + /** + * Gets the essential information for debugging + * + * @param string|null $tempFolderPath The path to the temp folder. + * @return string The report for debugging + */ + public static function toDebugReport(?string $tempFolderPath = null) + { + if ($tempFolderPath === null) { + $tempFolderPath = static::getTempFolderPath(); + } + $report = 'PHP SDK (SellingPartnerApi) Debug Report:' . PHP_EOL; + $report .= ' OS: ' . php_uname() . PHP_EOL; + $report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL; + $report .= ' The version of the OpenAPI document: 2020-11-01' . PHP_EOL; + $report .= ' SDK Package Version: 5.10.3' . PHP_EOL; + $report .= ' Temp Folder Path: ' . $tempFolderPath . PHP_EOL; + + return $report; + } + + /** + * Returns an array of host settings + * + * @return array an array of host settings + */ + public function getHostSettings() + { + return [ + [ + "url" => "https://sellingpartnerapi-na.amazon.com", + "description" => "No description provided", + ] + ]; + } + + /** + * Returns URL based on the index and variables + * + * @param int $index index of the host settings + * @param array|null $variables hash of variable and the corresponding value (optional) + * @return string URL based on host settings + */ + public function getHostFromSettings($index, $variables = null) + { + if (null === $variables) { + $variables = []; + } + + $hosts = $this->getHostSettings(); + + // check array index out of bound + if ($index < 0 || $index >= count($hosts)) { + throw new InvalidArgumentException("Invalid index $index when selecting the host. Must be less than ".count($hosts)); + } + + $host = $hosts[$index]; + $url = $host["url"]; + + // go through variable and assign a value + foreach ($host["variables"] ?? [] as $name => $variable) { + if (array_key_exists($name, $variables)) { // check to see if it's in the variables provided by the user + if (in_array($variables[$name], $variable["enum_values"], true)) { // check to see if the value is in the enum + $url = str_replace("{".$name."}", $variables[$name], $url); + } else { + throw new InvalidArgumentException("The variable `$name` in the host URL has invalid value ".$variables[$name].". Must be ".implode(',', $variable["enum_values"])."."); + } + } else { + // use default value + $url = str_replace("{".$name."}", $variable["default_value"], $url); + } + } + + return $url; + } +} diff --git a/lib/Model/OrdersV0/OrderItem.php b/lib/Model/OrdersV0/OrderItem.php new file mode 100644 index 000000000..59d41ad03 --- /dev/null +++ b/lib/Model/OrdersV0/OrderItem.php @@ -0,0 +1,1227 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class OrderItem extends BaseModel implements ModelInterface, ArrayAccess, \JsonSerializable, \IteratorAggregate +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'OrderItem'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'asin' => 'string', + 'seller_sku' => 'string', + 'order_item_id' => 'string', + 'title' => 'string', + 'quantity_ordered' => 'int', + 'quantity_shipped' => 'int', + 'product_info' => '\SellingPartnerApi\Model\OrdersV0\ProductInfoDetail', + 'points_granted' => '\SellingPartnerApi\Model\OrdersV0\PointsGrantedDetail', + 'item_price' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'shipping_price' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'item_tax' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'shipping_tax' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'shipping_discount' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'shipping_discount_tax' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'promotion_discount' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'promotion_discount_tax' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'promotion_ids' => 'string[]', + 'cod_fee' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'cod_fee_discount' => '\SellingPartnerApi\Model\OrdersV0\Money', + 'is_gift' => 'bool', + 'condition_note' => 'string', + 'condition_id' => 'string', + 'condition_subtype_id' => 'string', + 'scheduled_delivery_start_date' => 'string', + 'scheduled_delivery_end_date' => 'string', + 'price_designation' => 'string', + 'tax_collection' => '\SellingPartnerApi\Model\OrdersV0\TaxCollection', + 'serial_number_required' => 'bool', + 'is_transparency' => 'bool', + 'ioss_number' => 'string', + 'store_chain_store_id' => 'string', + 'deemed_reseller_category' => 'string', + 'buyer_info' => '\SellingPartnerApi\Model\OrdersV0\ItemBuyerInfo', + 'buyer_requested_cancel' => '\SellingPartnerApi\Model\OrdersV0\BuyerRequestedCancel', + 'serial_numbers' => 'string[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'asin' => null, + 'seller_sku' => null, + 'order_item_id' => null, + 'title' => null, + 'quantity_ordered' => null, + 'quantity_shipped' => null, + 'product_info' => null, + 'points_granted' => null, + 'item_price' => null, + 'shipping_price' => null, + 'item_tax' => null, + 'shipping_tax' => null, + 'shipping_discount' => null, + 'shipping_discount_tax' => null, + 'promotion_discount' => null, + 'promotion_discount_tax' => null, + 'promotion_ids' => null, + 'cod_fee' => null, + 'cod_fee_discount' => null, + 'is_gift' => null, + 'condition_note' => null, + 'condition_id' => null, + 'condition_subtype_id' => null, + 'scheduled_delivery_start_date' => null, + 'scheduled_delivery_end_date' => null, + 'price_designation' => null, + 'tax_collection' => null, + 'serial_number_required' => null, + 'is_transparency' => null, + 'ioss_number' => null, + 'store_chain_store_id' => null, + 'deemed_reseller_category' => null, + 'buyer_info' => null, + 'buyer_requested_cancel' => null, + 'serial_numbers' => null + ]; + + + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'asin' => 'ASIN', + 'seller_sku' => 'SellerSKU', + 'order_item_id' => 'OrderItemId', + 'title' => 'Title', + 'quantity_ordered' => 'QuantityOrdered', + 'quantity_shipped' => 'QuantityShipped', + 'product_info' => 'ProductInfo', + 'points_granted' => 'PointsGranted', + 'item_price' => 'ItemPrice', + 'shipping_price' => 'ShippingPrice', + 'item_tax' => 'ItemTax', + 'shipping_tax' => 'ShippingTax', + 'shipping_discount' => 'ShippingDiscount', + 'shipping_discount_tax' => 'ShippingDiscountTax', + 'promotion_discount' => 'PromotionDiscount', + 'promotion_discount_tax' => 'PromotionDiscountTax', + 'promotion_ids' => 'PromotionIds', + 'cod_fee' => 'CODFee', + 'cod_fee_discount' => 'CODFeeDiscount', + 'is_gift' => 'IsGift', + 'condition_note' => 'ConditionNote', + 'condition_id' => 'ConditionId', + 'condition_subtype_id' => 'ConditionSubtypeId', + 'scheduled_delivery_start_date' => 'ScheduledDeliveryStartDate', + 'scheduled_delivery_end_date' => 'ScheduledDeliveryEndDate', + 'price_designation' => 'PriceDesignation', + 'tax_collection' => 'TaxCollection', + 'serial_number_required' => 'SerialNumberRequired', + 'is_transparency' => 'IsTransparency', + 'ioss_number' => 'IossNumber', + 'store_chain_store_id' => 'StoreChainStoreId', + 'deemed_reseller_category' => 'DeemedResellerCategory', + 'buyer_info' => 'BuyerInfo', + 'buyer_requested_cancel' => 'BuyerRequestedCancel', + 'serial_numbers' => 'SerialNumbers' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'asin' => 'setAsin', + 'seller_sku' => 'setSellerSku', + 'order_item_id' => 'setOrderItemId', + 'title' => 'setTitle', + 'quantity_ordered' => 'setQuantityOrdered', + 'quantity_shipped' => 'setQuantityShipped', + 'product_info' => 'setProductInfo', + 'points_granted' => 'setPointsGranted', + 'item_price' => 'setItemPrice', + 'shipping_price' => 'setShippingPrice', + 'item_tax' => 'setItemTax', + 'shipping_tax' => 'setShippingTax', + 'shipping_discount' => 'setShippingDiscount', + 'shipping_discount_tax' => 'setShippingDiscountTax', + 'promotion_discount' => 'setPromotionDiscount', + 'promotion_discount_tax' => 'setPromotionDiscountTax', + 'promotion_ids' => 'setPromotionIds', + 'cod_fee' => 'setCodFee', + 'cod_fee_discount' => 'setCodFeeDiscount', + 'is_gift' => 'setIsGift', + 'condition_note' => 'setConditionNote', + 'condition_id' => 'setConditionId', + 'condition_subtype_id' => 'setConditionSubtypeId', + 'scheduled_delivery_start_date' => 'setScheduledDeliveryStartDate', + 'scheduled_delivery_end_date' => 'setScheduledDeliveryEndDate', + 'price_designation' => 'setPriceDesignation', + 'tax_collection' => 'setTaxCollection', + 'serial_number_required' => 'setSerialNumberRequired', + 'is_transparency' => 'setIsTransparency', + 'ioss_number' => 'setIossNumber', + 'store_chain_store_id' => 'setStoreChainStoreId', + 'deemed_reseller_category' => 'setDeemedResellerCategory', + 'buyer_info' => 'setBuyerInfo', + 'buyer_requested_cancel' => 'setBuyerRequestedCancel', + 'serial_numbers' => 'setSerialNumbers' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'asin' => 'getAsin', + 'seller_sku' => 'getSellerSku', + 'order_item_id' => 'getOrderItemId', + 'title' => 'getTitle', + 'quantity_ordered' => 'getQuantityOrdered', + 'quantity_shipped' => 'getQuantityShipped', + 'product_info' => 'getProductInfo', + 'points_granted' => 'getPointsGranted', + 'item_price' => 'getItemPrice', + 'shipping_price' => 'getShippingPrice', + 'item_tax' => 'getItemTax', + 'shipping_tax' => 'getShippingTax', + 'shipping_discount' => 'getShippingDiscount', + 'shipping_discount_tax' => 'getShippingDiscountTax', + 'promotion_discount' => 'getPromotionDiscount', + 'promotion_discount_tax' => 'getPromotionDiscountTax', + 'promotion_ids' => 'getPromotionIds', + 'cod_fee' => 'getCodFee', + 'cod_fee_discount' => 'getCodFeeDiscount', + 'is_gift' => 'getIsGift', + 'condition_note' => 'getConditionNote', + 'condition_id' => 'getConditionId', + 'condition_subtype_id' => 'getConditionSubtypeId', + 'scheduled_delivery_start_date' => 'getScheduledDeliveryStartDate', + 'scheduled_delivery_end_date' => 'getScheduledDeliveryEndDate', + 'price_designation' => 'getPriceDesignation', + 'tax_collection' => 'getTaxCollection', + 'serial_number_required' => 'getSerialNumberRequired', + 'is_transparency' => 'getIsTransparency', + 'ioss_number' => 'getIossNumber', + 'store_chain_store_id' => 'getStoreChainStoreId', + 'deemed_reseller_category' => 'getDeemedResellerCategory', + 'buyer_info' => 'getBuyerInfo', + 'buyer_requested_cancel' => 'getBuyerRequestedCancel', + 'serial_numbers' => 'getSerialNumbers' + ]; + + + + const DEEMED_RESELLER_CATEGORY_IOSS = 'IOSS'; + const DEEMED_RESELLER_CATEGORY_UOSS = 'UOSS'; + const DEEMED_RESELLER_CATEGORY_CA_MPF = 'CA_MPF'; + const DEEMED_RESELLER_CATEGORY_AU_VOEC = 'AU_VOEC'; + const DEEMED_RESELLER_CATEGORY_GB_VOEC = 'GB_VOEC'; + const DEEMED_RESELLER_CATEGORY_JE_VOEC = 'JE_VOEC'; + const DEEMED_RESELLER_CATEGORY_KZ_VOEC = 'KZ_VOEC'; + const DEEMED_RESELLER_CATEGORY_MY_VOEC = 'MY_VOEC'; + const DEEMED_RESELLER_CATEGORY_NO_VOEC = 'NO_VOEC'; + const DEEMED_RESELLER_CATEGORY_NG_VOEC = 'NG_VOEC'; + const DEEMED_RESELLER_CATEGORY_NZ_VOEC = 'NZ_VOEC'; + const DEEMED_RESELLER_CATEGORY_SG_VOEC = 'SG_VOEC'; + const DEEMED_RESELLER_CATEGORY_CH_SUPPLIER_IMPORT = 'CH_SUPPLIER_IMPORT'; + + + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getDeemedResellerCategoryAllowableValues() + { + $baseVals = [ + self::DEEMED_RESELLER_CATEGORY_IOSS, + self::DEEMED_RESELLER_CATEGORY_UOSS, + self::DEEMED_RESELLER_CATEGORY_AU_VOEC, + self::DEEMED_RESELLER_CATEGORY_CA_MPF, + self::DEEMED_RESELLER_CATEGORY_GB_VOEC, + self::DEEMED_RESELLER_CATEGORY_JE_VOEC, + self::DEEMED_RESELLER_CATEGORY_KZ_VOEC, + self::DEEMED_RESELLER_CATEGORY_MY_VOEC, + self::DEEMED_RESELLER_CATEGORY_NO_VOEC, + self::DEEMED_RESELLER_CATEGORY_NG_VOEC, + self::DEEMED_RESELLER_CATEGORY_NZ_VOEC, + self::DEEMED_RESELLER_CATEGORY_SG_VOEC, + self::DEEMED_RESELLER_CATEGORY_CH_SUPPLIER_IMPORT, + ]; + + // This is necessary because Amazon does not consistently capitalize their + // enum values, so we do case-insensitive enum value validation in ObjectSerializer + return array_map(function ($val) { return strtoupper($val); }, $baseVals); + } + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->container['asin'] = $data['asin'] ?? null; + $this->container['seller_sku'] = $data['seller_sku'] ?? null; + $this->container['order_item_id'] = $data['order_item_id'] ?? null; + $this->container['title'] = $data['title'] ?? null; + $this->container['quantity_ordered'] = $data['quantity_ordered'] ?? null; + $this->container['quantity_shipped'] = $data['quantity_shipped'] ?? null; + $this->container['product_info'] = $data['product_info'] ?? null; + $this->container['points_granted'] = $data['points_granted'] ?? null; + $this->container['item_price'] = $data['item_price'] ?? null; + $this->container['shipping_price'] = $data['shipping_price'] ?? null; + $this->container['item_tax'] = $data['item_tax'] ?? null; + $this->container['shipping_tax'] = $data['shipping_tax'] ?? null; + $this->container['shipping_discount'] = $data['shipping_discount'] ?? null; + $this->container['shipping_discount_tax'] = $data['shipping_discount_tax'] ?? null; + $this->container['promotion_discount'] = $data['promotion_discount'] ?? null; + $this->container['promotion_discount_tax'] = $data['promotion_discount_tax'] ?? null; + $this->container['promotion_ids'] = $data['promotion_ids'] ?? null; + $this->container['cod_fee'] = $data['cod_fee'] ?? null; + $this->container['cod_fee_discount'] = $data['cod_fee_discount'] ?? null; + $this->container['is_gift'] = $data['is_gift'] ?? null; + $this->container['condition_note'] = $data['condition_note'] ?? null; + $this->container['condition_id'] = $data['condition_id'] ?? null; + $this->container['condition_subtype_id'] = $data['condition_subtype_id'] ?? null; + $this->container['scheduled_delivery_start_date'] = $data['scheduled_delivery_start_date'] ?? null; + $this->container['scheduled_delivery_end_date'] = $data['scheduled_delivery_end_date'] ?? null; + $this->container['price_designation'] = $data['price_designation'] ?? null; + $this->container['tax_collection'] = $data['tax_collection'] ?? null; + $this->container['serial_number_required'] = $data['serial_number_required'] ?? null; + $this->container['is_transparency'] = $data['is_transparency'] ?? null; + $this->container['ioss_number'] = $data['ioss_number'] ?? null; + $this->container['store_chain_store_id'] = $data['store_chain_store_id'] ?? null; + $this->container['deemed_reseller_category'] = $data['deemed_reseller_category'] ?? null; + $this->container['buyer_info'] = $data['buyer_info'] ?? null; + $this->container['buyer_requested_cancel'] = $data['buyer_requested_cancel'] ?? null; + $this->container['serial_numbers'] = $data['serial_numbers'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + if ($this->container['asin'] === null) { + $invalidProperties[] = "'asin' can't be null"; + } + if ($this->container['order_item_id'] === null) { + $invalidProperties[] = "'order_item_id' can't be null"; + } + if ($this->container['quantity_ordered'] === null) { + $invalidProperties[] = "'quantity_ordered' can't be null"; + } + $allowedValues = $this->getDeemedResellerCategoryAllowableValues(); + if ( + !is_null($this->container['deemed_reseller_category']) && + !in_array(strtoupper($this->container['deemed_reseller_category']), $allowedValues, true) + ) { + $invalidProperties[] = sprintf( + "invalid value '%s' for 'deemed_reseller_category', must be one of '%s'", + $this->container['deemed_reseller_category'], + implode("', '", $allowedValues) + ); + } + + return $invalidProperties; + } + + + /** + * Gets asin + * + * @return string + */ + public function getAsin() + { + return $this->container['asin']; + } + + /** + * Sets asin + * + * @param string $asin The Amazon Standard Identification Number (ASIN) of the item. + * + * @return self + */ + public function setAsin($asin) + { + $this->container['asin'] = $asin; + + return $this; + } + /** + * Gets seller_sku + * + * @return string|null + */ + public function getSellerSku() + { + return $this->container['seller_sku']; + } + + /** + * Sets seller_sku + * + * @param string|null $seller_sku The seller stock keeping unit (SKU) of the item. + * + * @return self + */ + public function setSellerSku($seller_sku) + { + $this->container['seller_sku'] = $seller_sku; + + return $this; + } + /** + * Gets order_item_id + * + * @return string + */ + public function getOrderItemId() + { + return $this->container['order_item_id']; + } + + /** + * Sets order_item_id + * + * @param string $order_item_id An Amazon-defined order item identifier. + * + * @return self + */ + public function setOrderItemId($order_item_id) + { + $this->container['order_item_id'] = $order_item_id; + + return $this; + } + /** + * Gets title + * + * @return string|null + */ + public function getTitle() + { + return $this->container['title']; + } + + /** + * Sets title + * + * @param string|null $title The name of the item. + * + * @return self + */ + public function setTitle($title) + { + $this->container['title'] = $title; + + return $this; + } + /** + * Gets quantity_ordered + * + * @return int + */ + public function getQuantityOrdered() + { + return $this->container['quantity_ordered']; + } + + /** + * Sets quantity_ordered + * + * @param int $quantity_ordered The number of items in the order. + * + * @return self + */ + public function setQuantityOrdered($quantity_ordered) + { + $this->container['quantity_ordered'] = $quantity_ordered; + + return $this; + } + /** + * Gets quantity_shipped + * + * @return int|null + */ + public function getQuantityShipped() + { + return $this->container['quantity_shipped']; + } + + /** + * Sets quantity_shipped + * + * @param int|null $quantity_shipped The number of items shipped. + * + * @return self + */ + public function setQuantityShipped($quantity_shipped) + { + $this->container['quantity_shipped'] = $quantity_shipped; + + return $this; + } + /** + * Gets product_info + * + * @return \SellingPartnerApi\Model\OrdersV0\ProductInfoDetail|null + */ + public function getProductInfo() + { + return $this->container['product_info']; + } + + /** + * Sets product_info + * + * @param \SellingPartnerApi\Model\OrdersV0\ProductInfoDetail|null $product_info product_info + * + * @return self + */ + public function setProductInfo($product_info) + { + $this->container['product_info'] = $product_info; + + return $this; + } + /** + * Gets points_granted + * + * @return \SellingPartnerApi\Model\OrdersV0\PointsGrantedDetail|null + */ + public function getPointsGranted() + { + return $this->container['points_granted']; + } + + /** + * Sets points_granted + * + * @param \SellingPartnerApi\Model\OrdersV0\PointsGrantedDetail|null $points_granted points_granted + * + * @return self + */ + public function setPointsGranted($points_granted) + { + $this->container['points_granted'] = $points_granted; + + return $this; + } + /** + * Gets item_price + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getItemPrice() + { + return $this->container['item_price']; + } + + /** + * Sets item_price + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $item_price item_price + * + * @return self + */ + public function setItemPrice($item_price) + { + $this->container['item_price'] = $item_price; + + return $this; + } + /** + * Gets shipping_price + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getShippingPrice() + { + return $this->container['shipping_price']; + } + + /** + * Sets shipping_price + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $shipping_price shipping_price + * + * @return self + */ + public function setShippingPrice($shipping_price) + { + $this->container['shipping_price'] = $shipping_price; + + return $this; + } + /** + * Gets item_tax + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getItemTax() + { + return $this->container['item_tax']; + } + + /** + * Sets item_tax + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $item_tax item_tax + * + * @return self + */ + public function setItemTax($item_tax) + { + $this->container['item_tax'] = $item_tax; + + return $this; + } + /** + * Gets shipping_tax + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getShippingTax() + { + return $this->container['shipping_tax']; + } + + /** + * Sets shipping_tax + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $shipping_tax shipping_tax + * + * @return self + */ + public function setShippingTax($shipping_tax) + { + $this->container['shipping_tax'] = $shipping_tax; + + return $this; + } + /** + * Gets shipping_discount + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getShippingDiscount() + { + return $this->container['shipping_discount']; + } + + /** + * Sets shipping_discount + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $shipping_discount shipping_discount + * + * @return self + */ + public function setShippingDiscount($shipping_discount) + { + $this->container['shipping_discount'] = $shipping_discount; + + return $this; + } + /** + * Gets shipping_discount_tax + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getShippingDiscountTax() + { + return $this->container['shipping_discount_tax']; + } + + /** + * Sets shipping_discount_tax + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $shipping_discount_tax shipping_discount_tax + * + * @return self + */ + public function setShippingDiscountTax($shipping_discount_tax) + { + $this->container['shipping_discount_tax'] = $shipping_discount_tax; + + return $this; + } + /** + * Gets promotion_discount + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getPromotionDiscount() + { + return $this->container['promotion_discount']; + } + + /** + * Sets promotion_discount + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $promotion_discount promotion_discount + * + * @return self + */ + public function setPromotionDiscount($promotion_discount) + { + $this->container['promotion_discount'] = $promotion_discount; + + return $this; + } + /** + * Gets promotion_discount_tax + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getPromotionDiscountTax() + { + return $this->container['promotion_discount_tax']; + } + + /** + * Sets promotion_discount_tax + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $promotion_discount_tax promotion_discount_tax + * + * @return self + */ + public function setPromotionDiscountTax($promotion_discount_tax) + { + $this->container['promotion_discount_tax'] = $promotion_discount_tax; + + return $this; + } + /** + * Gets promotion_ids + * + * @return string[]|null + */ + public function getPromotionIds() + { + return $this->container['promotion_ids']; + } + + /** + * Sets promotion_ids + * + * @param string[]|null $promotion_ids A list of promotion identifiers provided by the seller when the promotions were created. + * + * @return self + */ + public function setPromotionIds($promotion_ids) + { + $this->container['promotion_ids'] = $promotion_ids; + + return $this; + } + /** + * Gets cod_fee + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getCodFee() + { + return $this->container['cod_fee']; + } + + /** + * Sets cod_fee + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $cod_fee cod_fee + * + * @return self + */ + public function setCodFee($cod_fee) + { + $this->container['cod_fee'] = $cod_fee; + + return $this; + } + /** + * Gets cod_fee_discount + * + * @return \SellingPartnerApi\Model\OrdersV0\Money|null + */ + public function getCodFeeDiscount() + { + return $this->container['cod_fee_discount']; + } + + /** + * Sets cod_fee_discount + * + * @param \SellingPartnerApi\Model\OrdersV0\Money|null $cod_fee_discount cod_fee_discount + * + * @return self + */ + public function setCodFeeDiscount($cod_fee_discount) + { + $this->container['cod_fee_discount'] = $cod_fee_discount; + + return $this; + } + /** + * Gets is_gift + * + * @return bool|null + */ + public function getIsGift() + { + return $this->container['is_gift']; + } + + /** + * Sets is_gift + * + * @param bool|null $is_gift When true, the item is a gift. + * + * @return self + */ + public function setIsGift($is_gift) + { + $this->container['is_gift'] = $is_gift; + + return $this; + } + /** + * Gets condition_note + * + * @return string|null + */ + public function getConditionNote() + { + return $this->container['condition_note']; + } + + /** + * Sets condition_note + * + * @param string|null $condition_note The condition of the item as described by the seller. + * + * @return self + */ + public function setConditionNote($condition_note) + { + $this->container['condition_note'] = $condition_note; + + return $this; + } + /** + * Gets condition_id + * + * @return string|null + */ + public function getConditionId() + { + return $this->container['condition_id']; + } + + /** + * Sets condition_id + * + * @param string|null $condition_id The condition of the item. + * Possible values: New, Used, Collectible, Refurbished, Preorder, Club. + * + * @return self + */ + public function setConditionId($condition_id) + { + $this->container['condition_id'] = $condition_id; + + return $this; + } + /** + * Gets condition_subtype_id + * + * @return string|null + */ + public function getConditionSubtypeId() + { + return $this->container['condition_subtype_id']; + } + + /** + * Sets condition_subtype_id + * + * @param string|null $condition_subtype_id The subcondition of the item. + * Possible values: New, Mint, Very Good, Good, Acceptable, Poor, Club, OEM, Warranty, Refurbished Warranty, Refurbished, Open Box, Any, Other. + * + * @return self + */ + public function setConditionSubtypeId($condition_subtype_id) + { + $this->container['condition_subtype_id'] = $condition_subtype_id; + + return $this; + } + /** + * Gets scheduled_delivery_start_date + * + * @return string|null + */ + public function getScheduledDeliveryStartDate() + { + return $this->container['scheduled_delivery_start_date']; + } + + /** + * Sets scheduled_delivery_start_date + * + * @param string|null $scheduled_delivery_start_date The start date of the scheduled delivery window in the time zone of the order destination. In ISO 8601 date time format. + * + * @return self + */ + public function setScheduledDeliveryStartDate($scheduled_delivery_start_date) + { + $this->container['scheduled_delivery_start_date'] = $scheduled_delivery_start_date; + + return $this; + } + /** + * Gets scheduled_delivery_end_date + * + * @return string|null + */ + public function getScheduledDeliveryEndDate() + { + return $this->container['scheduled_delivery_end_date']; + } + + /** + * Sets scheduled_delivery_end_date + * + * @param string|null $scheduled_delivery_end_date The end date of the scheduled delivery window in the time zone of the order destination. In ISO 8601 date time format. + * + * @return self + */ + public function setScheduledDeliveryEndDate($scheduled_delivery_end_date) + { + $this->container['scheduled_delivery_end_date'] = $scheduled_delivery_end_date; + + return $this; + } + /** + * Gets price_designation + * + * @return string|null + */ + public function getPriceDesignation() + { + return $this->container['price_designation']; + } + + /** + * Sets price_designation + * + * @param string|null $price_designation Indicates that the selling price is a special price that is available only for Amazon Business orders. For more information about the Amazon Business Seller Program, see the [Amazon Business website](https://www.amazon.com/b2b/info/amazon-business). + * Possible values: BusinessPrice - A special price that is available only for Amazon Business orders. + * + * @return self + */ + public function setPriceDesignation($price_designation) + { + $this->container['price_designation'] = $price_designation; + + return $this; + } + /** + * Gets tax_collection + * + * @return \SellingPartnerApi\Model\OrdersV0\TaxCollection|null + */ + public function getTaxCollection() + { + return $this->container['tax_collection']; + } + + /** + * Sets tax_collection + * + * @param \SellingPartnerApi\Model\OrdersV0\TaxCollection|null $tax_collection tax_collection + * + * @return self + */ + public function setTaxCollection($tax_collection) + { + $this->container['tax_collection'] = $tax_collection; + + return $this; + } + /** + * Gets serial_number_required + * + * @return bool|null + */ + public function getSerialNumberRequired() + { + return $this->container['serial_number_required']; + } + + /** + * Sets serial_number_required + * + * @param bool|null $serial_number_required When true, the product type for this item has a serial number. + * Returned only for Amazon Easy Ship orders. + * + * @return self + */ + public function setSerialNumberRequired($serial_number_required) + { + $this->container['serial_number_required'] = $serial_number_required; + + return $this; + } + /** + * Gets is_transparency + * + * @return bool|null + */ + public function getIsTransparency() + { + return $this->container['is_transparency']; + } + + /** + * Sets is_transparency + * + * @param bool|null $is_transparency When true, transparency codes are required. + * + * @return self + */ + public function setIsTransparency($is_transparency) + { + $this->container['is_transparency'] = $is_transparency; + + return $this; + } + /** + * Gets ioss_number + * + * @return string|null + */ + public function getIossNumber() + { + return $this->container['ioss_number']; + } + + /** + * Sets ioss_number + * + * @param string|null $ioss_number The IOSS number for the marketplace. Sellers shipping to the European Union (EU) from outside of the EU must provide this IOSS number to their carrier when Amazon has collected the VAT on the sale. + * + * @return self + */ + public function setIossNumber($ioss_number) + { + $this->container['ioss_number'] = $ioss_number; + + return $this; + } + /** + * Gets store_chain_store_id + * + * @return string|null + */ + public function getStoreChainStoreId() + { + return $this->container['store_chain_store_id']; + } + + /** + * Sets store_chain_store_id + * + * @param string|null $store_chain_store_id The store chain store identifier. Linked to a specific store in a store chain. + * + * @return self + */ + public function setStoreChainStoreId($store_chain_store_id) + { + $this->container['store_chain_store_id'] = $store_chain_store_id; + + return $this; + } + /** + * Gets deemed_reseller_category + * + * @return string|null + */ + public function getDeemedResellerCategory() + { + return $this->container['deemed_reseller_category']; + } + + /** + * Sets deemed_reseller_category + * + * @param string|null $deemed_reseller_category The category of deemed reseller. This applies to selling partners that are not based in the EU and is used to help them meet the VAT Deemed Reseller tax laws in the EU and UK. + * + * @return self + */ + public function setDeemedResellerCategory($deemed_reseller_category) + { + $allowedValues = $this->getDeemedResellerCategoryAllowableValues(); + if (!is_null($deemed_reseller_category) &&!in_array(strtoupper($deemed_reseller_category), $allowedValues, true)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value '%s' for 'deemed_reseller_category', must be one of '%s'", + $deemed_reseller_category, + implode("', '", $allowedValues) + ) + ); + } + $this->container['deemed_reseller_category'] = $deemed_reseller_category; + + return $this; + } + /** + * Gets buyer_info + * + * @return \SellingPartnerApi\Model\OrdersV0\ItemBuyerInfo|null + */ + public function getBuyerInfo() + { + return $this->container['buyer_info']; + } + + /** + * Sets buyer_info + * + * @param \SellingPartnerApi\Model\OrdersV0\ItemBuyerInfo|null $buyer_info buyer_info + * + * @return self + */ + public function setBuyerInfo($buyer_info) + { + $this->container['buyer_info'] = $buyer_info; + + return $this; + } + /** + * Gets buyer_requested_cancel + * + * @return \SellingPartnerApi\Model\OrdersV0\BuyerRequestedCancel|null + */ + public function getBuyerRequestedCancel() + { + return $this->container['buyer_requested_cancel']; + } + + /** + * Sets buyer_requested_cancel + * + * @param \SellingPartnerApi\Model\OrdersV0\BuyerRequestedCancel|null $buyer_requested_cancel buyer_requested_cancel + * + * @return self + */ + public function setBuyerRequestedCancel($buyer_requested_cancel) + { + $this->container['buyer_requested_cancel'] = $buyer_requested_cancel; + + return $this; + } + /** + * Gets serial_numbers + * + * @return string[]|null + */ + public function getSerialNumbers() + { + return $this->container['serial_numbers']; + } + + /** + * Sets serial_numbers + * + * @param string[]|null $serial_numbers A list of serial numbers for electronic products that are shipped to customers. Returned for FBA orders only. + * + * @return self + */ + public function setSerialNumbers($serial_numbers) + { + $this->container['serial_numbers'] = $serial_numbers; + + return $this; + } +} + + diff --git a/lib/Model/OrdersV0/TaxCollection.php b/lib/Model/OrdersV0/TaxCollection.php new file mode 100644 index 000000000..ea7ffbf1a --- /dev/null +++ b/lib/Model/OrdersV0/TaxCollection.php @@ -0,0 +1,282 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class TaxCollection extends BaseModel implements ModelInterface, ArrayAccess, \JsonSerializable, \IteratorAggregate +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'TaxCollection'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'model' => 'string', + 'responsible_party' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'model' => null, + 'responsible_party' => null + ]; + + + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'model' => 'Model', + 'responsible_party' => 'ResponsibleParty' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'model' => 'setModel', + 'responsible_party' => 'setResponsibleParty' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'model' => 'getModel', + 'responsible_party' => 'getResponsibleParty' + ]; + + + + const MODEL_MARKETPLACE_FACILITATOR = 'MarketplaceFacilitator'; + const MODEL_LOW_VALUE_GOODS = 'LowValueGoods'; + + + const RESPONSIBLE_PARTY_SERVICES_INC = 'Amazon Services, Inc.'; + const RESPONSIBLE_PARTY_COMMERCIAL_SERVICES_PTY_LTD = 'Amazon Commercial Services Pty Ltd'; + + + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getModelAllowableValues() + { + $baseVals = [ + self::MODEL_MARKETPLACE_FACILITATOR, + self::MODEL_LOW_VALUE_GOODS, + ]; + + // This is necessary because Amazon does not consistently capitalize their + // enum values, so we do case-insensitive enum value validation in ObjectSerializer + return array_map(function ($val) { return strtoupper($val); }, $baseVals); + } + + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getResponsiblePartyAllowableValues() + { + $baseVals = [ + self::RESPONSIBLE_PARTY_SERVICES_INC, + self::RESPONSIBLE_PARTY_COMMERCIAL_SERVICES_PTY_LTD, + ]; + + // This is necessary because Amazon does not consistently capitalize their + // enum values, so we do case-insensitive enum value validation in ObjectSerializer + return array_map(function ($val) { return strtoupper($val); }, $baseVals); + } + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->container['model'] = $data['model'] ?? null; + $this->container['responsible_party'] = $data['responsible_party'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + $allowedValues = $this->getModelAllowableValues(); + if ( + !is_null($this->container['model']) && + !in_array(strtoupper($this->container['model']), $allowedValues, true) + ) { + $invalidProperties[] = sprintf( + "invalid value '%s' for 'model', must be one of '%s'", + $this->container['model'], + implode("', '", $allowedValues) + ); + } + + $allowedValues = $this->getResponsiblePartyAllowableValues(); + if ( + !is_null($this->container['responsible_party']) && + !in_array(strtoupper($this->container['responsible_party']), $allowedValues, true) + ) { + $invalidProperties[] = sprintf( + "invalid value '%s' for 'responsible_party', must be one of '%s'", + $this->container['responsible_party'], + implode("', '", $allowedValues) + ); + } + + return $invalidProperties; + } + + + /** + * Gets model + * + * @return string|null + */ + public function getModel() + { + return $this->container['model']; + } + + /** + * Sets model + * + * @param string|null $model The tax collection model applied to the item. + * + * @return self + */ + public function setModel($model) + { + $allowedValues = $this->getModelAllowableValues(); + if (!is_null($model) &&!in_array(strtoupper($model), $allowedValues, true)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value '%s' for 'model', must be one of '%s'", + $model, + implode("', '", $allowedValues) + ) + ); + } + $this->container['model'] = $model; + + return $this; + } + /** + * Gets responsible_party + * + * @return string|null + */ + public function getResponsibleParty() + { + return $this->container['responsible_party']; + } + + /** + * Sets responsible_party + * + * @param string|null $responsible_party The party responsible for withholding the taxes and remitting them to the taxing authority. + * + * @return self + */ + public function setResponsibleParty($responsible_party) + { + if (empty($responsible_party)) { + $responsible_party = null; + } + $allowedValues = $this->getResponsiblePartyAllowableValues(); + if (!is_null($responsible_party) &&!in_array(strtoupper($responsible_party), $allowedValues, true)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value '%s' for 'responsible_party', must be one of '%s'", + $responsible_party, + implode("', '", $allowedValues) + ) + ); + } + $this->container['responsible_party'] = $responsible_party; + + return $this; + } +} + +