-
Notifications
You must be signed in to change notification settings - Fork 52
/
SellingPartnerSDK.php
288 lines (245 loc) · 9.8 KB
/
SellingPartnerSDK.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
declare(strict_types=1);
namespace AmazonPHP\SellingPartner;
use AmazonPHP\SellingPartner\Api\AplusContentApi\APlusSDK;
use AmazonPHP\SellingPartner\Api\AplusContentApi\APlusSDKInterface;
use AmazonPHP\SellingPartner\Api\ApplicationsApi\ApplicationManagementSDK;
use AmazonPHP\SellingPartner\Api\ApplicationsApi\ApplicationManagementSDKInterface;
use AmazonPHP\SellingPartner\Api\AwdApi\WarehousingAndDistributionSDK;
use AmazonPHP\SellingPartner\Api\AwdApi\WarehousingAndDistributionSDKInterface;
use AmazonPHP\SellingPartner\Api\CatalogApi\CatalogItemSDK;
use AmazonPHP\SellingPartner\Api\CatalogApi\CatalogItemSDKInterface;
use AmazonPHP\SellingPartner\Api\DefaultApi\FinancesSDK;
use AmazonPHP\SellingPartner\Api\DefaultApi\FinancesSDKInterface;
use AmazonPHP\SellingPartner\Api\DefinitionsApi\ProductTypesDefinitionsSDK;
use AmazonPHP\SellingPartner\Api\DefinitionsApi\ProductTypesDefinitionsSDKInterface;
use AmazonPHP\SellingPartner\Api\FbaInboundApi\FBAInboundSDK;
use AmazonPHP\SellingPartner\Api\FbaInboundApi\FBAInboundSDKInterface;
use AmazonPHP\SellingPartner\Api\FbaInboundApi\FulfillmentInboundSDK;
use AmazonPHP\SellingPartner\Api\FbaInboundApi\FulfillmentInboundSDKInterface;
use AmazonPHP\SellingPartner\Api\FbaInboundApi\FulfillmentInboundV0SDK;
use AmazonPHP\SellingPartner\Api\FbaInboundApi\FulfillmentInboundV0SDKInterface;
use AmazonPHP\SellingPartner\Api\FbaInventoryApi\FBAInventorySDK;
use AmazonPHP\SellingPartner\Api\FbaInventoryApi\FBAInventorySDKInterface;
use AmazonPHP\SellingPartner\Api\FbaOutboundApi\FulfillmentOutboundSDK;
use AmazonPHP\SellingPartner\Api\FbaOutboundApi\FulfillmentOutboundSDKInterface;
use AmazonPHP\SellingPartner\Api\FeedsApi\FeedsSDK;
use AmazonPHP\SellingPartner\Api\FeedsApi\FeedsSDKInterface;
use AmazonPHP\SellingPartner\Api\FeesApi\ProductFeesSDK;
use AmazonPHP\SellingPartner\Api\FeesApi\ProductFeesSDKInterface;
use AmazonPHP\SellingPartner\Api\ListingsApi\ListingsItemsSDK;
use AmazonPHP\SellingPartner\Api\MerchantFulfillmentApi\MerchantFulfillmentSDK;
use AmazonPHP\SellingPartner\Api\MerchantFulfillmentApi\MerchantFulfillmentSDKInterface;
use AmazonPHP\SellingPartner\Api\MessagingApi\MessagingSDK;
use AmazonPHP\SellingPartner\Api\MessagingApi\MessagingSDKInterface;
use AmazonPHP\SellingPartner\Api\NotificationsApi\NotificationsSDK;
use AmazonPHP\SellingPartner\Api\NotificationsApi\NotificationsSDKInterface;
use AmazonPHP\SellingPartner\Api\OrdersV0Api;
use AmazonPHP\SellingPartner\Api\ProductPricingApi\ProductPricingSDK;
use AmazonPHP\SellingPartner\Api\ProductPricingApi\ProductPricingSDKInterface;
use AmazonPHP\SellingPartner\Api\ReportsApi\ReportsSDK;
use AmazonPHP\SellingPartner\Api\ReportsApi\ReportsSDKInterface;
use AmazonPHP\SellingPartner\Api\SalesApi\SalesSDK;
use AmazonPHP\SellingPartner\Api\SalesApi\SalesSDKInterface;
use AmazonPHP\SellingPartner\Api\SellersApi\SellersSDK;
use AmazonPHP\SellingPartner\Api\SellersApi\SellersSDKInterface;
use AmazonPHP\SellingPartner\Api\ServiceApi\ServicesSDK;
use AmazonPHP\SellingPartner\Api\ServiceApi\ServicesSDKInterface;
use AmazonPHP\SellingPartner\Api\ShipmentApi;
use AmazonPHP\SellingPartner\Api\ShipmentInvoiceApi\ShipmentInvoicingSDK;
use AmazonPHP\SellingPartner\Api\ShipmentInvoiceApi\ShipmentInvoicingSDKInterface;
use AmazonPHP\SellingPartner\Api\ShippingApi\ShippingSDK;
use AmazonPHP\SellingPartner\Api\ShippingApi\ShippingSDKInterface;
use AmazonPHP\SellingPartner\Api\SolicitationsApi\SolicitationsSDK;
use AmazonPHP\SellingPartner\Api\SolicitationsApi\SolicitationsSDKInterface;
use AmazonPHP\SellingPartner\Api\TokensApi\TokensSDK;
use AmazonPHP\SellingPartner\Api\TokensApi\TokensSDKInterface;
use AmazonPHP\SellingPartner\Api\UploadsApi\UploadsSDK;
use AmazonPHP\SellingPartner\Api\UploadsApi\UploadsSDKInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Log\LoggerInterface;
final class SellingPartnerSDK
{
/**
* @var array<class-string>
*/
private array $instances;
private readonly HttpFactory $httpFactory;
public function __construct(
private readonly ClientInterface $httpClient,
private readonly RequestFactoryInterface $requestFactory,
private readonly StreamFactoryInterface $streamFactory,
private readonly Configuration $configuration,
private readonly LoggerInterface $logger
) {
$this->instances = [];
$this->httpFactory = new HttpFactory($requestFactory, $streamFactory);
}
public static function create(
ClientInterface $httpClient,
RequestFactoryInterface $requestFactory,
StreamFactoryInterface $streamFactory,
Configuration $configuration,
LoggerInterface $logger
) : self {
return new self($httpClient, $requestFactory, $streamFactory, $configuration, $logger);
}
public function configuration() : Configuration
{
return $this->configuration;
}
public function oAuth() : OAuth
{
return $this->instantiateSDK(OAuth::class);
}
public function aPlus() : APlusSDKInterface
{
return $this->instantiateSDK(APlusSDK::class);
}
public function applicationManagement() : ApplicationManagementSDKInterface
{
return $this->instantiateSDK(ApplicationManagementSDK::class);
}
public function catalogItem() : CatalogItemSDKInterface
{
return $this->instantiateSDK(CatalogItemSDK::class);
}
public function fbaInbound() : FBAInboundSDKInterface
{
return $this->instantiateSDK(FBAInboundSDK::class);
}
public function fbaInventory() : FBAInventorySDKInterface
{
return $this->instantiateSDK(FBAInventorySDK::class);
}
public function feeds() : FeedsSDKInterface
{
return $this->instantiateSDK(FeedsSDK::class);
}
public function finances() : FinancesSDKInterface
{
return $this->instantiateSDK(FinancesSDK::class);
}
public function fulfillmentInboundV0() : FulfillmentInboundV0SDKInterface
{
return $this->instantiateSDK(FulfillmentInboundV0SDK::class);
}
public function fulfillmentInbound() : FulfillmentInboundSDKInterface
{
return $this->instantiateSDK(FulfillmentInboundSDK::class);
}
public function fulfillmentOutbound() : FulfillmentOutboundSDKInterface
{
return $this->instantiateSDK(FulfillmentOutboundSDK::class);
}
public function listingsItems() : ListingsItemsSDK
{
return $this->instantiateSDK(ListingsItemsSDK::class);
}
public function merchantFulfillment() : MerchantFulfillmentSDKInterface
{
return $this->instantiateSDK(MerchantFulfillmentSDK::class);
}
public function messaging() : MessagingSDKInterface
{
return $this->instantiateSDK(MessagingSDK::class);
}
public function notifications() : NotificationsSDKInterface
{
return $this->instantiateSDK(NotificationsSDK::class);
}
public function orders() : OrdersV0Api\OrdersSDKInterface
{
return $this->instantiateSDK(OrdersV0Api\OrdersSDK::class);
}
public function orderShipment() : ShipmentApi\OrdersSDKInterface
{
return $this->instantiateSDK(ShipmentApi\OrdersSDK::class);
}
public function productFees() : ProductFeesSDKInterface
{
return $this->instantiateSDK(ProductFeesSDK::class);
}
public function productPricing() : ProductPricingSDKInterface
{
return $this->instantiateSDK(ProductPricingSDK::class);
}
public function productTypesDefinitions() : ProductTypesDefinitionsSDKInterface
{
return $this->instantiateSDK(ProductTypesDefinitionsSDK::class);
}
public function reports() : ReportsSDKInterface
{
return $this->instantiateSDK(ReportsSDK::class);
}
public function sales() : SalesSDKInterface
{
return $this->instantiateSDK(SalesSDK::class);
}
public function sellers() : SellersSDKInterface
{
return $this->instantiateSDK(SellersSDK::class);
}
public function services() : ServicesSDKInterface
{
return $this->instantiateSDK(ServicesSDK::class);
}
public function shipmentInvoicing() : ShipmentInvoicingSDKInterface
{
return $this->instantiateSDK(ShipmentInvoicingSDK::class);
}
public function shipping() : ShippingSDKInterface
{
return $this->instantiateSDK(ShippingSDK::class);
}
public function solicitations() : SolicitationsSDKInterface
{
return $this->instantiateSDK(SolicitationsSDK::class);
}
public function tokens() : TokensSDKInterface
{
return $this->instantiateSDK(TokensSDK::class);
}
public function uploads() : UploadsSDKInterface
{
return $this->instantiateSDK(UploadsSDK::class);
}
public function warehousingDistribution() : WarehousingAndDistributionSDKInterface
{
return $this->instantiateSDK(WarehousingAndDistributionSDK::class);
}
public function vendor() : VendorSDK
{
return $this->instantiateSDK(VendorSDK::class);
}
/**
* @template T
*
* @param T $sdkClass
*
* @return T
*/
private function instantiateSDK(string $sdkClass) : string|object
{
if (isset($this->instances[$sdkClass])) {
return $this->instances[$sdkClass];
}
$this->instances[$sdkClass] = ($sdkClass === VendorSDK::class)
? VendorSDK::create(
$this->httpClient,
$this->requestFactory,
$this->streamFactory,
$this->configuration,
$this->logger
)
: new $sdkClass(
$this->httpClient,
$this->httpFactory,
$this->configuration,
$this->logger
);
return $this->instances[$sdkClass];
}
}