-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDHL24.php
More file actions
117 lines (106 loc) · 2.75 KB
/
DHL24.php
File metadata and controls
117 lines (106 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace DHL;
use DHL\Structures\AuthData;
use DHL\Structures\ItemToPrint;
use DHL\Structures\ShipmentFullData;
include 'DHL24WebapiClient.php';
include 'Structures/AuthData.php';
include 'Structures/ShipmentFullData.php';
include 'Structures/ItemToPrint.php';
/**
* Class using to create request to API
*/
class DHL24 {
private $__client;
private $__authData;
public function __construct() {
$this->__client = new DHL24WebapiClient();
$this->__authData = new AuthData();
}
/**
* Getting information about current version of API
*
* @return xml
*/
public function getVersion() {
$result = $this->__client->getVersion();
return $result;
}
/**
* Creating shipment in DHL system
*
* @param [date] $shipmentDate
* @return void
*/
public function createShipments($shipmentDate) {
$shipments = new ShipmentFullData();
$params = [
'authData' => $this->__authData->getAuthData(),
'shipments' => $shipments->getShipmentFullData($shipmentDate)
];
$this->__client->createShipments($params);
$this->__saveFiles();
}
/**
* Getting waybill and thermal labels from API
*
* @param [date] $shipmentId
* @param [string] $type
* @return void
*/
public function getLabels($shipmentId, $type) {
$itemToPrint = new ItemToPrint();
$params = [
'authData' => $this->__authData->getAuthData(),
'itemsToPrint' => $itemToPrint->getItemToPrint($shipmentId, $type)
];
$result = $this->__client->getLabels($params);
$this->__saveLabels($result, $type);
}
/**
* Booking courier for shipment pickup
*
* @param [int] $shipmentId
* @param [date] $shipmentDate
* @return void
*/
public function bookCourier($shipmentId, $shipmentDate) {
$params = [
'authData' => $this->__authData->getAuthData(),
'pickupDate' => $shipmentDate,
'pickupTimeFrom' => '10:00',
'pickupTimeTo' => '16:00',
'shipmentIdList' => [
$shipmentId
]
];
$this->__client->bookCourier($params);
$this->__saveFiles();
}
/**
* Saving requests and responses from API to .xml files
*
* @return void
*/
private function __saveFiles() {
$time_stamp = time();
file_put_contents('requests/' . 'request_' . $time_stamp . '.xml', $this->__client->__getLastRequest());
file_put_contents('requests/' . 'response_' . $time_stamp . '.xml', $this->__client->__getLastResponse());
}
/**
* Saving waybill and thermal labels from API to files with label type extension
*
* @param [xml] $data
* @param [string] $type
* @return void
*/
private function __saveLabels($data, $type) {
if($type == 'protocol')
$labels = $data->getLabelsResult;
else
$labels = $data->getLabelsResult->item;
foreach ($labels as $label) {
file_put_contents('labels/' . $label->labelName, base64_decode($label->labelData));
}
}
}