|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of PHP CS Fixer. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
|
7
|
|
|
* Dariusz Rumiński <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This source file is subject to the MIT license that is bundled |
|
10
|
|
|
* with this source code in the file LICENSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Etrias\EwarehousingConnector\Services; |
|
14
|
|
|
|
|
15
|
|
|
use DateTime; |
|
16
|
|
|
use Etrias\EwarehousingConnector\Client\EwarehousingClient; |
|
17
|
|
|
use Etrias\EwarehousingConnector\Response\InboundResponse; |
|
18
|
|
|
use Etrias\EwarehousingConnector\Response\SuccessResponse; |
|
19
|
|
|
use Etrias\EwarehousingConnector\Serializer\ServiceTrait; |
|
20
|
|
|
use GuzzleHttp\RequestOptions; |
|
21
|
|
|
use JMS\Serializer\SerializerInterface; |
|
22
|
|
|
|
|
23
|
|
|
class InboundService implements InboundServiceInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use ServiceTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** @var EwarehousingClient */ |
|
28
|
|
|
protected $client; |
|
29
|
|
|
|
|
30
|
|
|
/** @var SerializerInterface */ |
|
31
|
|
|
protected $serializer; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* OrderService constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param EwarehousingClient $client |
|
37
|
|
|
* @param SerializerInterface $serializer |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(EwarehousingClient $client, SerializerInterface $serializer) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->client = $client; |
|
42
|
|
|
$this->serializer = $serializer; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
* |
|
48
|
|
|
* @return InboundResponse[] |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getListing( |
|
51
|
|
|
DateTime $from = null, |
|
52
|
|
|
DateTime $to = null, |
|
53
|
|
|
$page = 1, |
|
54
|
|
|
$sort = null, |
|
55
|
|
|
$direction = null |
|
56
|
|
|
) { |
|
57
|
|
|
$data = [ |
|
58
|
|
|
'from' => $from ? $from->format('Y-m-d') : null, |
|
59
|
|
|
'to' => $to ? $to->format('Y-m-d') : null, |
|
60
|
|
|
'page' => $page, |
|
61
|
|
|
'sort' => $sort, |
|
62
|
|
|
'direction' => $direction, |
|
63
|
|
|
]; |
|
64
|
|
|
|
|
65
|
|
|
$guzzleResponse = $this->client->get('2/inbound', [RequestOptions::QUERY => $data]); |
|
66
|
|
|
|
|
67
|
|
|
return $this->deserializeResponse($guzzleResponse, 'array<'.InboundResponse::class.'>'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
* |
|
73
|
|
|
* @return SuccessResponse |
|
74
|
|
|
*/ |
|
75
|
|
|
public function createInbound($reference, array $lines) |
|
76
|
|
|
{ |
|
77
|
|
|
$data = [ |
|
78
|
|
|
'reference' => $reference, |
|
79
|
|
|
'lines' => json_decode($this->serializer->serialize($lines, 'json'), true), |
|
80
|
|
|
]; |
|
81
|
|
|
|
|
82
|
|
|
$guzzleResponse = $this->client->post('2/inbound/create', [RequestOptions::FORM_PARAMS => $data]); |
|
83
|
|
|
|
|
84
|
|
|
return $this->deserializeResponse($guzzleResponse, SuccessResponse::class); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|