PageRenderTime 83ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/src/MarketplaceWebService/Client.php

https://github.com/softwarevamp/amazon-mws
PHP | 1928 lines | 1492 code | 175 blank | 261 comment | 156 complexity | 60fb9a2adaf6d79f5ed5aada70d49551 MD5 | raw file
Possible License(s): GPL-3.0, Apache-2.0
  1. <?php
  2. /**
  3. * PHP Version 5
  4. *
  5. * @category Amazon
  6. * @package MarketplaceWebService
  7. * @copyright Copyright 2009 Amazon Technologies, Inc.
  8. * @link http://aws.amazon.com
  9. * @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
  10. * @version 2009-01-01
  11. */
  12. /*******************************************************************************
  13. *
  14. * Marketplace Web Service PHP5 Library
  15. * Generated: Thu May 07 13:07:36 PDT 2009
  16. *
  17. */
  18. /**
  19. * @see MarketplaceWebService_Interface
  20. */
  21. // require_once ('MarketplaceWebService/Interface.php');
  22. // require_once ('RequestType.php');
  23. define('CONVERTED_PARAMETERS_KEY', 'PARAMETERS');
  24. define('CONVERTED_HEADERS_KEY', 'HEADERS');
  25. /**
  26. * The Amazon Marketplace Web Service contain APIs for inventory and order management.
  27. *
  28. * MarketplaceWebService_Client is an implementation of MarketplaceWebService
  29. *
  30. */
  31. class MarketplaceWebService_Client implements MarketplaceWebService_Interface
  32. {
  33. /** @var string */
  34. private $awsAccessKeyId = null;
  35. /** @var string */
  36. private $awsSecretAccessKey = null;
  37. /** @var array */
  38. private $config = array ('ServiceURL' => null,
  39. 'UserAgent' => 'PHP Client Library/2011-08-01 (Language=PHP5)',
  40. 'SignatureVersion' => 2,
  41. 'SignatureMethod' => 'HmacSHA256',
  42. 'ProxyHost' => null,
  43. 'ProxyPort' => -1,
  44. 'MaxErrorRetry' => 3,
  45. );
  46. const SERVICE_VERSION = '2009-01-01';
  47. const REQUEST_TYPE = "POST";
  48. const MWS_CLIENT_VERSION = '2011-08-01';
  49. private $defaultHeaders = array();
  50. private $responseBodyContents;
  51. // "streaming" responses that are errors will be send to this handle;
  52. private $errorResponseBody;
  53. private $headerContents;
  54. private $curlClient;
  55. /**
  56. * Construct new Client
  57. *
  58. * @param string $awsAccessKeyId AWS Access Key ID
  59. * @param string $awsSecretAccessKey AWS Secret Access Key
  60. * @param array $config configuration options.
  61. * @param string $applicationName application name.
  62. * @param string $applicationVersion application version.
  63. * @param array $attributes user-agent attributes
  64. * @return unknown_type
  65. * Valid configuration options are:
  66. * <ul>
  67. * <li>ServiceURL</li>
  68. * <li>SignatureVersion</li>
  69. * <li>TimesRetryOnError</li>
  70. * <li>ProxyHost</li>
  71. * <li>ProxyPort</li>
  72. * <li>MaxErrorRetry</li>
  73. * </ul>
  74. */
  75. public function __construct(
  76. $awsAccessKeyId, $awsSecretAccessKey, $config, $applicationName, $applicationVersion, $attributes = null) {
  77. iconv_set_encoding('output_encoding', 'UTF-8');
  78. iconv_set_encoding('input_encoding', 'UTF-8');
  79. iconv_set_encoding('internal_encoding', 'UTF-8');
  80. $this->awsAccessKeyId = $awsAccessKeyId;
  81. $this->awsSecretAccessKey = $awsSecretAccessKey;
  82. if (!is_null($config))
  83. $this->config = array_merge($this->config, $config);
  84. $this->setUserAgentHeader($applicationName, $applicationVersion, $attributes);
  85. }
  86. /**
  87. * Sets a MWS compliant HTTP User-Agent Header value.
  88. * $attributeNameValuePairs is an associative array.
  89. *
  90. * @param $applicationName
  91. * @param $applicationVersion
  92. * @param $attributes
  93. * @return unknown_type
  94. */
  95. public function setUserAgentHeader(
  96. $applicationName,
  97. $applicationVersion,
  98. $attributes = null) {
  99. if (is_null($attributes)) {
  100. $attributes = array ();
  101. }
  102. $this->config['UserAgent'] =
  103. $this->constructUserAgentHeader($applicationName, $applicationVersion, $attributes);
  104. }
  105. /**
  106. * Construct a valid MWS compliant HTTP User-Agent Header. From the MWS Developer's Guide, this
  107. * entails:
  108. * "To meet the requirements, begin with the name of your application, followed by a forward
  109. * slash, followed by the version of the application, followed by a space, an opening
  110. * parenthesis, the Language name value pair, and a closing paranthesis. The Language parameter
  111. * is a required attribute, but you can add additional attributes separated by semi-colons."
  112. *
  113. * @param $applicationName
  114. * @param $applicationVersion
  115. * @param $additionalNameValuePairs
  116. * @return unknown_type
  117. */
  118. private function constructUserAgentHeader($applicationName, $applicationVersion, $attributes = null) {
  119. if (is_null($applicationName) || $applicationName === "") {
  120. throw new InvalidArgumentException('$applicationName cannot be null.');
  121. }
  122. if (is_null($applicationVersion) || $applicationVersion === "") {
  123. throw new InvalidArgumentException('$applicationVersion cannot be null.');
  124. }
  125. $userAgent =
  126. $this->quoteApplicationName($applicationName)
  127. . '/'
  128. . $this->quoteApplicationVersion($applicationVersion);
  129. $userAgent .= ' (';
  130. $userAgent .= 'Language=PHP/' . phpversion();
  131. $userAgent .= '; ';
  132. $userAgent .= 'Platform=' . php_uname('s') . '/' . php_uname('m') . '/' . php_uname('r');
  133. $userAgent .= '; ';
  134. $userAgent .= 'MWSClientVersion=' . self::MWS_CLIENT_VERSION;
  135. foreach ($attributes as $key => $value) {
  136. if (is_null($value) || $value === '') {
  137. throw new InvalidArgumentException("Value for $key cannot be null or empty.");
  138. }
  139. $userAgent .= '; '
  140. . $this->quoteAttributeName($key)
  141. . '='
  142. . $this->quoteAttributeValue($value);
  143. }
  144. $userAgent .= ')';
  145. return $userAgent;
  146. }
  147. /**
  148. * Collapse multiple whitespace characters into a single ' ' character.
  149. * @param $s
  150. * @return string
  151. */
  152. private function collapseWhitespace($s) {
  153. return preg_replace('/ {2,}|\s/', ' ', $s);
  154. }
  155. /**
  156. * Collapse multiple whitespace characters into a single ' ' and backslash escape '\',
  157. * and '/' characters from a string.
  158. * @param $s
  159. * @return string
  160. */
  161. private function quoteApplicationName($s) {
  162. $quotedString = $this->collapseWhitespace($s);
  163. $quotedString = preg_replace('/\\\\/', '\\\\\\\\', $quotedString);
  164. $quotedString = preg_replace('/\//', '\\/', $quotedString);
  165. return $quotedString;
  166. }
  167. /**
  168. * Collapse multiple whitespace characters into a single ' ' and backslash escape '\',
  169. * and '(' characters from a string.
  170. *
  171. * @param $s
  172. * @return string
  173. */
  174. private function quoteApplicationVersion($s) {
  175. $quotedString = $this->collapseWhitespace($s);
  176. $quotedString = preg_replace('/\\\\/', '\\\\\\\\', $quotedString);
  177. $quotedString = preg_replace('/\\(/', '\\(', $quotedString);
  178. return $quotedString;
  179. }
  180. /**
  181. * Collapse multiple whitespace characters into a single ' ' and backslash escape '\',
  182. * and '=' characters from a string.
  183. *
  184. * @param $s
  185. * @return unknown_type
  186. */
  187. private function quoteAttributeName($s) {
  188. $quotedString = $this->collapseWhitespace($s);
  189. $quotedString = preg_replace('/\\\\/', '\\\\\\\\', $quotedString);
  190. $quotedString = preg_replace('/\\=/', '\\=', $quotedString);
  191. return $quotedString;
  192. }
  193. /**
  194. * Collapse multiple whitespace characters into a single ' ' and backslash escape ';', '\',
  195. * and ')' characters from a string.
  196. *
  197. * @param $s
  198. * @return unknown_type
  199. */
  200. private function quoteAttributeValue($s) {
  201. $quotedString = $this->collapseWhitespace($s);
  202. $quotedString = preg_replace('/\\\\/', '\\\\\\\\', $quotedString);
  203. $quotedString = preg_replace('/\\;/', '\\;', $quotedString);
  204. $quotedString = preg_replace('/\\)/', '\\)', $quotedString);
  205. return $quotedString;
  206. }
  207. // Public API ------------------------------------------------------------//
  208. /**
  209. * Get Report
  210. * The GetReport operation returns the contents of a report. Reports can potentially be
  211. * very large (>100MB) which is why we only return one report at a time, and in a
  212. * streaming fashion.
  213. *
  214. * @see http://docs.amazonwebservices.com/${docPath}GetReport.html
  215. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportRequest request
  216. * or MarketplaceWebService_Model_GetReportRequest object itself
  217. * @see MarketplaceWebService_Model_GetReport
  218. * @return MarketplaceWebService_Model_GetReportResponse MarketplaceWebService_Model_GetReportResponse
  219. *
  220. * @throws MarketplaceWebService_Exception
  221. */
  222. public function getReport($request)
  223. {
  224. if (!$request instanceof MarketplaceWebService_Model_GetReportRequest) {
  225. // require_once ('MarketplaceWebService/Model/GetReportRequest.php');
  226. $request = new MarketplaceWebService_Model_GetReportRequest($request);
  227. }
  228. // require_once ('MarketplaceWebService/Model/GetReportResponse.php');
  229. $httpResponse = $this->invoke($this->convertGetReport($request), $request->getReport());
  230. $response = MarketplaceWebService_Model_GetReportResponse::fromXML($httpResponse['ResponseBody']);
  231. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  232. return $response;
  233. }
  234. /**
  235. * Get Report Schedule Count
  236. * returns the number of report schedules
  237. *
  238. * @see http://docs.amazonwebservices.com/${docPath}GetReportScheduleCount.html
  239. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportScheduleCountRequest request
  240. * or MarketplaceWebService_Model_GetReportScheduleCountRequest object itself
  241. * @see MarketplaceWebService_Model_GetReportScheduleCount
  242. * @return MarketplaceWebService_Model_GetReportScheduleCountResponse MarketplaceWebService_Model_GetReportScheduleCountResponse
  243. *
  244. * @throws MarketplaceWebService_Exception
  245. */
  246. public function getReportScheduleCount($request)
  247. {
  248. if (!$request instanceof MarketplaceWebService_Model_GetReportScheduleCountRequest) {
  249. // require_once ('MarketplaceWebService/Model/GetReportScheduleCountRequest.php');
  250. $request = new MarketplaceWebService_Model_GetReportScheduleCountRequest($request);
  251. }
  252. // require_once ('MarketplaceWebService/Model/GetReportScheduleCountResponse.php');
  253. $httpResponse = $this->invoke($this->convertGetReportScheduleCount($request));
  254. $response = MarketplaceWebService_Model_GetReportScheduleCountResponse::fromXML($httpResponse['ResponseBody']);
  255. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  256. return $response;
  257. }
  258. /**
  259. * Get Report Request List By Next Token
  260. * retrieve the next batch of list items and if there are more items to retrieve
  261. *
  262. * @see http://docs.amazonwebservices.com/${docPath}GetReportRequestListByNextToken.html
  263. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportRequestListByNextTokenRequest request
  264. * or MarketplaceWebService_Model_GetReportRequestListByNextTokenRequest object itself
  265. * @see MarketplaceWebService_Model_GetReportRequestListByNextToken
  266. * @return MarketplaceWebService_Model_GetReportRequestListByNextTokenResponse MarketplaceWebService_Model_GetReportRequestListByNextTokenResponse
  267. *
  268. * @throws MarketplaceWebService_Exception
  269. */
  270. public function getReportRequestListByNextToken($request)
  271. {
  272. if (!$request instanceof MarketplaceWebService_Model_GetReportRequestListByNextTokenRequest) {
  273. // require_once ('MarketplaceWebService/Model/GetReportRequestListByNextTokenRequest.php');
  274. $request = new MarketplaceWebService_Model_GetReportRequestListByNextTokenRequest($request);
  275. }
  276. // require_once ('MarketplaceWebService/Model/GetReportRequestListByNextTokenResponse.php');
  277. $httpResponse = $this->invoke($this->convertGetReportRequestListByNextToken($request));
  278. $response = MarketplaceWebService_Model_GetReportRequestListByNextTokenResponse::fromXML($httpResponse['ResponseBody']);
  279. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  280. return $response;
  281. }
  282. /**
  283. * Update Report Acknowledgements
  284. * The UpdateReportAcknowledgements operation updates the acknowledged status of one or more reports.
  285. *
  286. * @see http://docs.amazonwebservices.com/${docPath}UpdateReportAcknowledgements.html
  287. * @param mixed $request array of parameters for MarketplaceWebService_Model_UpdateReportAcknowledgementsRequest request
  288. * or MarketplaceWebService_Model_UpdateReportAcknowledgementsRequest object itself
  289. * @see MarketplaceWebService_Model_UpdateReportAcknowledgements
  290. * @return MarketplaceWebService_Model_UpdateReportAcknowledgementsResponse MarketplaceWebService_Model_UpdateReportAcknowledgementsResponse
  291. *
  292. * @throws MarketplaceWebService_Exception
  293. */
  294. public function updateReportAcknowledgements($request)
  295. {
  296. if (!$request instanceof MarketplaceWebService_Model_UpdateReportAcknowledgementsRequest) {
  297. // require_once ('MarketplaceWebService/Model/UpdateReportAcknowledgementsRequest.php');
  298. $request = new MarketplaceWebService_Model_UpdateReportAcknowledgementsRequest($request);
  299. }
  300. // require_once ('MarketplaceWebService/Model/UpdateReportAcknowledgementsResponse.php');
  301. $httpResponse = $this->invoke($this->convertUpdateReportAcknowledgements($request));
  302. $response = MarketplaceWebService_Model_UpdateReportAcknowledgementsResponse::fromXML($httpResponse['ResponseBody']);
  303. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  304. return $response;
  305. }
  306. /**
  307. * Submit Feed
  308. * Uploads a file for processing together with the necessary
  309. * metadata to process the file, such as which type of feed it is.
  310. * PurgeAndReplace if true means that your existing e.g. inventory is
  311. * wiped out and replace with the contents of this feed - use with
  312. * caution (the default is false).
  313. *
  314. * @see http://docs.amazonwebservices.com/${docPath}SubmitFeed.html
  315. * @param mixed $request array of parameters for MarketplaceWebService_Model_SubmitFeedRequest request
  316. * or MarketplaceWebService_Model_SubmitFeedRequest object itself
  317. * @see MarketplaceWebService_Model_SubmitFeed
  318. * @return MarketplaceWebService_Model_SubmitFeedResponse MarketplaceWebService_Model_SubmitFeedResponse
  319. *
  320. * @throws MarketplaceWebService_Exception
  321. */
  322. public function submitFeed($request)
  323. {
  324. if (!$request instanceof MarketplaceWebService_Model_SubmitFeedRequest) {
  325. // require_once ('MarketplaceWebService/Model/SubmitFeedRequest.php');
  326. $request = new MarketplaceWebService_Model_SubmitFeedRequest($request);
  327. }
  328. // require_once ('MarketplaceWebService/Model/SubmitFeedResponse.php');
  329. $httpResponse = $this->invoke($this->convertSubmitFeed($request), $request->getFeedContent(), $request->getContentMd5());
  330. $response = MarketplaceWebService_Model_SubmitFeedResponse::fromXML($httpResponse['ResponseBody']);
  331. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  332. return $response;
  333. }
  334. /**
  335. * Get Report Count
  336. * returns a count of reports matching your criteria;
  337. * by default, the number of reports generated in the last 90 days,
  338. * regardless of acknowledgement status
  339. *
  340. * @see http://docs.amazonwebservices.com/${docPath}GetReportCount.html
  341. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportCountRequest request
  342. * or MarketplaceWebService_Model_GetReportCountRequest object itself
  343. * @see MarketplaceWebService_Model_GetReportCount
  344. * @return MarketplaceWebService_Model_GetReportCountResponse MarketplaceWebService_Model_GetReportCountResponse
  345. *
  346. * @throws MarketplaceWebService_Exception
  347. */
  348. public function getReportCount($request)
  349. {
  350. if (!$request instanceof MarketplaceWebService_Model_GetReportCountRequest) {
  351. // require_once ('MarketplaceWebService/Model/GetReportCountRequest.php');
  352. $request = new MarketplaceWebService_Model_GetReportCountRequest($request);
  353. }
  354. // require_once ('MarketplaceWebService/Model/GetReportCountResponse.php');
  355. $httpResponse = $this->invoke($this->convertGetReportCount($request));
  356. $response = MarketplaceWebService_Model_GetReportCountResponse::fromXML($httpResponse['ResponseBody']);
  357. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  358. return $response;
  359. }
  360. /**
  361. * Get Feed Submission List By Next Token
  362. * retrieve the next batch of list items and if there are more items to retrieve
  363. *
  364. * @see http://docs.amazonwebservices.com/${docPath}GetFeedSubmissionListByNextToken.html
  365. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetFeedSubmissionListByNextTokenRequest request
  366. * or MarketplaceWebService_Model_GetFeedSubmissionListByNextTokenRequest object itself
  367. * @see MarketplaceWebService_Model_GetFeedSubmissionListByNextToken
  368. * @return MarketplaceWebService_Model_GetFeedSubmissionListByNextTokenResponse MarketplaceWebService_Model_GetFeedSubmissionListByNextTokenResponse
  369. *
  370. * @throws MarketplaceWebService_Exception
  371. */
  372. public function getFeedSubmissionListByNextToken($request)
  373. {
  374. if (!$request instanceof MarketplaceWebService_Model_GetFeedSubmissionListByNextTokenRequest) {
  375. // require_once ('MarketplaceWebService/Model/GetFeedSubmissionListByNextTokenRequest.php');
  376. $request = new MarketplaceWebService_Model_GetFeedSubmissionListByNextTokenRequest($request);
  377. }
  378. // require_once ('MarketplaceWebService/Model/GetFeedSubmissionListByNextTokenResponse.php');
  379. $httpResponse = $this->invoke($this->convertGetFeedSubmissionListByNextToken($request));
  380. $response = MarketplaceWebService_Model_GetFeedSubmissionListByNextTokenResponse::fromXML($httpResponse['ResponseBody']);
  381. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  382. return $response;
  383. }
  384. /**
  385. * Cancel Feed Submissions
  386. * cancels feed submissions - by default all of the submissions of the
  387. * last 30 days that have not started processing
  388. *
  389. * @see http://docs.amazonwebservices.com/${docPath}CancelFeedSubmissions.html
  390. * @param mixed $request array of parameters for MarketplaceWebService_Model_CancelFeedSubmissionsRequest request
  391. * or MarketplaceWebService_Model_CancelFeedSubmissionsRequest object itself
  392. * @see MarketplaceWebService_Model_CancelFeedSubmissions
  393. * @return MarketplaceWebService_Model_CancelFeedSubmissionsResponse MarketplaceWebService_Model_CancelFeedSubmissionsResponse
  394. *
  395. * @throws MarketplaceWebService_Exception
  396. */
  397. public function cancelFeedSubmissions($request)
  398. {
  399. if (!$request instanceof MarketplaceWebService_Model_CancelFeedSubmissionsRequest) {
  400. // require_once ('MarketplaceWebService/Model/CancelFeedSubmissionsRequest.php');
  401. $request = new MarketplaceWebService_Model_CancelFeedSubmissionsRequest($request);
  402. }
  403. // require_once ('MarketplaceWebService/Model/CancelFeedSubmissionsResponse.php');
  404. $httpResponse = $this->invoke($this->convertCancelFeedSubmissions($request));
  405. $response = MarketplaceWebService_Model_CancelFeedSubmissionsResponse::fromXML($httpResponse['ResponseBody']);
  406. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  407. return $response;
  408. }
  409. /**
  410. * Request Report
  411. * requests the generation of a report
  412. *
  413. * @see http://docs.amazonwebservices.com/${docPath}RequestReport.html
  414. * @param mixed $request array of parameters for MarketplaceWebService_Model_RequestReportRequest request
  415. * or MarketplaceWebService_Model_RequestReportRequest object itself
  416. * @see MarketplaceWebService_Model_RequestReport
  417. * @return MarketplaceWebService_Model_RequestReportResponse MarketplaceWebService_Model_RequestReportResponse
  418. *
  419. * @throws MarketplaceWebService_Exception
  420. */
  421. public function requestReport($request)
  422. {
  423. if (!$request instanceof MarketplaceWebService_Model_RequestReportRequest) {
  424. // require_once ('MarketplaceWebService/Model/RequestReportRequest.php');
  425. $request = new MarketplaceWebService_Model_RequestReportRequest($request);
  426. }
  427. // require_once ('MarketplaceWebService/Model/RequestReportResponse.php');
  428. $httpResponse = $this->invoke($this->convertRequestReport($request));
  429. $response = MarketplaceWebService_Model_RequestReportResponse::fromXML($httpResponse['ResponseBody']);
  430. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  431. return $response;
  432. }
  433. /**
  434. * Get Feed Submission Count
  435. * returns the number of feeds matching all of the specified criteria
  436. *
  437. * @see http://docs.amazonwebservices.com/${docPath}GetFeedSubmissionCount.html
  438. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetFeedSubmissionCountRequest request
  439. * or MarketplaceWebService_Model_GetFeedSubmissionCountRequest object itself
  440. * @see MarketplaceWebService_Model_GetFeedSubmissionCount
  441. * @return MarketplaceWebService_Model_GetFeedSubmissionCountResponse MarketplaceWebService_Model_GetFeedSubmissionCountResponse
  442. *
  443. * @throws MarketplaceWebService_Exception
  444. */
  445. public function getFeedSubmissionCount($request)
  446. {
  447. if (!$request instanceof MarketplaceWebService_Model_GetFeedSubmissionCountRequest) {
  448. // require_once ('MarketplaceWebService/Model/GetFeedSubmissionCountRequest.php');
  449. $request = new MarketplaceWebService_Model_GetFeedSubmissionCountRequest($request);
  450. }
  451. // require_once ('MarketplaceWebService/Model/GetFeedSubmissionCountResponse.php');
  452. $httpResponse = $this->invoke($this->convertGetFeedSubmissionCount($request));
  453. $response = MarketplaceWebService_Model_GetFeedSubmissionCountResponse::fromXML($httpResponse['ResponseBody']);
  454. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  455. return $response;
  456. }
  457. /**
  458. * Cancel Report Requests
  459. * cancels report requests that have not yet started processing,
  460. * by default all those within the last 90 days
  461. *
  462. * @see http://docs.amazonwebservices.com/${docPath}CancelReportRequests.html
  463. * @param mixed $request array of parameters for MarketplaceWebService_Model_CancelReportRequestsRequest request
  464. * or MarketplaceWebService_Model_CancelReportRequestsRequest object itself
  465. * @see MarketplaceWebService_Model_CancelReportRequests
  466. * @return MarketplaceWebService_Model_CancelReportRequestsResponse MarketplaceWebService_Model_CancelReportRequestsResponse
  467. *
  468. * @throws MarketplaceWebService_Exception
  469. */
  470. public function cancelReportRequests($request)
  471. {
  472. if (!$request instanceof MarketplaceWebService_Model_CancelReportRequestsRequest) {
  473. // require_once ('MarketplaceWebService/Model/CancelReportRequestsRequest.php');
  474. $request = new MarketplaceWebService_Model_CancelReportRequestsRequest($request);
  475. }
  476. // require_once ('MarketplaceWebService/Model/CancelReportRequestsResponse.php');
  477. $httpResponse = $this->invoke($this->convertCancelReportRequests($request));
  478. $response = MarketplaceWebService_Model_CancelReportRequestsResponse::fromXML($httpResponse['ResponseBody']);
  479. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  480. return $response;
  481. }
  482. /**
  483. * Get Report List
  484. * returns a list of reports; by default the most recent ten reports,
  485. * regardless of their acknowledgement status
  486. *
  487. * @see http://docs.amazonwebservices.com/${docPath}GetReportList.html
  488. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportListRequest request
  489. * or MarketplaceWebService_Model_GetReportListRequest object itself
  490. * @see MarketplaceWebService_Model_GetReportList
  491. * @return MarketplaceWebService_Model_GetReportListResponse MarketplaceWebService_Model_GetReportListResponse
  492. *
  493. * @throws MarketplaceWebService_Exception
  494. */
  495. public function getReportList($request)
  496. {
  497. if (!$request instanceof MarketplaceWebService_Model_GetReportListRequest) {
  498. // require_once ('MarketplaceWebService/Model/GetReportListRequest.php');
  499. $request = new MarketplaceWebService_Model_GetReportListRequest($request);
  500. }
  501. // require_once ('MarketplaceWebService/Model/GetReportListResponse.php');
  502. $httpResponse = $this->invoke($this->convertGetReportList($request));
  503. $response = MarketplaceWebService_Model_GetReportListResponse::fromXML($httpResponse['ResponseBody']);
  504. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  505. return $response;
  506. }
  507. /**
  508. * Get Feed Submission Result
  509. * retrieves the feed processing report
  510. *
  511. * @see http://docs.amazonwebservices.com/${docPath}GetFeedSubmissionResult.html
  512. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetFeedSubmissionResultRequest request
  513. * or MarketplaceWebService_Model_GetFeedSubmissionResultRequest object itself
  514. * @see MarketplaceWebService_Model_GetFeedSubmissionResult
  515. * @return MarketplaceWebService_Model_GetFeedSubmissionResultResponse MarketplaceWebService_Model_GetFeedSubmissionResultResponse
  516. *
  517. * @throws MarketplaceWebService_Exception
  518. */
  519. public function getFeedSubmissionResult($request)
  520. {
  521. if (!$request instanceof MarketplaceWebService_Model_GetFeedSubmissionResultRequest) {
  522. // require_once ('MarketplaceWebService/Model/GetFeedSubmissionResultRequest.php');
  523. $request = new MarketplaceWebService_Model_GetFeedSubmissionResultRequest($request);
  524. }
  525. // require_once ('MarketplaceWebService/Model/GetFeedSubmissionResultResponse.php');
  526. $httpResponse = $this->invoke($this->convertGetFeedSubmissionResult($request), $request->getFeedSubmissionResult());
  527. $response = MarketplaceWebService_Model_GetFeedSubmissionResultResponse::fromXML($httpResponse['ResponseBody']);
  528. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  529. return $response;
  530. }
  531. /**
  532. * Get Feed Submission List
  533. * returns a list of feed submission identifiers and their associated metadata
  534. *
  535. * @see http://docs.amazonwebservices.com/${docPath}GetFeedSubmissionList.html
  536. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetFeedSubmissionListRequest request
  537. * or MarketplaceWebService_Model_GetFeedSubmissionListRequest object itself
  538. * @see MarketplaceWebService_Model_GetFeedSubmissionList
  539. * @return MarketplaceWebService_Model_GetFeedSubmissionListResponse MarketplaceWebService_Model_GetFeedSubmissionListResponse
  540. *
  541. * @throws MarketplaceWebService_Exception
  542. */
  543. public function getFeedSubmissionList($request)
  544. {
  545. if (!$request instanceof MarketplaceWebService_Model_GetFeedSubmissionListRequest) {
  546. // require_once ('MarketplaceWebService/Model/GetFeedSubmissionListRequest.php');
  547. $request = new MarketplaceWebService_Model_GetFeedSubmissionListRequest($request);
  548. }
  549. // require_once ('MarketplaceWebService/Model/GetFeedSubmissionListResponse.php');
  550. $httpResponse = $this->invoke($this->convertGetFeedSubmissionList($request));
  551. $response = MarketplaceWebService_Model_GetFeedSubmissionListResponse::fromXML($httpResponse['ResponseBody']);
  552. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  553. return $response;
  554. }
  555. /**
  556. * Get Report Request List
  557. * returns a list of report requests ids and their associated metadata
  558. *
  559. * @see http://docs.amazonwebservices.com/${docPath}GetReportRequestList.html
  560. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportRequestListRequest request
  561. * or MarketplaceWebService_Model_GetReportRequestListRequest object itself
  562. * @see MarketplaceWebService_Model_GetReportRequestList
  563. * @return MarketplaceWebService_Model_GetReportRequestListResponse MarketplaceWebService_Model_GetReportRequestListResponse
  564. *
  565. * @throws MarketplaceWebService_Exception
  566. */
  567. public function getReportRequestList($request)
  568. {
  569. if (!$request instanceof MarketplaceWebService_Model_GetReportRequestListRequest) {
  570. // require_once ('MarketplaceWebService/Model/GetReportRequestListRequest.php');
  571. $request = new MarketplaceWebService_Model_GetReportRequestListRequest($request);
  572. }
  573. // require_once ('MarketplaceWebService/Model/GetReportRequestListResponse.php');
  574. $httpResponse = $this->invoke($this->convertGetReportRequestList($request));
  575. $response = MarketplaceWebService_Model_GetReportRequestListResponse::fromXML($httpResponse['ResponseBody']);
  576. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  577. return $response;
  578. }
  579. /**
  580. * Get Report Schedule List By Next Token
  581. * retrieve the next batch of list items and if there are more items to retrieve
  582. *
  583. * @see http://docs.amazonwebservices.com/${docPath}GetReportScheduleListByNextToken.html
  584. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportScheduleListByNextTokenRequest request
  585. * or MarketplaceWebService_Model_GetReportScheduleListByNextTokenRequest object itself
  586. * @see MarketplaceWebService_Model_GetReportScheduleListByNextToken
  587. * @return MarketplaceWebService_Model_GetReportScheduleListByNextTokenResponse MarketplaceWebService_Model_GetReportScheduleListByNextTokenResponse
  588. *
  589. * @throws MarketplaceWebService_Exception
  590. */
  591. public function getReportScheduleListByNextToken($request)
  592. {
  593. if (!$request instanceof MarketplaceWebService_Model_GetReportScheduleListByNextTokenRequest) {
  594. // require_once ('MarketplaceWebService/Model/GetReportScheduleListByNextTokenRequest.php');
  595. $request = new MarketplaceWebService_Model_GetReportScheduleListByNextTokenRequest($request);
  596. }
  597. // require_once ('MarketplaceWebService/Model/GetReportScheduleListByNextTokenResponse.php');
  598. $httpResponse = $this->invoke($this->convertGetReportScheduleListByNextToken($request));
  599. $response = MarketplaceWebService_Model_GetReportScheduleListByNextTokenResponse::fromXML($httpResponse['ResponseBody']);
  600. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  601. return $response;
  602. }
  603. /**
  604. * Get Report List By Next Token
  605. * retrieve the next batch of list items and if there are more items to retrieve
  606. *
  607. * @see http://docs.amazonwebservices.com/${docPath}GetReportListByNextToken.html
  608. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportListByNextTokenRequest request
  609. * or MarketplaceWebService_Model_GetReportListByNextTokenRequest object itself
  610. * @see MarketplaceWebService_Model_GetReportListByNextToken
  611. * @return MarketplaceWebService_Model_GetReportListByNextTokenResponse MarketplaceWebService_Model_GetReportListByNextTokenResponse
  612. *
  613. * @throws MarketplaceWebService_Exception
  614. */
  615. public function getReportListByNextToken($request)
  616. {
  617. if (!$request instanceof MarketplaceWebService_Model_GetReportListByNextTokenRequest) {
  618. // require_once ('MarketplaceWebService/Model/GetReportListByNextTokenRequest.php');
  619. $request = new MarketplaceWebService_Model_GetReportListByNextTokenRequest($request);
  620. }
  621. // require_once ('MarketplaceWebService/Model/GetReportListByNextTokenResponse.php');
  622. $httpResponse = $this->invoke($this->convertGetReportListByNextToken($request));
  623. $response = MarketplaceWebService_Model_GetReportListByNextTokenResponse::fromXML($httpResponse['ResponseBody']);
  624. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  625. return $response;
  626. }
  627. /**
  628. * Manage Report Schedule
  629. * Creates, updates, or deletes a report schedule
  630. * for a given report type, such as order reports in particular.
  631. *
  632. * @see http://docs.amazonwebservices.com/${docPath}ManageReportSchedule.html
  633. * @param mixed $request array of parameters for MarketplaceWebService_Model_ManageReportScheduleRequest request
  634. * or MarketplaceWebService_Model_ManageReportScheduleRequest object itself
  635. * @see MarketplaceWebService_Model_ManageReportSchedule
  636. * @return MarketplaceWebService_Model_ManageReportScheduleResponse MarketplaceWebService_Model_ManageReportScheduleResponse
  637. *
  638. * @throws MarketplaceWebService_Exception
  639. */
  640. public function manageReportSchedule($request)
  641. {
  642. if (!$request instanceof MarketplaceWebService_Model_ManageReportScheduleRequest) {
  643. // require_once ('MarketplaceWebService/Model/ManageReportScheduleRequest.php');
  644. $request = new MarketplaceWebService_Model_ManageReportScheduleRequest($request);
  645. }
  646. // require_once ('MarketplaceWebService/Model/ManageReportScheduleResponse.php');
  647. $httpResponse = $this->invoke($this->convertManageReportSchedule($request));
  648. $response = MarketplaceWebService_Model_ManageReportScheduleResponse::fromXML($httpResponse['ResponseBody']);
  649. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  650. return $response;
  651. }
  652. /**
  653. * Get Report Request Count
  654. * returns a count of report requests; by default all the report
  655. * requests in the last 90 days
  656. *
  657. * @see http://docs.amazonwebservices.com/${docPath}GetReportRequestCount.html
  658. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportRequestCountRequest request
  659. * or MarketplaceWebService_Model_GetReportRequestCountRequest object itself
  660. * @see MarketplaceWebService_Model_GetReportRequestCount
  661. * @return MarketplaceWebService_Model_GetReportRequestCountResponse MarketplaceWebService_Model_GetReportRequestCountResponse
  662. *
  663. * @throws MarketplaceWebService_Exception
  664. */
  665. public function getReportRequestCount($request)
  666. {
  667. if (!$request instanceof MarketplaceWebService_Model_GetReportRequestCountRequest) {
  668. // require_once ('MarketplaceWebService/Model/GetReportRequestCountRequest.php');
  669. $request = new MarketplaceWebService_Model_GetReportRequestCountRequest($request);
  670. }
  671. // require_once ('MarketplaceWebService/Model/GetReportRequestCountResponse.php');
  672. $httpResponse = $this->invoke($this->convertGetReportRequestCount($request));
  673. $response = MarketplaceWebService_Model_GetReportRequestCountResponse::fromXML($httpResponse['ResponseBody']);
  674. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  675. return $response;
  676. }
  677. /**
  678. * Get Report Schedule List
  679. * returns the list of report schedules
  680. *
  681. * @see http://docs.amazonwebservices.com/${docPath}GetReportScheduleList.html
  682. * @param mixed $request array of parameters for MarketplaceWebService_Model_GetReportScheduleListRequest request
  683. * or MarketplaceWebService_Model_GetReportScheduleListRequest object itself
  684. * @see MarketplaceWebService_Model_GetReportScheduleList
  685. * @return MarketplaceWebService_Model_GetReportScheduleListResponse MarketplaceWebService_Model_GetReportScheduleListResponse
  686. *
  687. * @throws MarketplaceWebService_Exception
  688. */
  689. public function getReportScheduleList($request)
  690. {
  691. if (!$request instanceof MarketplaceWebService_Model_GetReportScheduleListRequest) {
  692. // require_once ('MarketplaceWebService/Model/GetReportScheduleListRequest.php');
  693. $request = new MarketplaceWebService_Model_GetReportScheduleListRequest($request);
  694. }
  695. // require_once ('MarketplaceWebService/Model/GetReportScheduleListResponse.php');
  696. $httpResponse = $this->invoke($this->convertGetReportScheduleList($request));
  697. $response = MarketplaceWebService_Model_GetReportScheduleListResponse::fromXML($httpResponse['ResponseBody']);
  698. $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
  699. return $response;
  700. }
  701. // Private API ------------------------------------------------------------//
  702. /**
  703. * Get the base64 encoded md5 value of $data. If $data is a memory or temp file stream, this
  704. * method dumps the contents into a string before calculating the md5. Hence, this method
  705. * shouldn't be used for large memory streams.
  706. *
  707. * @param $data
  708. * @return unknown_type
  709. */
  710. private function getContentMd5($data) {
  711. $md5Hash = null;
  712. if (is_string($data)) {
  713. $md5Hash = md5($data, true);
  714. } else if (is_resource($data)) {
  715. // Assume $data is a stream.
  716. $streamMetadata = stream_get_meta_data($data);
  717. if ($streamMetadata['stream_type'] === 'MEMORY' || $streamMetadata['stream_type'] === 'TEMP') {
  718. $md5Hash = md5(stream_get_contents($data), true);
  719. } else {
  720. $md5Hash = md5_file($streamMetadata['uri'], true);
  721. }
  722. }
  723. return base64_encode($md5Hash);
  724. }
  725. /**
  726. * Invoke request and return response
  727. */
  728. private function invoke(array $converted, $dataHandle = null, $contentMd5 = null)
  729. {
  730. $parameters = $converted[CONVERTED_PARAMETERS_KEY];
  731. $actionName = $parameters["Action"];
  732. $response = array();
  733. $responseBody = null;
  734. $statusCode = 200;
  735. /* Submit the request and read response body */
  736. try {
  737. // Ensure the endpoint URL is set.
  738. if (empty($this->config['ServiceURL'])) {
  739. throw new MarketplaceWebService_Exception(
  740. array('ErrorCode' => 'InvalidServiceUrl',
  741. 'Message' => "Missing serviceUrl configuration value. You may obtain a list of valid MWS URLs by consulting the MWS Developer's Guide, or reviewing the sample code published along side this library."));
  742. }
  743. /* Add required request parameters */
  744. $parameters = $this->addRequiredParameters($parameters);
  745. $converted[CONVERTED_PARAMETERS_KEY] = $parameters;
  746. $shouldRetry = false;
  747. $retries = 0;
  748. do {
  749. try {
  750. $response = $this->performRequest($actionName, $converted, $dataHandle, $contentMd5);
  751. $httpStatus = $response['Status'];
  752. switch ($httpStatus) {
  753. case 200:
  754. $shouldRetry = false;
  755. break;
  756. case 500:
  757. case 503:
  758. // require_once ('MarketplaceWebService/Model/ErrorResponse.php');
  759. $errorResponse = MarketplaceWebService_Model_ErrorResponse::fromXML($response['ResponseBody']);
  760. // We will not retry throttling errors since this would just add to the throttling problem.
  761. $shouldRetry = ($errorResponse->getError()->getCode() === 'RequestThrottled')
  762. ? false : true;
  763. if ($shouldRetry && $retries <= $this->config['MaxErrorRetry']) {
  764. $this->pauseOnRetry(++$retries);
  765. } else {
  766. throw $this->reportAnyErrors($response['ResponseBody'], $response['Status'], null, $response['ResponseHeaderMetadata']);
  767. }
  768. break;
  769. default:
  770. $shouldRetry = false;
  771. throw $this->reportAnyErrors($response['ResponseBody'], $response['Status'], null, $response['ResponseHeaderMetadata']);
  772. break;
  773. }
  774. /* Rethrow on deserializer error */
  775. } catch (Exception $e) {
  776. // require_once ('MarketplaceWebService/Exception.php');
  777. throw new MarketplaceWebService_Exception(array('Exception' => $e, 'Message' => $e->getMessage()));
  778. }
  779. } while ($shouldRetry);
  780. } catch (MarketplaceWebService_Exception $se) {
  781. throw $se;
  782. } catch (Exception $t) {
  783. throw new MarketplaceWebService_Exception(array('Exception' => $t, 'Message' => $t->getMessage()));
  784. }
  785. return array('ResponseBody' => $response['ResponseBody'], 'ResponseHeaderMetadata' => $response['ResponseHeaderMetadata']);
  786. }
  787. /**
  788. * Look for additional error strings in the response and return formatted exception
  789. */
  790. private function reportAnyErrors($responseBody, $status, Exception $e = null, $responseHeaderMetadata)
  791. {
  792. $exProps = array();
  793. $exProps["StatusCode"] = $status;
  794. $exProps["ResponseHeaderMetadata"] = $responseHeaderMetadata;
  795. libxml_use_internal_errors(true); // Silence XML parsing errors
  796. $xmlBody = simplexml_load_string($responseBody);
  797. if ($xmlBody !== false) { // Check XML loaded without errors
  798. $exProps["XML"] = $responseBody;
  799. $exProps["ErrorCode"] = $xmlBody->Error->Code;
  800. $exProps["Message"] = $xmlBody->Error->Message;
  801. $exProps["ErrorType"] = !empty($xmlBody->Error->Type) ? $xmlBody->Error->Type : "Unknown";
  802. $exProps["RequestId"] = !empty($xmlBody->RequestID) ? $xmlBody->RequestID : $xmlBody->RequestId; // 'd' in RequestId is sometimes capitalized
  803. } else { // We got bad XML in response, just throw a generic exception
  804. $exProps["Message"] = "Internal Error";
  805. }
  806. // require_once ('MarketplaceWebService/Exception.php');
  807. return new MarketplaceWebService_Exception($exProps);
  808. }
  809. /**
  810. * Setup and execute the request via cURL and return the server response.
  811. *
  812. * @param $action - the MWS action to perform.
  813. * @param $parameters - the MWS parameters for the Action.
  814. * @param $dataHandle - A stream handle to either a feed to upload, or a report/feed submission result to download.
  815. * @param $contentMd5 - The Content-MD5 HTTP header value used for feed submissions.
  816. * @return array
  817. */
  818. private function performRequest($action, array $converted, $dataHandle = null, $contentMd5 = null) {
  819. $curlOptions = $this->configureCurlOptions($action, $converted, $dataHandle, $contentMd5);
  820. if (is_null($curlOptions[CURLOPT_RETURNTRANSFER]) || !$curlOptions[CURLOPT_RETURNTRANSFER]) {
  821. $curlOptions[CURLOPT_RETURNTRANSFER] = true;
  822. }
  823. $this->curlClient = curl_init();
  824. curl_setopt_array($this->curlClient, $curlOptions);
  825. $this->headerContents = @fopen('php://memory', 'rw+');
  826. $this->errorResponseBody = @fopen('php://memory', 'rw+');
  827. $httpResponse = curl_exec($this->curlClient);
  828. rewind($this->headerContents);
  829. $header = stream_get_contents($this->headerContents);
  830. $parsedHeader = $this->parseHttpHeader($header);
  831. // require_once ('MarketplaceWebService/Model/ResponseHeaderMetadata.php');
  832. $responseHeaderMetadata = new MarketplaceWebService_Model_ResponseHeaderMetadata(
  833. $parsedHeader['x-mws-request-id'],
  834. $parsedHeader['x-mws-response-context'],
  835. $parsedHeader['x-mws-timestamp']);
  836. $code = (int) curl_getinfo($this->curlClient, CURLINFO_HTTP_CODE);
  837. // Only attempt to verify the Content-MD5 value if the request was successful.
  838. if (RequestType::getRequestType($action) === RequestType::POST_DOWNLOAD) {
  839. if ($code != 200) {
  840. rewind($this->errorResponseBody);
  841. $httpResponse = stream_get_contents($this->errorResponseBody);
  842. } else {
  843. $this->verifyContentMd5($this->getParsedHeader($parsedHeader,'Content-MD5'), $dataHandle);
  844. $httpResponse = $this->getDownloadResponseDocument($action, $parsedHeader);
  845. }
  846. }
  847. // Cleanup open streams and cURL instance.
  848. @fclose($this->headerContents);
  849. @fclose($this->errorResponseBody);
  850. curl_close($this->curlClient);
  851. return array (
  852. 'Status' => $code,
  853. 'ResponseBody' => $httpResponse,
  854. 'ResponseHeaderMetadata' => $responseHeaderMetadata);
  855. }
  856. private function getParsedHeader($parsedHeader, $key) {
  857. return $parsedHeader[strtolower($key)];
  858. }
  859. /**
  860. * Compares the received Content-MD5 Hash value from the response with a locally calculated
  861. * value based on the contents of the response body. If the received hash value doesn't match
  862. * the locally calculated hash value, an exception is raised.
  863. *
  864. * @param $receivedMd5Hash
  865. * @param $streamHandle
  866. * @return unknown_type
  867. */
  868. private function verifyContentMd5($receivedMd5Hash, $streamHandle) {
  869. rewind($streamHandle);
  870. $expectedMd5Hash = $this->getContentMd5($streamHandle);
  871. rewind($streamHandle);
  872. if (!($receivedMd5Hash === $expectedMd5Hash)) {
  873. // require_once ('MarketplaceWebService/Exception.php');
  874. throw new MarketplaceWebService_Exception(
  875. array(
  876. 'Message' => 'Received Content-MD5 = ' . $receivedMd5Hash . ' but expected ' . $expectedMd5Hash,
  877. 'ErrorCode' => 'ContentMD5DoesNotMatch'));
  878. }
  879. }
  880. /**
  881. * Build an associative array of an HTTP Header lines. For requests, the HTTP request line
  882. * is not contained in the array, nor is the HTTP status line for response headers.
  883. *
  884. * @param $header
  885. * @return array
  886. */
  887. private function parseHttpHeader($header) {
  888. $parsedHeader = array ();
  889. foreach (explode("\n", $header) as $line) {
  890. $splitLine = preg_split('/:\s/', $line, 2, PREG_SPLIT_NO_EMPTY);
  891. if (sizeof($splitLine) == 2) {
  892. $k = strtolower(trim($splitLine[0]));
  893. $v = trim($splitLine[1]);
  894. if (array_key_exists($k, $parsedHeader)) {
  895. $parsedHeader[$k] = $parsedHeader[$k] . "," . $v;
  896. } else {
  897. $parsedHeader[$k] = $v;
  898. }
  899. }
  900. }
  901. return $parsedHeader;
  902. }
  903. /**
  904. * cURL callback to write the response HTTP body into a stream. This is only intended to be used
  905. * with RequestType::POST_DOWNLOAD request types, since the responses can potentially become
  906. * large.
  907. *
  908. * @param $ch - The curl handle.
  909. * @param $string - body portion to write.
  910. * @return int - number of byes written.
  911. */
  912. private function responseCallback($ch, $string) {
  913. $httpStatusCode = (int) curl_getinfo($this->curlClient, CURLINFO_HTTP_CODE);
  914. // For unsuccessful responses, i.e. non-200 HTTP responses, we write the response body
  915. // into a separate stream.
  916. $responseHandle;
  917. if ($httpStatusCode == 200) {
  918. $responseHandle = $this->responseBodyContents;
  919. } else {
  920. $responseHandle = $this->errorResponseBody;
  921. }
  922. return fwrite($responseHandle, $string);
  923. }
  924. /**
  925. * cURL callback to write the response HTTP header into a stream.
  926. *
  927. * @param $ch - The curl handle.
  928. * @param $string - header portion to write.
  929. * @return int - number of bytes written to stream.
  930. */
  931. private function headerCallback($ch, $string) {
  932. $bytesWritten = fwrite($this->headerContents, $string);
  933. return $bytesWritten;
  934. }
  935. /**
  936. * Gets cURL options common to all MWS requests.
  937. * @return unknown_type
  938. */
  939. private function getDefaultCurlOptions() {
  940. return array (
  941. CURLOPT_POST => true,
  942. CURLOPT_USERAGENT => $this->config['UserAgent'],
  943. CURLOPT_VERBOSE => true,
  944. CURLOPT_HEADERFUNCTION => array ($this, 'headerCallback'),
  945. CURLOPT_RETURNTRANSFER => true,
  946. CURLOPT_SSL_VERIFYPEER => true,
  947. CURLOPT_SSL_VERIFYHOST => 2
  948. );
  949. }
  950. /**
  951. * Configures specific curl options based on the request type.
  952. *
  953. * @param $action
  954. * @param $parameters
  955. * @param $streamHandle
  956. * @return array
  957. */
  958. private function configureCurlOptions($action, array $converted, $streamHandle = null, $contentMd5 = null) {
  959. $curlOptions = $this->getDefaultCurlOptions();
  960. if (!is_null($this->config['ProxyHost'])) {
  961. $proxy = $this->config['ProxyHost'];
  962. $proxy .= ':' . ($this->config['ProxyPort'] == -1 ? '80' : $this->config['ProxyPort']);
  963. $curlOptions[CURLOPT_PROXY] = $proxy;
  964. }
  965. $serviceUrl = $this->config['ServiceURL'];
  966. // append the '/' character to the end of the service URL if it doesn't exist.
  967. if (!(substr($serviceUrl, strlen($serviceUrl) - 1) === '/')) {
  968. $serviceUrl .= '/';
  969. }
  970. $requestType = RequestType::getRequestType($action);
  971. if ($requestType == RequestType::POST_UPLOAD) {
  972. if (is_null($streamHandle) || !is_resource($streamHandle)) {
  973. // require_once ('MarketplaceWebService/Exception.php');
  974. throw new MarketplaceWebService_Exception(
  975. array ('Message' => 'Missing stream resource.'));
  976. }
  977. $serviceUrl .= '?' . $this->getParametersAsString($converted[CONVERTED_PARAMETERS_KEY]);
  978. $curlOptions[CURLOPT_URL] = $serviceUrl;
  979. $header[] = 'Expect: ';
  980. $header[] = 'Accept: ';
  981. $header[] = 'Transfer-Encoding: chunked';
  982. $header[] = 'Content-MD5: ' . $contentMd5;
  983. $curlOptions[CURLOPT_HTTPHEADER] = array_merge($header, $converted[CONVERTED_HEADERS_KEY]);
  984. rewind($streamHandle);
  985. $curlOptions[CURLOPT_INFILE] = $streamHandle;
  986. $curlOptions[CURLOPT_UPLOAD] = true;
  987. $curlOptions[CURLOPT_CUSTOMREQUEST] = self::REQUEST_TYPE;
  988. } else if (!($requestType === RequestType::UNKNOWN)) {
  989. $curlOptions[CURLOPT_URL] = $this->config['ServiceURL'];
  990. $curlOptions[CURLOPT_POSTFIELDS] = $this->getParametersAsString($converted[CONVERTED_PARAMETERS_KEY]);
  991. if ($requestType == RequestType::POST_DOWNLOAD) {
  992. $this->responseBodyContents = $streamHandle;
  993. $curlOptions[CURLOPT_WRITEFUNCTION] = array ($this, 'responseCallback');
  994. }
  995. } else {
  996. throw new InvalidArgumentException("$action is not a valid request type.");
  997. }
  998. return $curlOptions;
  999. }
  1000. /**
  1001. * For RequestType::POST_DOWNLOAD actions, construct a response containing the Amazon Request ID
  1002. * and Content MD5 header value.
  1003. *
  1004. * @param $responseType
  1005. * @param $header
  1006. * @return unknown_type
  1007. */
  1008. private function getDownloadResponseDocument($responseType, $header) {
  1009. $md5 = $this->getParsedHeader($header, 'Content-MD5');
  1010. $requestId = $this->getParsedHeader($header, 'x-amz-request-id');
  1011. $response = '<' . $responseType . 'Response xmlns="http://mws.amazonaws.com/doc/2009-01-01/">';
  1012. $response .= '<' . $responseType . 'Result>';
  1013. $response .= '<ContentMd5>';
  1014. $response .= $md5;
  1015. $response .= '</ContentMd5>';
  1016. $response .= '</' . $responseType . 'Result>';
  1017. $response .= '<ResponseMetadata>';
  1018. $response .= '<RequestId>';
  1019. $response .= $requestId;
  1020. $response .= '</RequestId>';
  1021. $response .= '</ResponseMetadata>';
  1022. $response .= '</' . $responseType . 'Response>';
  1023. return $response;
  1024. }
  1025. /**
  1026. * Exponential sleep on failed request
  1027. * @param retries current retry
  1028. */
  1029. private function pauseOnRetry($retries)
  1030. {
  1031. $delay = (int) (pow(4, $retries) * 100000) ;
  1032. usleep($delay);
  1033. }
  1034. /**
  1035. * Add authentication related and version parameters
  1036. */
  1037. private function addRequiredParameters(array $parameters)
  1038. {
  1039. $parameters['AWSAccessKeyId'] = $this->awsAccessKeyId;
  1040. $parameters['Timestamp'] = $this->getFormattedTimestamp(new DateTime('now', new DateTimeZone('UTC')));
  1041. $parameters['Version'] = self::SERVICE_VERSION;
  1042. $parameters['SignatureVersion'] = $this->config['SignatureVersion'];
  1043. if ($parameters['SignatureVersion'] > 1) {
  1044. $parameters['SignatureMethod'] = $this->config['SignatureMethod'];
  1045. }
  1046. $parameters['Signature'] = $this->signParameters($parameters, $this->awsSecretAccessKey);
  1047. return $parameters;
  1048. }
  1049. /**
  1050. * Convert paremeters to Url encoded query string
  1051. */
  1052. private function getParametersAsString(array $parameters)
  1053. {
  1054. $queryParameters = array();
  1055. foreach ($parameters as $key => $value) {
  1056. $queryParameters[] = $key . '=' . $this->urlencode($value);
  1057. }
  1058. return implode('&', $queryParameters);
  1059. }
  1060. /**
  1061. * Computes RFC 2104-compliant HMAC signature for request parameters
  1062. * Implements AWS Signature, as per following spec:
  1063. *
  1064. * Signature Version 0: This is not supported in the Marketplace Web Service.
  1065. *
  1066. * Signature Version 1: This is not supported in the Marketplace Web Service.
  1067. *
  1068. * Signature Version is 2, string to sign is based on following:
  1069. *
  1070. * 1. The HTTP Request Method followed by an ASCII newline (%0A)
  1071. * 2. The HTTP Host header in the form of lowercase host, followed by an ASCII newline.
  1072. * 3. The URL encoded HTTP absolute path component of the URI
  1073. * (up to but not including the query string parameters);
  1074. * if this is empty use a forward '/'. This parameter is followed by an ASCII newline.
  1075. * 4. The concatenation of all query string components (names and values)
  1076. * as UTF-8 characters which are URL encoded as per RFC 3986
  1077. * (hex characters MUST be uppercase), sorted using lexicographic byte ordering.
  1078. * Parameter names are separated from their values by the '=' character
  1079. * (ASCII character 61), even if the value is empty.
  1080. * Pairs of parameter and values are separated by the '&' character (ASCII code 38).
  1081. *
  1082. */
  1083. private function signParameters(array $parameters, $key) {
  1084. $signatureVersion = $parameters['SignatureVersion'];
  1085. $algorithm = "HmacSHA1";
  1086. $stringToSign = null;
  1087. if (0 === $signatureVersion) {
  1088. throw new InvalidArgumentException(
  1089. 'Signature Version 0 is no longer supported. Only Signature Version 2 is supported.');
  1090. } else if (1 === $signatureVersion) {
  1091. throw new InvalidArgumentException(
  1092. 'Signature Version 1 is no longer supported. Only Signature Version 2 is supported.');
  1093. } else if (2 === $signatureVersion) {
  1094. $algorithm = $this->config['SignatureMethod'];
  1095. $parameters['SignatureMethod'] = $algorithm;
  1096. $stringToSign = $this->calculateStringToSignV2($parameters);
  1097. } else {
  1098. throw new Exception("Invalid Signature Version specified");
  1099. }
  1100. return $this->sign($stringToSign, $key, $algorithm);
  1101. }
  1102. /**
  1103. * Calculate String to Sign for SignatureVersion 2
  1104. * @param array $parameters request parameters
  1105. * @return String to Sign
  1106. */
  1107. private function calculateStringToSignV2(array $parameters, $queuepath = null) {
  1108. $parsedUrl = parse_url($this->config['ServiceURL']);
  1109. $endpoint = $parsedUrl['host'];
  1110. if (isset($parsedUrl['port']) && !is_null($parsedUrl['port'])) {
  1111. $endpoint .= ':' . $parsedUrl['port'];
  1112. }
  1113. $data = 'POST';
  1114. $data .= "\n";
  1115. $data .= $endpoint;
  1116. $data .= "\n";
  1117. if ($queuepath) {
  1118. $uri = $queuepath;
  1119. } else {
  1120. $uri = "/";
  1121. }
  1122. $uriencoded = implode("/", array_map(array($this, "urlencode"), explode("/", $uri)));
  1123. $data .= $uriencoded;
  1124. $data .= "\n";
  1125. uksort($parameters, 'strcmp');
  1126. $data .= $this->getParametersAsString($parameters);
  1127. return $data;
  1128. }
  1129. private function urlencode($value) {
  1130. return str_replace('%7E', '~', rawurlencode($value));
  1131. }
  1132. /**
  1133. * Computes RFC 2104-compliant HMAC signature
  1134. */
  1135. private function sign($data, $key, $algorithm)
  1136. {
  1137. if ($algorithm === 'HmacSHA1') {
  1138. $hash = 'sha1';
  1139. } else if ($algorithm === 'HmacSHA256') {
  1140. $hash = 'sha256';
  1141. } else {
  1142. throw new Exception ("Non-supported signing method specified");
  1143. }
  1144. return base64_encode(
  1145. hash_hmac($hash, $data, $key, true)
  1146. );
  1147. }
  1148. /**
  1149. * Returns a ISO 8601 formatted string from a DateTime instance.
  1150. */
  1151. private function getFormattedTimestamp($dateTime) {
  1152. return $dateTime->format(DATE_ISO8601);
  1153. }
  1154. /**
  1155. * Convert GetReportRequest to name value pairs
  1156. */
  1157. private function convertGetReport($request) {
  1158. $parameters = array();
  1159. $parameters['Action'] = 'GetReport';
  1160. if ($request->isSetMarketplace()) {
  1161. $parameters['Marketplace'] = $request->getMarketplace();
  1162. }
  1163. if ($request->isSetMerchant()) {
  1164. $parameters['Merchant'] = $request->getMerchant();
  1165. }
  1166. if ($request->isSetReportId()) {
  1167. $parameters['ReportId'] = $request->getReportId();
  1168. }
  1169. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1170. }
  1171. /**
  1172. * Convert GetReportScheduleCountRequest to name value pairs
  1173. */
  1174. private function convertGetReportScheduleCount($request) {
  1175. $parameters = array();
  1176. $parameters['Action'] = 'GetReportScheduleCount';
  1177. if ($request->isSetMarketplace()) {
  1178. $parameters['Marketplace'] = $request->getMarketplace();
  1179. }
  1180. if ($request->isSetMerchant()) {
  1181. $parameters['Merchant'] = $request->getMerchant();
  1182. }
  1183. if ($request->isSetReportTypeList()) {
  1184. $reportTypeList = $request->getReportTypeList();
  1185. foreach ($reportTypeList->getType() as $typeIndex => $type) {
  1186. $parameters['ReportTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1187. }
  1188. }
  1189. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1190. }
  1191. /**
  1192. * Convert GetReportRequestListByNextTokenRequest to name value pairs
  1193. */
  1194. private function convertGetReportRequestListByNextToken($request) {
  1195. $parameters = array();
  1196. $parameters['Action'] = 'GetReportRequestListByNextToken';
  1197. if ($request->isSetMarketplace()) {
  1198. $parameters['Marketplace'] = $request->getMarketplace();
  1199. }
  1200. if ($request->isSetMerchant()) {
  1201. $parameters['Merchant'] = $request->getMerchant();
  1202. }
  1203. if ($request->isSetNextToken()) {
  1204. $parameters['NextToken'] = $request->getNextToken();
  1205. }
  1206. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1207. }
  1208. /**
  1209. * Convert UpdateReportAcknowledgementsRequest to name value pairs
  1210. */
  1211. private function convertUpdateReportAcknowledgements($request) {
  1212. $parameters = array();
  1213. $parameters['Action'] = 'UpdateReportAcknowledgements';
  1214. if ($request->isSetMarketplace()) {
  1215. $parameters['Marketplace'] = $request->getMarketplace();
  1216. }
  1217. if ($request->isSetMerchant()) {
  1218. $parameters['Merchant'] = $request->getMerchant();
  1219. }
  1220. if ($request->isSetReportIdList()) {
  1221. $reportIdList = $request->getReportIdList();
  1222. foreach ($reportIdList->getId() as $idIndex => $id) {
  1223. $parameters['ReportIdList' . '.' . 'Id' . '.' . ($idIndex + 1)] = $id;
  1224. }
  1225. }
  1226. if ($request->isSetAcknowledged()) {
  1227. $parameters['Acknowledged'] = $request->getAcknowledged() ? "true" : "false";
  1228. }
  1229. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1230. }
  1231. /**
  1232. * Convert SubmitFeedRequest to name value pairs
  1233. */
  1234. private function convertSubmitFeed($request) {
  1235. $parameters = array();
  1236. $parameters['Action'] = 'SubmitFeed';
  1237. if ($request->isSetMarketplace()) {
  1238. $parameters['Marketplace'] = $request->getMarketplace();
  1239. }
  1240. if ($request->isSetMerchant()) {
  1241. $parameters['Merchant'] = $request->getMerchant();
  1242. }
  1243. if ($request->isSetMarketplaceIdList()) {
  1244. $marketplaceIdList = $request->getMarketplaceIdList();
  1245. foreach ($marketplaceIdList->getId() as $idIndex => $id) {
  1246. $parameters['MarketplaceIdList.Id.'.($idIndex + 1)] = $id;
  1247. }
  1248. }
  1249. if ($request->isSetFeedType()) {
  1250. $parameters['FeedType'] = $request->getFeedType();
  1251. }
  1252. if ($request->isSetPurgeAndReplace()) {
  1253. $parameters['PurgeAndReplace'] = $request->getPurgeAndReplace() ? "true" : "false";
  1254. }
  1255. $headers = array();
  1256. array_push($headers, "Content-Type: " . $request->getContentType()->toString());
  1257. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $headers);
  1258. }
  1259. /**
  1260. * Convert GetReportCountRequest to name value pairs
  1261. */
  1262. private function convertGetReportCount($request) {
  1263. $parameters = array();
  1264. $parameters['Action'] = 'GetReportCount';
  1265. if ($request->isSetMarketplace()) {
  1266. $parameters['Marketplace'] = $request->getMarketplace();
  1267. }
  1268. if ($request->isSetMerchant()) {
  1269. $parameters['Merchant'] = $request->getMerchant();
  1270. }
  1271. if ($request->isSetReportTypeList()) {
  1272. $reportTypeList = $request->getReportTypeList();
  1273. foreach ($reportTypeList->getType() as $typeIndex => $type) {
  1274. $parameters['ReportTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1275. }
  1276. }
  1277. if ($request->isSetAcknowledged()) {
  1278. $parameters['Acknowledged'] = $request->getAcknowledged() ? "true" : "false";
  1279. }
  1280. if ($request->isSetAvailableFromDate()) {
  1281. $parameters['AvailableFromDate'] =
  1282. $this->getFormattedTimestamp($request->getAvailableFromDate());
  1283. }
  1284. if ($request->isSetAvailableToDate()) {
  1285. $parameters['AvailableToDate'] =
  1286. $this->getFormattedTimestamp($request->getAvailableToDate());
  1287. }
  1288. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1289. }
  1290. /**
  1291. * Convert GetFeedSubmissionListByNextTokenRequest to name value pairs
  1292. */
  1293. private function convertGetFeedSubmissionListByNextToken($request) {
  1294. $parameters = array();
  1295. $parameters['Action'] = 'GetFeedSubmissionListByNextToken';
  1296. if ($request->isSetMarketplace()) {
  1297. $parameters['Marketplace'] = $request->getMarketplace();
  1298. }
  1299. if ($request->isSetMerchant()) {
  1300. $parameters['Merchant'] = $request->getMerchant();
  1301. }
  1302. if ($request->isSetNextToken()) {
  1303. $parameters['NextToken'] = $request->getNextToken();
  1304. }
  1305. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1306. }
  1307. /**
  1308. * Convert CancelFeedSubmissionsRequest to name value pairs
  1309. */
  1310. private function convertCancelFeedSubmissions($request) {
  1311. $parameters = array();
  1312. $parameters['Action'] = 'CancelFeedSubmissions';
  1313. if ($request->isSetMarketplace()) {
  1314. $parameters['Marketplace'] = $request->getMarketplace();
  1315. }
  1316. if ($request->isSetMerchant()) {
  1317. $parameters['Merchant'] = $request->getMerchant();
  1318. }
  1319. if ($request->isSetFeedSubmissionIdList()) {
  1320. $feedSubmissionIdList = $request->getFeedSubmissionIdList();
  1321. foreach ($feedSubmissionIdList->getId() as $idIndex => $id) {
  1322. $parameters['FeedSubmissionIdList' . '.' . 'Id' . '.' . ($idIndex + 1)] = $id;
  1323. }
  1324. }
  1325. if ($request->isSetFeedTypeList()) {
  1326. $feedTypeList = $request->getFeedTypeList();
  1327. foreach ($feedTypeList->getType() as $typeIndex => $type) {
  1328. $parameters['FeedTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1329. }
  1330. }
  1331. if ($request->isSetSubmittedFromDate()) {
  1332. $parameters['SubmittedFromDate'] =
  1333. $this->getFormattedTimestamp($request->getSubmittedFromDate());
  1334. }
  1335. if ($request->isSetSubmittedToDate()) {
  1336. $parameters['SubmittedToDate'] =
  1337. $this->getFormattedTimestamp($request->getSubmittedToDate());
  1338. }
  1339. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1340. }
  1341. /**
  1342. * Convert RequestReportRequest to name value pairs
  1343. */
  1344. private function convertRequestReport($request) {
  1345. $parameters = array();
  1346. $parameters['Action'] = 'RequestReport';
  1347. if ($request->isSetMarketplace()) {
  1348. $parameters['Marketplace'] = $request->getMarketplace();
  1349. }
  1350. if ($request->isSetMerchant()) {
  1351. $parameters['Merchant'] = $request->getMerchant();
  1352. }
  1353. if ($request->isSetMarketplaceIdList()) {
  1354. $marketplaceIdList = $request->getMarketplaceIdList();
  1355. foreach ($marketplaceIdList->getId() as $idIndex => $id) {
  1356. $parameters['MarketplaceIdList.Id.'.($idIndex + 1)] = $id;
  1357. }
  1358. }
  1359. if ($request->isSetReportType()) {
  1360. $parameters['ReportType'] = $request->getReportType();
  1361. }
  1362. if ($request->isSetStartDate()) {
  1363. $parameters['StartDate'] =
  1364. $this->getFormattedTimestamp($request->getStartDate());
  1365. }
  1366. if ($request->isSetEndDate()) {
  1367. $parameters['EndDate'] =
  1368. $this->getFormattedTimestamp($request->getEndDate());
  1369. }
  1370. if ($request->isSetReportOptions()) {
  1371. $parameters['ReportOptions'] = $request->getReportOptions();
  1372. }
  1373. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1374. }
  1375. /**
  1376. * Convert GetFeedSubmissionCountRequest to name value pairs
  1377. */
  1378. private function convertGetFeedSubmissionCount($request) {
  1379. $parameters = array();
  1380. $parameters['Action'] = 'GetFeedSubmissionCount';
  1381. if ($request->isSetMarketplace()) {
  1382. $parameters['Marketplace'] = $request->getMarketplace();
  1383. }
  1384. if ($request->isSetMerchant()) {
  1385. $parameters['Merchant'] = $request->getMerchant();
  1386. }
  1387. if ($request->isSetFeedTypeList()) {
  1388. $feedTypeList = $request->getFeedTypeList();
  1389. foreach ($feedTypeList->getType() as $typeIndex => $type) {
  1390. $parameters['FeedTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1391. }
  1392. }
  1393. if ($request->isSetFeedProcessingStatusList()) {
  1394. $feedProcessingStatusList = $request->getFeedProcessingStatusList();
  1395. foreach ($feedProcessingStatusList->getStatus() as $statusIndex => $status) {
  1396. $parameters['FeedProcessingStatusList' . '.' . 'Status' . '.' . ($statusIndex + 1)] = $status;
  1397. }
  1398. }
  1399. if ($request->isSetSubmittedFromDate()) {
  1400. $parameters['SubmittedFromDate'] =
  1401. $this->getFormattedTimestamp($request->getSubmittedFromDate());
  1402. }
  1403. if ($request->isSetSubmittedToDate()) {
  1404. $parameters['SubmittedToDate'] =
  1405. $this->getFormattedTimestamp($request->getSubmittedToDate());
  1406. }
  1407. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1408. }
  1409. /**
  1410. * Convert CancelReportRequestsRequest to name value pairs
  1411. */
  1412. private function convertCancelReportRequests($request) {
  1413. $parameters = array();
  1414. $parameters['Action'] = 'CancelReportRequests';
  1415. if ($request->isSetMarketplace()) {
  1416. $parameters['Marketplace'] = $request->getMarketplace();
  1417. }
  1418. if ($request->isSetMerchant()) {
  1419. $parameters['Merchant'] = $request->getMerchant();
  1420. }
  1421. if ($request->isSetReportRequestIdList()) {
  1422. $reportRequestIdList = $request->getReportRequestIdList();
  1423. foreach ($reportRequestIdList->getId() as $idIndex => $id) {
  1424. $parameters['ReportRequestIdList' . '.' . 'Id' . '.' . ($idIndex + 1)] = $id;
  1425. }
  1426. }
  1427. if ($request->isSetReportTypeList()) {
  1428. $reportTypeList = $request->getReportTypeList();
  1429. foreach ($reportTypeList->getType() as $typeIndex => $type) {
  1430. $parameters['ReportTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1431. }
  1432. }
  1433. if ($request->isSetReportProcessingStatusList()) {
  1434. $reportProcessingStatusList = $request->getReportProcessingStatusList();
  1435. foreach ($reportProcessingStatusList->getStatus() as $statusIndex => $status) {
  1436. $parameters['ReportProcessingStatusList' . '.' . 'Status' . '.' . ($statusIndex + 1)] = $status;
  1437. }
  1438. }
  1439. if ($request->isSetRequestedFromDate()) {
  1440. $parameters['RequestedFromDate'] =
  1441. $this->getFormattedTimestamp($request->getRequestedFromDate());
  1442. }
  1443. if ($request->isSetRequestedToDate()) {
  1444. $parameters['RequestedToDate'] =
  1445. $this->getFormattedTimestamp($request->getRequestedToDate());
  1446. }
  1447. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1448. }
  1449. /**
  1450. * Convert GetReportListRequest to name value pairs
  1451. */
  1452. private function convertGetReportList($request) {
  1453. $parameters = array();
  1454. $parameters['Action'] = 'GetReportList';
  1455. if ($request->isSetMarketplace()) {
  1456. $parameters['Marketplace'] = $request->getMarketplace();
  1457. }
  1458. if ($request->isSetMerchant()) {
  1459. $parameters['Merchant'] = $request->getMerchant();
  1460. }
  1461. if ($request->isSetMaxCount()) {
  1462. $parameters['MaxCount'] = $request->getMaxCount();
  1463. }
  1464. if ($request->isSetReportTypeList()) {
  1465. $reportTypeList = $request->getReportTypeList();
  1466. foreach ($reportTypeList->getType() as $typeIndex => $type) {
  1467. $parameters['ReportTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1468. }
  1469. }
  1470. if ($request->isSetAcknowledged()) {
  1471. $parameters['Acknowledged'] = $request->getAcknowledged() ? "true" : "false";
  1472. }
  1473. if ($request->isSetAvailableFromDate()) {
  1474. $parameters['AvailableFromDate'] =
  1475. $this->getFormattedTimestamp($request->getAvailableFromDate());
  1476. }
  1477. if ($request->isSetAvailableToDate()) {
  1478. $parameters['AvailableToDate'] =
  1479. $this->getFormattedTimestamp($request->getAvailableToDate());
  1480. }
  1481. if ($request->isSetReportRequestIdList()) {
  1482. $reportRequestIdList = $request->getReportRequestIdList();
  1483. foreach ($reportRequestIdList->getId() as $idIndex => $id) {
  1484. $parameters['ReportRequestIdList' . '.' . 'Id' . '.' . ($idIndex + 1)] = $id;
  1485. }
  1486. }
  1487. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1488. }
  1489. /**
  1490. * Convert GetFeedSubmissionResultRequest to name value pairs
  1491. */
  1492. private function convertGetFeedSubmissionResult($request) {
  1493. $parameters = array();
  1494. $parameters['Action'] = 'GetFeedSubmissionResult';
  1495. if ($request->isSetMarketplace()) {
  1496. $parameters['Marketplace'] = $request->getMarketplace();
  1497. }
  1498. if ($request->isSetMerchant()) {
  1499. $parameters['Merchant'] = $request->getMerchant();
  1500. }
  1501. if ($request->isSetFeedSubmissionId()) {
  1502. $parameters['FeedSubmissionId'] = $request->getFeedSubmissionId();
  1503. }
  1504. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1505. }
  1506. /**
  1507. * Convert GetFeedSubmissionListRequest to name value pairs
  1508. */
  1509. private function convertGetFeedSubmissionList($request) {
  1510. $parameters = array();
  1511. $parameters['Action'] = 'GetFeedSubmissionList';
  1512. if ($request->isSetMarketplace()) {
  1513. $parameters['Marketplace'] = $request->getMarketplace();
  1514. }
  1515. if ($request->isSetMerchant()) {
  1516. $parameters['Merchant'] = $request->getMerchant();
  1517. }
  1518. if ($request->isSetFeedSubmissionIdList()) {
  1519. $feedSubmissionIdList = $request->getFeedSubmissionIdList();
  1520. foreach ($feedSubmissionIdList->getId() as $idIndex => $id) {
  1521. $parameters['FeedSubmissionIdList' . '.' . 'Id' . '.' . ($idIndex + 1)] = $id;
  1522. }
  1523. }
  1524. if ($request->isSetMaxCount()) {
  1525. $parameters['MaxCount'] = $request->getMaxCount();
  1526. }
  1527. if ($request->isSetFeedTypeList()) {
  1528. $feedTypeList = $request->getFeedTypeList();
  1529. foreach ($feedTypeList->getType() as $typeIndex => $type) {
  1530. $parameters['FeedTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1531. }
  1532. }
  1533. if ($request->isSetFeedProcessingStatusList()) {
  1534. $feedProcessingStatusList = $request->getFeedProcessingStatusList();
  1535. foreach ($feedProcessingStatusList->getStatus() as $statusIndex => $status) {
  1536. $parameters['FeedProcessingStatusList' . '.' . 'Status' . '.' . ($statusIndex + 1)] = $status;
  1537. }
  1538. }
  1539. if ($request->isSetSubmittedFromDate()) {
  1540. $parameters['SubmittedFromDate'] =
  1541. $this->getFormattedTimestamp($request->getSubmittedFromDate());
  1542. }
  1543. if ($request->isSetSubmittedToDate()) {
  1544. $parameters['SubmittedToDate'] =
  1545. $this->getFormattedTimestamp($request->getSubmittedToDate());
  1546. }
  1547. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1548. }
  1549. /**
  1550. * Convert GetReportRequestListRequest to name value pairs
  1551. */
  1552. private function convertGetReportRequestList($request) {
  1553. $parameters = array();
  1554. $parameters['Action'] = 'GetReportRequestList';
  1555. if ($request->isSetMarketplace()) {
  1556. $parameters['Marketplace'] = $request->getMarketplace();
  1557. }
  1558. if ($request->isSetMerchant()) {
  1559. $parameters['Merchant'] = $request->getMerchant();
  1560. }
  1561. if ($request->isSetReportRequestIdList()) {
  1562. $reportRequestIdList = $request->getReportRequestIdList();
  1563. foreach ($reportRequestIdList->getId() as $idIndex => $id) {
  1564. $parameters['ReportRequestIdList' . '.' . 'Id' . '.' . ($idIndex + 1)] = $id;
  1565. }
  1566. }
  1567. if ($request->isSetReportTypeList()) {
  1568. $reportTypeList = $request->getReportTypeList();
  1569. foreach ($reportTypeList->getType() as $typeIndex => $type) {
  1570. $parameters['ReportTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1571. }
  1572. }
  1573. if ($request->isSetReportProcessingStatusList()) {
  1574. $reportProcessingStatusList = $request->getReportProcessingStatusList();
  1575. foreach ($reportProcessingStatusList->getStatus() as $statusIndex => $status) {
  1576. $parameters['ReportProcessingStatusList' . '.' . 'Status' . '.' . ($statusIndex + 1)] = $status;
  1577. }
  1578. }
  1579. if ($request->isSetMaxCount()) {
  1580. $parameters['MaxCount'] = $request->getMaxCount();
  1581. }
  1582. if ($request->isSetRequestedFromDate()) {
  1583. $parameters['RequestedFromDate'] =
  1584. $this->getFormattedTimestamp($request->getRequestedFromDate());
  1585. }
  1586. if ($request->isSetRequestedToDate()) {
  1587. $parameters['RequestedToDate'] =
  1588. $this->getFormattedTimestamp($request->getRequestedToDate());
  1589. }
  1590. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1591. }
  1592. /**
  1593. * Convert GetReportScheduleListByNextTokenRequest to name value pairs
  1594. */
  1595. private function convertGetReportScheduleListByNextToken($request) {
  1596. $parameters = array();
  1597. $parameters['Action'] = 'GetReportScheduleListByNextToken';
  1598. if ($request->isSetMarketplace()) {
  1599. $parameters['Marketplace'] = $request->getMarketplace();
  1600. }
  1601. if ($request->isSetMerchant()) {
  1602. $parameters['Merchant'] = $request->getMerchant();
  1603. }
  1604. if ($request->isSetNextToken()) {
  1605. $parameters['NextToken'] = $request->getNextToken();
  1606. }
  1607. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1608. }
  1609. /**
  1610. * Convert GetReportListByNextTokenRequest to name value pairs
  1611. */
  1612. private function convertGetReportListByNextToken($request) {
  1613. $parameters = array();
  1614. $parameters['Action'] = 'GetReportListByNextToken';
  1615. if ($request->isSetMarketplace()) {
  1616. $parameters['Marketplace'] = $request->getMarketplace();
  1617. }
  1618. if ($request->isSetMerchant()) {
  1619. $parameters['Merchant'] = $request->getMerchant();
  1620. }
  1621. if ($request->isSetNextToken()) {
  1622. $parameters['NextToken'] = $request->getNextToken();
  1623. }
  1624. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1625. }
  1626. /**
  1627. * Convert ManageReportScheduleRequest to name value pairs
  1628. */
  1629. private function convertManageReportSchedule($request) {
  1630. $parameters = array();
  1631. $parameters['Action'] = 'ManageReportSchedule';
  1632. if ($request->isSetMarketplace()) {
  1633. $parameters['Marketplace'] = $request->getMarketplace();
  1634. }
  1635. if ($request->isSetMerchant()) {
  1636. $parameters['Merchant'] = $request->getMerchant();
  1637. }
  1638. if ($request->isSetReportType()) {
  1639. $parameters['ReportType'] = $request->getReportType();
  1640. }
  1641. if ($request->isSetSchedule()) {
  1642. $parameters['Schedule'] = $request->getSchedule();
  1643. }
  1644. if ($request->isSetScheduleDate()) {
  1645. $parameters['ScheduleDate'] =
  1646. $this->getFormattedTimestamp($request->getScheduleDate());
  1647. }
  1648. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1649. }
  1650. /**
  1651. * Convert GetReportRequestCountRequest to name value pairs
  1652. */
  1653. private function convertGetReportRequestCount($request) {
  1654. $parameters = array();
  1655. $parameters['Action'] = 'GetReportRequestCount';
  1656. if ($request->isSetMarketplace()) {
  1657. $parameters['Marketplace'] = $request->getMarketplace();
  1658. }
  1659. if ($request->isSetMerchant()) {
  1660. $parameters['Merchant'] = $request->getMerchant();
  1661. }
  1662. if ($request->isSetReportTypeList()) {
  1663. $reportTypeList = $request->getReportTypeList();
  1664. foreach ($reportTypeList->getType() as $typeIndex => $type) {
  1665. $parameters['ReportTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1666. }
  1667. }
  1668. if ($request->isSetReportProcessingStatusList()) {
  1669. $reportProcessingStatusList = $request->getReportProcessingStatusList();
  1670. foreach ($reportProcessingStatusList->getStatus() as $statusIndex => $status) {
  1671. $parameters['ReportProcessingStatusList' . '.' . 'Status' . '.' . ($statusIndex + 1)] = $status;
  1672. }
  1673. }
  1674. if ($request->isSetRequestedFromDate()) {
  1675. $parameters['RequestedFromDate'] =
  1676. $this->getFormattedTimestamp($request->getRequestedFromDate());
  1677. }
  1678. if ($request->isSetRequestedToDate()) {
  1679. $parameters['RequestedToDate'] =
  1680. $this->getFormattedTimestamp($request->getRequestedToDate());
  1681. }
  1682. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1683. }
  1684. /**
  1685. * Convert GetReportScheduleListRequest to name value pairs
  1686. */
  1687. private function convertGetReportScheduleList($request) {
  1688. $parameters = array();
  1689. $parameters['Action'] = 'GetReportScheduleList';
  1690. if ($request->isSetMarketplace()) {
  1691. $parameters['Marketplace'] = $request->getMarketplace();
  1692. }
  1693. if ($request->isSetMerchant()) {
  1694. $parameters['Merchant'] = $request->getMerchant();
  1695. }
  1696. if ($request->isSetReportTypeList()) {
  1697. $reportTypeList = $request->getReportTypeList();
  1698. foreach ($reportTypeList->getType() as $typeIndex => $type) {
  1699. $parameters['ReportTypeList' . '.' . 'Type' . '.' . ($typeIndex + 1)] = $type;
  1700. }
  1701. }
  1702. return array(CONVERTED_PARAMETERS_KEY => $parameters, CONVERTED_HEADERS_KEY => $this->defaultHeaders);
  1703. }
  1704. }