|
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\PaazlConnector\Services; |
|
14
|
|
|
|
|
15
|
|
|
use Etrias\PaazlConnector\Processor\Processor; |
|
16
|
|
|
use Etrias\PaazlConnector\ServiceType\Service as GeneralServiceType; |
|
17
|
|
|
use Etrias\PaazlConnector\StructType\AddressRequest; |
|
18
|
|
|
use Etrias\PaazlConnector\StructType\AddressResponse; |
|
19
|
|
|
use Etrias\PaazlConnector\StructType\CoordinatesType; |
|
20
|
|
|
use Etrias\PaazlConnector\StructType\DeliveryEstimateRequest; |
|
21
|
|
|
use Etrias\PaazlConnector\StructType\DeliveryEstimateResponse; |
|
22
|
|
|
use Etrias\PaazlConnector\StructType\RateRequest; |
|
23
|
|
|
use Etrias\PaazlConnector\StructType\RateResponse; |
|
24
|
|
|
use Etrias\PaazlConnector\StructType\ServicePointsRequest; |
|
25
|
|
|
use Etrias\PaazlConnector\StructType\ServicePointsResponse; |
|
26
|
|
|
use RuntimeException; |
|
27
|
|
|
|
|
28
|
|
|
class ListService |
|
29
|
|
|
{ |
|
30
|
|
|
use Processor; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var SecurityServiceInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $securityService; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var GeneralServiceType |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $generalServiceType; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* DocumentService constructor. |
|
43
|
|
|
* |
|
44
|
|
|
* @param GeneralServiceType $generalServiceType |
|
45
|
|
|
* @param SecurityServiceInterface $securityService |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(GeneralServiceType $generalServiceType, SecurityServiceInterface $securityService) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->securityService = $securityService; |
|
50
|
|
|
$this->generalServiceType = $generalServiceType; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param $orderReference |
|
55
|
|
|
* @param $zipCode |
|
56
|
|
|
* @param $houseNumber |
|
57
|
|
|
* @param null $addition |
|
58
|
|
|
* @param null $targetWebShop |
|
59
|
|
|
* |
|
60
|
|
|
* @return AddressResponse |
|
61
|
|
|
*/ |
|
62
|
|
View Code Duplication |
public function getAddress($orderReference, $zipCode, $houseNumber, $addition = null, $targetWebShop = null) |
|
63
|
|
|
{ |
|
64
|
|
|
$request = new AddressRequest( |
|
65
|
|
|
$this->securityService->getHash($orderReference), |
|
66
|
|
|
$this->generalServiceType->getWebShopId(), |
|
67
|
|
|
$targetWebShop, |
|
68
|
|
|
$orderReference, |
|
69
|
|
|
$zipCode, |
|
70
|
|
|
$houseNumber, |
|
71
|
|
|
$addition |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$response = $this->generalServiceType->address($request); |
|
75
|
|
|
|
|
76
|
|
|
return $this->processResponse($response, $this->generalServiceType); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param $orderReference |
|
81
|
|
|
* @param $weight |
|
82
|
|
|
* @param $value |
|
83
|
|
|
* @param $valueCurrency |
|
84
|
|
|
* @param $consigneeCountry |
|
85
|
|
|
* @param $consigneeCity |
|
86
|
|
|
* @param $consigneePostcode |
|
87
|
|
|
* @param null $shippingOption |
|
88
|
|
|
* @param null $senderCountry |
|
89
|
|
|
* @param null $senderCity |
|
90
|
|
|
* @param null $senderPostcode |
|
91
|
|
|
* @param null $targetWebShop |
|
92
|
|
|
* |
|
93
|
|
|
* @return DeliveryEstimateResponse |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getDeliveryEstimate( |
|
96
|
|
|
$orderReference, |
|
97
|
|
|
$weight, |
|
98
|
|
|
$value, |
|
99
|
|
|
$valueCurrency, |
|
100
|
|
|
$consigneeCountry, |
|
101
|
|
|
$consigneeCity, |
|
102
|
|
|
$consigneePostcode, |
|
103
|
|
|
$shippingOption = null, |
|
104
|
|
|
$senderCountry = null, |
|
105
|
|
|
$senderCity = null, |
|
106
|
|
|
$senderPostcode = null, |
|
107
|
|
|
$targetWebShop = null) |
|
108
|
|
|
{ |
|
109
|
|
|
$request = new DeliveryEstimateRequest( |
|
110
|
|
|
$this->securityService->getHash($orderReference), |
|
111
|
|
|
$this->generalServiceType->getWebShopId(), |
|
112
|
|
|
$targetWebShop, |
|
113
|
|
|
$orderReference, |
|
114
|
|
|
$shippingOption, |
|
115
|
|
|
$weight, |
|
116
|
|
|
$value, |
|
117
|
|
|
$valueCurrency, |
|
118
|
|
|
$senderCountry, |
|
119
|
|
|
$senderCity, |
|
120
|
|
|
$senderPostcode, |
|
121
|
|
|
$consigneeCountry, |
|
122
|
|
|
$consigneeCity, |
|
123
|
|
|
$consigneePostcode |
|
124
|
|
|
); |
|
125
|
|
|
|
|
126
|
|
|
$response = $this->generalServiceType->deliveryEstimate($request); |
|
127
|
|
|
|
|
128
|
|
|
return $this->processResponse($response, $this->generalServiceType); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param $orderReference |
|
133
|
|
|
* @param null $country |
|
134
|
|
|
* @param null $postalCode |
|
135
|
|
|
* @param null $shippingOption |
|
136
|
|
|
* @param null $targetWebShop |
|
137
|
|
|
* |
|
138
|
|
|
* @return RateResponse |
|
139
|
|
|
*/ |
|
140
|
|
View Code Duplication |
public function getRates($orderReference, $country = null, $postalCode = null, $shippingOption = null, $targetWebShop = null) |
|
141
|
|
|
{ |
|
142
|
|
|
$request = new RateRequest( |
|
143
|
|
|
$this->securityService->getHash($orderReference), |
|
144
|
|
|
$this->generalServiceType->getWebShopId(), |
|
145
|
|
|
$targetWebShop, |
|
146
|
|
|
$orderReference, |
|
147
|
|
|
$country, |
|
148
|
|
|
$postalCode, |
|
149
|
|
|
$shippingOption |
|
150
|
|
|
); |
|
151
|
|
|
$response = $this->generalServiceType->rate($request); |
|
152
|
|
|
|
|
153
|
|
|
return $this->processResponse($response, $this->generalServiceType); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param null $country |
|
158
|
|
|
* @param null $postcode |
|
159
|
|
|
* @param CoordinatesType|null $southWest |
|
160
|
|
|
* @param CoordinatesType|null $northEast |
|
161
|
|
|
* @param null $limit |
|
162
|
|
|
* @param null $shippingOption |
|
163
|
|
|
* @param null $evening |
|
164
|
|
|
* @param null $weekend |
|
165
|
|
|
* @param null $targetWebShop |
|
166
|
|
|
* |
|
167
|
|
|
* @return ServicePointsResponse |
|
168
|
|
|
*/ |
|
169
|
|
|
public function getServicePoints( |
|
170
|
|
|
$country = null, |
|
171
|
|
|
$postcode = null, |
|
172
|
|
|
CoordinatesType $southWest = null, |
|
173
|
|
|
CoordinatesType $northEast = null, |
|
174
|
|
|
$limit = null, |
|
175
|
|
|
$shippingOption = null, |
|
176
|
|
|
$evening = null, |
|
177
|
|
|
$weekend = null, |
|
178
|
|
|
$targetWebShop = null |
|
179
|
|
|
) { |
|
180
|
|
|
$hashInput = ''; |
|
181
|
|
|
|
|
182
|
|
|
if ($country !== null) { |
|
183
|
|
|
$hashInput .= $country; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
if ($postcode !== null) { |
|
187
|
|
|
$hashInput .= $postcode; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
if ($southWest !== null) { |
|
191
|
|
|
throw new RuntimeException('Not yet implemented'); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
if ($northEast !== null) { |
|
195
|
|
|
throw new RuntimeException('Not yet implemented'); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
$request = new ServicePointsRequest( |
|
199
|
|
|
$this->securityService->getHash($hashInput), |
|
200
|
|
|
$this->generalServiceType->getWebShopId(), |
|
201
|
|
|
$targetWebShop, |
|
202
|
|
|
$shippingOption, |
|
203
|
|
|
$evening, |
|
204
|
|
|
$weekend, |
|
205
|
|
|
$country, |
|
206
|
|
|
$postcode, |
|
207
|
|
|
$limit, |
|
208
|
|
|
$southWest, |
|
209
|
|
|
$northEast |
|
210
|
|
|
); |
|
211
|
|
|
|
|
212
|
|
|
$response = $this->generalServiceType->servicePoints($request); |
|
213
|
|
|
|
|
214
|
|
|
return $this->processResponse($response, $this->generalServiceType); |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|