1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Looxis\LaravelAmazonMWS; |
4
|
|
|
|
5
|
|
|
class MWSFeeds |
6
|
|
|
{ |
7
|
|
|
const VERSION = '2009-01-01'; |
8
|
|
|
|
9
|
|
|
protected $client; |
10
|
|
|
protected $content; |
11
|
|
|
protected $type; |
12
|
|
|
protected $params = []; |
13
|
|
|
|
14
|
|
|
public function __construct(MWSClient $client) |
15
|
|
|
{ |
16
|
|
|
$this->client = $client; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function getContent() |
20
|
|
|
{ |
21
|
|
|
return $this->content; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function setParams($params) |
25
|
|
|
{ |
26
|
|
|
$this->params = $params; |
27
|
|
|
|
28
|
|
|
return $this; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getParams() |
32
|
|
|
{ |
33
|
|
|
return $this->params; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function setContent($content) |
37
|
|
|
{ |
38
|
|
|
$this->content = $content; |
39
|
|
|
|
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getType() |
44
|
|
|
{ |
45
|
|
|
return $this->type; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function setType($type) |
49
|
|
|
{ |
50
|
|
|
$this->type = $type; |
51
|
|
|
|
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function submit($purgeAndReplace = false, $amazonOrderId = null, $documentType = null) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$contentmd5Hash = base64_encode(md5($this->getContent(), true)); |
58
|
|
|
$params = array_merge([ |
59
|
|
|
'FeedType' => $this->type, |
60
|
|
|
'PurgeAndReplace' => $purgeAndReplace, |
61
|
|
|
'ContentMD5Value' => $contentmd5Hash, |
62
|
|
|
], $this->getParams()); |
63
|
|
|
$response = $this->client->post('SubmitFeed', '/', self::VERSION, $params, $this->getContent()); |
64
|
|
|
|
65
|
|
|
return $this->parseSubmitFeedResponse($response); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function parseSubmitFeedResponse($response) |
69
|
|
|
{ |
70
|
|
|
$requestId = data_get($response, 'ResponseMetadata.RequestId'); |
71
|
|
|
$feed = data_get($response, 'SubmitFeedResult.FeedSubmissionInfo'); |
72
|
|
|
|
73
|
|
|
return [ |
74
|
|
|
'request_id' => $requestId, |
75
|
|
|
'data' => $feed, |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getFeedSubmissionResult($amazonFeedSubmissionId) |
80
|
|
|
{ |
81
|
|
|
$params = [ |
82
|
|
|
'FeedSubmissionId' => $amazonFeedSubmissionId, |
83
|
|
|
]; |
84
|
|
|
|
85
|
|
|
$response = $this->client->post('GetFeedSubmissionResult', '/', self::VERSION, $params); |
86
|
|
|
|
87
|
|
|
return $this->parseSubmissionResultResponse($response); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function parseSubmissionResultResponse($response) |
91
|
|
|
{ |
92
|
|
|
if (is_null(data_get($response, 'Message.ProcessingReport.StatusCode'))) { |
93
|
|
|
return (string) $response; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return [ |
97
|
|
|
'status_code' => data_get($response, 'Message.ProcessingReport.StatusCode'), |
98
|
|
|
'processing_summary' => data_get($response, 'Message.ProcessingReport.ProcessingSummary'), |
99
|
|
|
'result' => data_get($response, 'Message.ProcessingReport.Result'), |
100
|
|
|
]; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.