Skip to content

Commit d81b9b6

Browse files
authored
Issue cleanup and addition of Application Management API (#641)
Modify Vendor SDK to return VendorOrdersSDK for the ordersSDK() method. Add Application Management API SDK to library. Modify unit tests to account for changes.
1 parent d274e25 commit d81b9b6

File tree

69 files changed

+920
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+920
-87
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ This library is not in a stable stage yet, please use with caution.
6262
| [3.x](https://github.com/amazon-php/sp-api-sdk/tree/3.x) | 🚫 |
6363
| [4.x](https://github.com/amazon-php/sp-api-sdk/tree/4.x) | 🚫 |
6464
| [5.x](https://github.com/amazon-php/sp-api-sdk/tree/5.x) ||
65-
| [6.x](https://github.com/amazon-php/sp-api-sdk/tree/5.x) ||
65+
| [6.x](https://github.com/amazon-php/sp-api-sdk/tree/6.x) ||
6666

6767
Version <s> [1.x](https://github.com/amazon-php/sp-api-sdk/tree/1.x) </s> is deprecated becuase of the attempt to
6868
make a little more sense of what Amazon is doing with using "tags" in their Open API specification.
@@ -92,6 +92,7 @@ Some minor adjustments were made in the template files for models/api.
9292
- Additions
9393
- Fulfillment Inbound API v2024-03-20
9494
- Amazon Warehousing and Distribution API v2024-05-09
95+
- Application Management API v2023-11-30
9596
- Removals
9697
- Fulfillment Inbound API v0
9798
- Authorization API
@@ -103,6 +104,7 @@ Some minor adjustments were made in the template files for models/api.
103104
[SellingPartnerSDK](/src/AmazonPHP/SellingPartner/SellingPartnerSDK.php) - Facade for all SDK's
104105

105106
- [APlusSDK](/src/AmazonPHP/SellingPartner/Api/AplusContentApi/APlusSDK.php)
107+
- [ApplicationManagement](/src/AmazonPHP/SellingPartner/Api/ApplicationsApi/ApplicationManagementSDK.php)
106108
- [CatalogItemSDK](/src/AmazonPHP/SellingPartner/Api/CatalogApi/CatalogItemSDK.php)
107109
- [FBAInboundSDK](/src/AmazonPHP/SellingPartner/Api/FbaInboundApi/FBAInboundSDK.php)
108110
- [FBAInventorySDK](/src/AmazonPHP/SellingPartner/Api/FbaInventoryApi/FBAInventorySDK.php)

bin/generate.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,11 @@ docker run --user "$(id -u)":"$(id -g)" --rm -v "${PWD}:/sp-api" openapitools/op
286286
--language-specific-primitives \\DateTimeInterface \
287287
--type-mappings date=\\DateTimeInterface,Date=\\DateTimeInterface,DateTime=\\DateTimeInterface
288288

289+
docker run --user "$(id -u)":"$(id -g)" --rm -v "${PWD}:/sp-api" openapitools/openapi-generator-cli generate \
290+
-i https://raw.githubusercontent.com/amzn/selling-partner-api-models/main/models/application-management-api-model/application_2023-11-30.json \
291+
-c /sp-api/config/generator-application-management.yaml \
292+
--global-property models,apis,apiDocs=false,modelDocs=false,modelTests=false,apiTests=false,supportingFiles=false \
293+
-o /sp-api \
294+
--language-specific-primitives \\DateTimeInterface \
295+
--type-mappings date=\\DateTimeInterface,Date=\\DateTimeInterface,DateTime=\\DateTimeInterface
296+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
generatorName: php
2+
templateDir: sp-api/resources/php-amazon-selling-partner-api
3+
additionalProperties:
4+
invokerPackage: AmazonPHP\SellingPartner
5+
srcBasePath: src/AmazonPHP/SellingPartner
6+
modelPackage: Model\ApplicationManagement
7+
packageName: ApplicationManagement
8+
files:
9+
api.mustache:
10+
templateType: API
11+
destinationFilename: /ApplicationManagementSDK.php
12+
api_interface.mustache:
13+
templateType: API
14+
destinationFilename: /ApplicationManagementSDKInterface.php
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AmazonPHP\SellingPartner\Api\ApplicationsApi;
6+
7+
use AmazonPHP\SellingPartner\AccessToken;
8+
use AmazonPHP\SellingPartner\Configuration;
9+
use AmazonPHP\SellingPartner\Exception\ApiException;
10+
use AmazonPHP\SellingPartner\Exception\InvalidArgumentException;
11+
use AmazonPHP\SellingPartner\HttpFactory;
12+
use AmazonPHP\SellingPartner\HttpSignatureHeaders;
13+
use Psr\Http\Client\ClientExceptionInterface;
14+
use Psr\Http\Client\ClientInterface;
15+
use Psr\Http\Message\RequestInterface;
16+
use Psr\Log\LoggerInterface;
17+
18+
/**
19+
* Selling Partner API for Application Management.
20+
*
21+
* The Selling Partner API for Application Management lets you programmatically update the client secret on registered applications.
22+
*
23+
* The version of the OpenAPI document: 2023-11-30
24+
*
25+
* This class was auto-generated by https://openapi-generator.tech
26+
* Do not change it, it will be overwritten with next execution of /bin/generate.sh
27+
*/
28+
final class ApplicationManagementSDK implements ApplicationManagementSDKInterface
29+
{
30+
public function __construct(private readonly ClientInterface $client, private readonly HttpFactory $httpFactory, private readonly Configuration $configuration, private readonly LoggerInterface $logger)
31+
{
32+
}
33+
34+
/**
35+
* Operation rotateApplicationClientSecret.
36+
*
37+
* @throws ApiException on non-2xx response
38+
* @throws InvalidArgumentException
39+
*/
40+
public function rotateApplicationClientSecret(AccessToken $accessToken, string $region)
41+
{
42+
$request = $this->rotateApplicationClientSecretRequest($accessToken, $region);
43+
44+
$this->configuration->extensions()->preRequest('ApplicationManagement', 'rotateApplicationClientSecret', $request);
45+
46+
try {
47+
$correlationId = $this->configuration->idGenerator()->generate();
48+
$sanitizedRequest = $request;
49+
50+
foreach ($this->configuration->loggingSkipHeaders() as $sensitiveHeader) {
51+
$sanitizedRequest = $sanitizedRequest->withoutHeader($sensitiveHeader);
52+
}
53+
54+
if ($this->configuration->loggingEnabled('ApplicationManagement', 'rotateApplicationClientSecret')) {
55+
$this->logger->log(
56+
$this->configuration->logLevel('ApplicationManagement', 'rotateApplicationClientSecret'),
57+
'Amazon Selling Partner API pre request',
58+
[
59+
'api' => 'ApplicationManagement',
60+
'operation' => 'rotateApplicationClientSecret',
61+
'request_correlation_id' => $correlationId,
62+
'request_body' => (string) $sanitizedRequest->getBody(),
63+
'request_headers' => $sanitizedRequest->getHeaders(),
64+
'request_uri' => (string) $sanitizedRequest->getUri(),
65+
]
66+
);
67+
}
68+
69+
$response = $this->client->sendRequest($request);
70+
71+
$this->configuration->extensions()->postRequest('ApplicationManagement', 'rotateApplicationClientSecret', $request, $response);
72+
73+
if ($this->configuration->loggingEnabled('ApplicationManagement', 'rotateApplicationClientSecret')) {
74+
$sanitizedResponse = $response;
75+
76+
foreach ($this->configuration->loggingSkipHeaders() as $sensitiveHeader) {
77+
$sanitizedResponse = $sanitizedResponse->withoutHeader($sensitiveHeader);
78+
}
79+
80+
$this->logger->log(
81+
$this->configuration->logLevel('ApplicationManagement', 'rotateApplicationClientSecret'),
82+
'Amazon Selling Partner API post request',
83+
[
84+
'api' => 'ApplicationManagement',
85+
'operation' => 'rotateApplicationClientSecret',
86+
'response_correlation_id' => $correlationId,
87+
'response_body' => (string) $sanitizedResponse->getBody(),
88+
'response_headers' => $sanitizedResponse->getHeaders(),
89+
'response_status_code' => $sanitizedResponse->getStatusCode(),
90+
'request_uri' => (string) $sanitizedRequest->getUri(),
91+
'request_body' => (string) $sanitizedRequest->getBody(),
92+
]
93+
);
94+
}
95+
} catch (ClientExceptionInterface $e) {
96+
throw new ApiException(
97+
"[{$e->getCode()}] {$e->getMessage()}",
98+
(int) $e->getCode(),
99+
null,
100+
null,
101+
$e
102+
);
103+
}
104+
105+
$statusCode = $response->getStatusCode();
106+
107+
if ($statusCode < 200 || $statusCode > 299) {
108+
throw new ApiException(
109+
\sprintf(
110+
'[%d] Error connecting to the API (%s)',
111+
$statusCode,
112+
(string) $request->getUri()
113+
),
114+
$statusCode,
115+
$response->getHeaders(),
116+
(string) $response->getBody()
117+
);
118+
}
119+
120+
return null;
121+
}
122+
123+
/**
124+
* Create request for operation 'rotateApplicationClientSecret'.
125+
*
126+
* @throws \AmazonPHP\SellingPartner\Exception\InvalidArgumentException
127+
*/
128+
public function rotateApplicationClientSecretRequest(AccessToken $accessToken, string $region) : RequestInterface
129+
{
130+
$resourcePath = '/applications/2023-11-30/clientSecret';
131+
$formParams = [];
132+
$queryParams = [];
133+
$headerParams = [];
134+
$multipart = false;
135+
$query = '';
136+
137+
if (\count($queryParams)) {
138+
$query = \http_build_query($queryParams);
139+
}
140+
141+
if ($multipart) {
142+
$headers = [
143+
'accept' => ['application/json'],
144+
'host' => [$this->configuration->apiHost($region)],
145+
'user-agent' => [$this->configuration->userAgent()],
146+
];
147+
} else {
148+
$headers = [
149+
'content-type' => ['application/json'],
150+
'accept' => ['application/json'],
151+
'host' => [$this->configuration->apiHost($region)],
152+
'user-agent' => [$this->configuration->userAgent()],
153+
];
154+
}
155+
156+
$request = $this->httpFactory->createRequest(
157+
'POST',
158+
$this->configuration->apiURL($region) . $resourcePath . '?' . $query
159+
);
160+
161+
// for model (json/xml)
162+
if (\count($formParams) > 0) {
163+
if ($multipart) {
164+
$multipartContents = [];
165+
166+
foreach ($formParams as $formParamName => $formParamValue) {
167+
$formParamValueItems = \is_array($formParamValue) ? $formParamValue : [$formParamValue];
168+
169+
foreach ($formParamValueItems as $formParamValueItem) {
170+
$multipartContents[] = [
171+
'name' => $formParamName,
172+
'contents' => $formParamValueItem,
173+
];
174+
}
175+
}
176+
$request = $request->withParsedBody($multipartContents);
177+
} elseif ($headers['content-type'] === ['application/json']) {
178+
$request = $request->withBody($this->httpFactory->createStreamFromString(\json_encode($formParams, JSON_THROW_ON_ERROR)));
179+
} else {
180+
$request = $request->withParsedBody($formParams);
181+
}
182+
}
183+
184+
foreach (\array_merge($headerParams, $headers) as $name => $header) {
185+
$request = $request->withHeader($name, $header);
186+
}
187+
188+
return HttpSignatureHeaders::forConfig(
189+
$this->configuration,
190+
$accessToken,
191+
$region,
192+
$request
193+
);
194+
}
195+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace AmazonPHP\SellingPartner\Api\ApplicationsApi;
4+
5+
use AmazonPHP\SellingPartner\AccessToken;
6+
use AmazonPHP\SellingPartner\Exception\ApiException;
7+
use AmazonPHP\SellingPartner\Exception\InvalidArgumentException;
8+
9+
/**
10+
* Selling Partner API for Application Management.
11+
*
12+
* The Selling Partner API for Application Management lets you programmatically update the client secret on registered applications.
13+
*
14+
* The version of the OpenAPI document: 2023-11-30
15+
*
16+
* This class was auto-generated by https://openapi-generator.tech
17+
* Do not change it, it will be overwritten with next execution of /bin/generate.sh
18+
*/
19+
interface ApplicationManagementSDKInterface
20+
{
21+
public const API_NAME = 'ApplicationManagement';
22+
23+
public const OPERATION_ROTATEAPPLICATIONCLIENTSECRET = 'rotateApplicationClientSecret';
24+
25+
public const OPERATION_ROTATEAPPLICATIONCLIENTSECRET_PATH = '/applications/2023-11-30/clientSecret';
26+
27+
/**
28+
* Operation rotateApplicationClientSecret.
29+
*
30+
* @throws ApiException on non-2xx response
31+
* @throws InvalidArgumentException
32+
*/
33+
public function rotateApplicationClientSecret(AccessToken $accessToken, string $region);
34+
}

src/AmazonPHP/SellingPartner/Api/MerchantFulfillmentApi/MerchantFulfillmentSDK.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* Selling Partner API for Merchant Fulfillment.
2121
*
22-
* With the Selling Partner API for Merchant Fulfillment, you can build applications that sellers can use to purchase shipping for non-Prime and Prime orders using Amazon's Buy Shipping Services.
22+
* The Selling Partner API for Merchant Fulfillment helps you build applications that let sellers purchase shipping for non-Prime and Prime orders using Amazons Buy Shipping Services.
2323
*
2424
* The version of the OpenAPI document: v0
2525
*
@@ -226,7 +226,7 @@ public function cancelShipmentRequest(AccessToken $accessToken, string $region,
226226
/**
227227
* Operation createShipment.
228228
*
229-
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\CreateShipmentRequest $body Request schema for &#x60;CreateShipment&#x60; operation. (required)
229+
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\CreateShipmentRequest $body Request schema for CreateShipment operation. (required)
230230
*
231231
* @throws ApiException on non-2xx response
232232
* @throws InvalidArgumentException
@@ -322,7 +322,7 @@ public function createShipment(AccessToken $accessToken, string $region, \Amazon
322322
/**
323323
* Create request for operation 'createShipment'.
324324
*
325-
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\CreateShipmentRequest $body Request schema for &#x60;CreateShipment&#x60; operation. (required)
325+
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\CreateShipmentRequest $body Request schema for CreateShipment operation. (required)
326326
*
327327
* @throws \AmazonPHP\SellingPartner\Exception\InvalidArgumentException
328328
*/
@@ -412,7 +412,7 @@ public function createShipmentRequest(AccessToken $accessToken, string $region,
412412
/**
413413
* Operation getAdditionalSellerInputs.
414414
*
415-
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\GetAdditionalSellerInputsRequest $body Request schema for the &#x60;GetAdditionalSellerInputs&#x60; operation. (required)
415+
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\GetAdditionalSellerInputsRequest $body Request schema for GetAdditionalSellerInputs operation. (required)
416416
*
417417
* @throws ApiException on non-2xx response
418418
* @throws InvalidArgumentException
@@ -508,7 +508,7 @@ public function getAdditionalSellerInputs(AccessToken $accessToken, string $regi
508508
/**
509509
* Create request for operation 'getAdditionalSellerInputs'.
510510
*
511-
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\GetAdditionalSellerInputsRequest $body Request schema for the &#x60;GetAdditionalSellerInputs&#x60; operation. (required)
511+
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\GetAdditionalSellerInputsRequest $body Request schema for GetAdditionalSellerInputs operation. (required)
512512
*
513513
* @throws \AmazonPHP\SellingPartner\Exception\InvalidArgumentException
514514
*/

src/AmazonPHP/SellingPartner/Api/MerchantFulfillmentApi/MerchantFulfillmentSDKInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Selling Partner API for Merchant Fulfillment.
1111
*
12-
* With the Selling Partner API for Merchant Fulfillment, you can build applications that sellers can use to purchase shipping for non-Prime and Prime orders using Amazon's Buy Shipping Services.
12+
* The Selling Partner API for Merchant Fulfillment helps you build applications that let sellers purchase shipping for non-Prime and Prime orders using Amazons Buy Shipping Services.
1313
*
1414
* The version of the OpenAPI document: v0
1515
*
@@ -53,7 +53,7 @@ public function cancelShipment(AccessToken $accessToken, string $region, string
5353
/**
5454
* Operation createShipment.
5555
*
56-
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\CreateShipmentRequest $body Request schema for &#x60;CreateShipment&#x60; operation. (required)
56+
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\CreateShipmentRequest $body Request schema for CreateShipment operation. (required)
5757
*
5858
* @throws ApiException on non-2xx response
5959
* @throws InvalidArgumentException
@@ -63,7 +63,7 @@ public function createShipment(AccessToken $accessToken, string $region, \Amazon
6363
/**
6464
* Operation getAdditionalSellerInputs.
6565
*
66-
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\GetAdditionalSellerInputsRequest $body Request schema for the &#x60;GetAdditionalSellerInputs&#x60; operation. (required)
66+
* @param \AmazonPHP\SellingPartner\Model\MerchantFulfillment\GetAdditionalSellerInputsRequest $body Request schema for GetAdditionalSellerInputs operation. (required)
6767
*
6868
* @throws ApiException on non-2xx response
6969
* @throws InvalidArgumentException

0 commit comments

Comments
 (0)