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\Service; |
14
|
|
|
|
15
|
|
|
use DateTime; |
16
|
|
|
use Etrias\PaazlConnector\Processor\Processor; |
17
|
|
|
use Etrias\PaazlConnector\ServiceType\Service as GeneralServiceType; |
18
|
|
|
use Etrias\PaazlConnector\StructType\CancelShipmentsRequest; |
19
|
|
|
use Etrias\PaazlConnector\StructType\CancelShipmentsResponse; |
20
|
|
|
use Etrias\PaazlConnector\StructType\DateRangeType; |
21
|
|
|
use Etrias\PaazlConnector\StructType\ExistingLabelType; |
22
|
|
|
use Etrias\PaazlConnector\StructType\OrdersToShipRequest; |
23
|
|
|
use Etrias\PaazlConnector\StructType\OrdersToShipResponse; |
24
|
|
|
use Etrias\PaazlConnector\StructType\ShippingOptionRequest; |
25
|
|
|
use Etrias\PaazlConnector\StructType\ShippingOptionResponse; |
26
|
|
|
use RuntimeException; |
27
|
|
|
|
28
|
|
|
class ShippingService |
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
|
|
|
* @throws RuntimeException |
55
|
|
|
*/ |
56
|
|
|
public function generateShippingManifest() |
57
|
|
|
{ |
58
|
|
|
throw new RuntimeException('Not Implemented'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param DateTime $date |
63
|
|
|
* @param null $targetWebShop |
64
|
|
|
* |
65
|
|
|
* @return OrdersToShipResponse |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public function getOrdersToShip(DateTime $date = null, $targetWebShop = null) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
if ($date === null) { |
70
|
|
|
$date = new DateTime(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$request = new OrdersToShipRequest( |
74
|
|
|
$this->securityService->getHash($date->format('Ymd')), |
75
|
|
|
$this->generalServiceType->getWebShopId(), |
76
|
|
|
$targetWebShop, |
77
|
|
|
$date->format('Y-m-d') |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$response = $this->generalServiceType->ordersToShip($request); |
81
|
|
|
|
82
|
|
|
return $this->processResponse($response, $this->generalServiceType); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param array $barCodes [$orderReference => $barcode] |
87
|
|
|
* @param null $targetWebShop |
88
|
|
|
* |
89
|
|
|
* @return CancelShipmentsResponse |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public function cancelShipments(array $barCodes, $targetWebShop = null) |
92
|
|
|
{ |
93
|
|
|
$labels = []; |
94
|
|
|
|
95
|
|
|
foreach ($barCodes as $orderReference => $barCode) { |
96
|
|
|
$labels[] = new ExistingLabelType( |
97
|
|
|
$this->securityService->getHash($orderReference), |
98
|
|
|
$targetWebShop, |
99
|
|
|
$orderReference, |
100
|
|
|
$barCode |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$request = new CancelShipmentsRequest( |
105
|
|
|
$this->generalServiceType->getWebShopId(), |
106
|
|
|
$labels |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$response = $this->generalServiceType->cancelShipments($request); |
110
|
|
|
|
111
|
|
|
return $this->processResponse($response, $this->generalServiceType); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param $orderReference |
116
|
|
|
* @param DateRangeType|null $deliveryDateRange |
117
|
|
|
* @param string $country |
118
|
|
|
* @param null $postcode |
119
|
|
|
* @param bool $extendedDeliveryDateDetails |
120
|
|
|
* @param null $shippingOption |
121
|
|
|
* @param null $deliveryEstimate |
122
|
|
|
* @param $targetWebShop |
123
|
|
|
* |
124
|
|
|
* @return ShippingOptionResponse |
125
|
|
|
*/ |
126
|
|
|
public function getShippingOptions( |
127
|
|
|
$orderReference, |
128
|
|
|
$country, |
129
|
|
|
DateRangeType $deliveryDateRange = null, |
130
|
|
|
$postcode, |
131
|
|
|
$extendedDeliveryDateDetails, |
|
|
|
|
132
|
|
|
$shippingOption, |
133
|
|
|
$deliveryEstimate, |
134
|
|
|
$targetWebShop |
135
|
|
|
) { |
136
|
|
|
$request = new ShippingOptionRequest( |
137
|
|
|
$this->securityService->getHash($orderReference), |
138
|
|
|
$this->generalServiceType->getWebShopId(), |
139
|
|
|
$targetWebShop, |
140
|
|
|
$orderReference, |
141
|
|
|
$postcode, |
142
|
|
|
$country, |
143
|
|
|
null, |
144
|
|
|
null, |
145
|
|
|
$extendedDeliveryDateDetails, |
146
|
|
|
$shippingOption, |
147
|
|
|
$deliveryEstimate, |
148
|
|
|
$deliveryDateRange |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
$response = $this->generalServiceType->shippingOption($request); |
152
|
|
|
|
153
|
|
|
return $this->processResponse($response, $this->generalServiceType); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.