Completed
Push — master ( 83c463...a53568 )
by Christian
05:34
created

MWSFeeds::parseSubmissionResultResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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)
0 ignored issues
show
Unused Code introduced by
The parameter $documentType is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $amazonOrderId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
        return [
93
            'status_code' => data_get($response, 'Message.ProcessingReport.StatusCode'),
94
            'processing_summary' => data_get($response, 'Message.ProcessingReport.ProcessingSummary'),
95
            'result' => data_get($response, 'Message.ProcessingReport.Result'),
96
        ];
97
    }
98
}
99