|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Etrias\EwarehousingConnector\Services; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Etrias\EwarehousingConnector\Client\EwarehousingClient; |
|
8
|
|
|
use Etrias\EwarehousingConnector\Response\DocumentResponse; |
|
9
|
|
|
use Etrias\EwarehousingConnector\Response\SuccessResponse; |
|
10
|
|
|
use Etrias\EwarehousingConnector\Serializer\ServiceTrait; |
|
11
|
|
|
use GuzzleHttp\RequestOptions; |
|
12
|
|
|
use JMS\Serializer\SerializerInterface; |
|
13
|
|
|
|
|
14
|
|
|
class DocumentService implements DocumentServiceInterface |
|
15
|
|
|
{ |
|
16
|
|
|
use ServiceTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var EwarehousingClient |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $client; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var SerializerInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $serializer; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* OrderService constructor. |
|
29
|
|
|
* |
|
30
|
|
|
* @param EwarehousingClient $client |
|
31
|
|
|
* @param SerializerInterface $serializer |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(EwarehousingClient $client, SerializerInterface $serializer) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->client = $client; |
|
36
|
|
|
$this->serializer = $serializer; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $reference |
|
41
|
|
|
* |
|
42
|
|
|
* @return DocumentResponse[] |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getAll($reference) |
|
45
|
|
|
{ |
|
46
|
|
|
$data = [ |
|
47
|
|
|
'reference' => $reference |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
$guzzleResponse = $this->client->get('1/documents/order', [RequestOptions::QUERY => $data]); |
|
51
|
|
|
|
|
52
|
|
|
return $this->deserializeResponse($guzzleResponse, 'array<'.DocumentResponse::class.'>'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
* |
|
58
|
|
|
* @return SuccessResponse; |
|
59
|
|
|
*/ |
|
60
|
|
|
public function add( |
|
61
|
|
|
$reference, |
|
62
|
|
|
$fileContent, |
|
63
|
|
|
$fileName = null, |
|
64
|
|
|
$quantityToPrint = null, |
|
65
|
|
|
$isShippingLabel = false |
|
66
|
|
|
) { |
|
67
|
|
|
|
|
68
|
|
|
if ($fileName === null) { |
|
69
|
|
|
$fileName = $reference.'.pdf'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$data = [ |
|
73
|
|
|
[ |
|
74
|
|
|
'name' => 'shippingLabel', |
|
75
|
|
|
'contents' => (int) $isShippingLabel |
|
76
|
|
|
], |
|
77
|
|
|
[ |
|
78
|
|
|
'name' => 'file', |
|
79
|
|
|
'contents' => $fileContent, |
|
80
|
|
|
'filename' => $fileName |
|
81
|
|
|
] |
|
82
|
|
|
]; |
|
83
|
|
|
|
|
84
|
|
|
if (is_numeric($quantityToPrint)) { |
|
85
|
|
|
$data[] = [ |
|
86
|
|
|
'name' => 'quantity', |
|
87
|
|
|
'contents' => $quantityToPrint |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$guzzleResponse = $this->client->post( |
|
92
|
|
|
'/1/orders/document/'.$reference, |
|
93
|
|
|
[ |
|
94
|
|
|
RequestOptions::MULTIPART => $data |
|
95
|
|
|
] |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
return $this->deserializeResponse($guzzleResponse, SuccessResponse::class); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param string $documentId |
|
103
|
|
|
* |
|
104
|
|
|
* @return SuccessResponse |
|
105
|
|
|
*/ |
|
106
|
|
|
public function delete($documentId) |
|
107
|
|
|
{ |
|
108
|
|
|
$guzzleResponse = $this->client->get( |
|
109
|
|
|
'/1/documents/delete/'.$documentId |
|
110
|
|
|
); |
|
111
|
|
|
|
|
112
|
|
|
return $this->deserializeResponse($guzzleResponse, SuccessResponse::class); |
|
113
|
|
|
} |
|
114
|
|
|
} |