1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DPD\Interconnector; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client as GuzzleClient; |
6
|
|
|
use Psr\Http\Message\ResponseInterface; |
7
|
|
|
use DPD\Interconnector\Request\LabelsRequest; |
8
|
|
|
use DPD\Interconnector\Request\ManifestRequest; |
9
|
|
|
use DPD\Interconnector\Request\ShipmentRequest; |
10
|
|
|
use DPD\Interconnector\Request\DeleteShipmentRequest; |
11
|
|
|
|
12
|
|
|
class Client extends GuzzleClient |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* test endpoint for Estonia |
16
|
|
|
*/ |
17
|
|
|
const EE_TEST_ENDPOINT_URL = 'https://ee.integration.dpd.eo.pl/ws-mapper-rest/'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* production endpoint for Estonia |
21
|
|
|
*/ |
22
|
|
|
const EE_PRODUCTION_ENDPOINT_URL = 'https://integration.dpd.ee:8443/ws-mapper-rest/'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* test endpoint for Latvia |
26
|
|
|
*/ |
27
|
|
|
const LV_TEST_ENDPOINT_URL = 'https://lv.integration.dpd.eo.pl/ws-mapper-rest/'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* production endpoint for Latvia |
31
|
|
|
*/ |
32
|
|
|
const LV_PRODUCTION_ENDPOINT_URL = 'https://integration.dpd.lv:8443/ws-mapper-rest/'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* test endpoint for Lithuania |
36
|
|
|
*/ |
37
|
|
|
const LT_TEST_ENDPOINT_URL = 'https://lt.integration.dpd.eo.pl/ws-mapper-rest/'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* production endpoint for Lithuania |
41
|
|
|
*/ |
42
|
|
|
const LT_PRODUCTION_ENDPOINT_URL = 'https://integracijos.dpd.lt/ws-mapper-rest/'; |
43
|
|
|
|
44
|
|
|
public function createShipment(ShipmentRequest $shipment): ResponseInterface |
45
|
|
|
{ |
46
|
|
|
return $this->request( |
47
|
|
|
'POST', |
48
|
|
|
$this->getEndpointUrl($shipment->getCountry()) . '/createShipment_', |
49
|
|
|
[ |
50
|
|
|
'form_params' => $shipment->toArray(), |
51
|
|
|
'verify' => false |
52
|
|
|
] |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getLabels(LabelsRequest $request): ResponseInterface |
57
|
|
|
{ |
58
|
|
|
return $this->request( |
59
|
|
|
'POST', |
60
|
|
|
$this->getEndpointUrl($request->getCountry()) . '/parcelPrint_', |
61
|
|
|
[ |
62
|
|
|
'form_params' => $request->toArray(), |
63
|
|
|
'verify' => false |
64
|
|
|
] |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getManifest(ManifestRequest $request): ResponseInterface |
69
|
|
|
{ |
70
|
|
|
return $this->request( |
71
|
|
|
'POST', |
72
|
|
|
$this->getEndpointUrl($request->getCountry()) . '/parcelManifestPrint_', |
73
|
|
|
[ |
74
|
|
|
'form_params' => $request->toArray(), |
75
|
|
|
'verify' => false |
76
|
|
|
] |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function removeShipment(DeleteShipmentRequest $request): ResponseInterface |
81
|
|
|
{ |
82
|
|
|
return $this->request( |
83
|
|
|
'POST', |
84
|
|
|
$this->getEndpointUrl($request->getCountry()) . '/parcelDelete_', |
85
|
|
|
[ |
86
|
|
|
'form_params' => $request->toArray(), |
87
|
|
|
'verify' => false |
88
|
|
|
] |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
private function getEndpointUrl(string $country) |
93
|
|
|
{ |
94
|
|
|
switch ($country) { |
95
|
|
|
case 'LT': |
96
|
|
|
return self::LT_PRODUCTION_ENDPOINT_URL; |
97
|
|
|
case 'LV': |
98
|
|
|
return self::LV_PRODUCTION_ENDPOINT_URL; |
99
|
|
|
case 'EE': |
100
|
|
|
default: |
101
|
|
|
return self::EE_PRODUCTION_ENDPOINT_URL; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |