Skip to content

Commit d497aae

Browse files
authored
Merge pull request #371 from DiamondLightSource/pre-release/2022-R5.1
Merge 2022-R5.1 into master
2 parents 1de2a09 + a25e608 commit d497aae

File tree

2 files changed

+38
-41
lines changed

2 files changed

+38
-41
lines changed

api/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
"repositories": [
1111
{
1212
"type": "github",
13-
"url": "https://github.com/stufisher/DHL-API.git"
13+
"url": "https://github.com/mattprit/dhl-api.git"
1414
}
1515
],
1616
"require": {
17-
"alfallouji/dhl_api": "dev-master#8a1699a5",
1817
"apereo/phpcas": "1.3.8",
1918
"ezyang/htmlpurifier": "4.12.0",
2019
"firebase/php-jwt": "2.2.0",
@@ -25,7 +24,8 @@
2524
"slim/slim": "2.4.3",
2625
"stomp-php/stomp-php": "3.0.6",
2726
"symfony/http-foundation": "^2.8",
28-
"symfony/filesystem": "^2.8"
27+
"symfony/filesystem": "^2.8",
28+
"mtcmedia/dhl-api": "dev-master#9b4b6315"
2929
},
3030
"autoload": {
3131
"psr-4": {

api/src/Shipment/Courier/DHL.php

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
namespace SynchWeb\Shipment\Courier;
44

5-
use DHL\Client\Web as WebserviceClient;
6-
use DHL\Datatype\AM\PieceType;
7-
use DHL\Datatype\GB\Piece;
8-
use DHL\Entity\AM\GetQuote;
9-
use DHL\Entity\GB\BookPURequest;
10-
use DHL\Entity\GB\BookPUResponse;
11-
use DHL\Entity\GB\CancelPURequest;
12-
use DHL\Entity\GB\CancelPUResponse;
13-
use DHL\Entity\GB\KnownTrackingRequest as Tracking;
14-
use DHL\Entity\GB\ShipmentRequest;
15-
use DHL\Entity\GB\ShipmentResponse;
5+
use Mtc\Dhl\Client\Web as DHLWebClient;
6+
use Mtc\Dhl\Datatype\AM\PieceType;
7+
use Mtc\Dhl\Datatype\EU\Piece;
8+
use Mtc\Dhl\Entity\AM\GetQuote;
9+
use Mtc\Dhl\Entity\EU\BookPURequest;
10+
use Mtc\Dhl\Entity\EU\BookPUResponse;
11+
use Mtc\Dhl\Entity\EU\CancelPURequest;
12+
use Mtc\Dhl\Entity\EU\CancelPUResponse;
13+
use Mtc\Dhl\Entity\EU\ShipmentRequest;
14+
use Mtc\Dhl\Entity\EU\ShipmentResponse;
15+
use Mtc\Dhl\Entity\EU\KnownTrackingRequest;
1616

1717
class DHL
1818
{
@@ -107,7 +107,7 @@ function get_tracking_info($options)
107107
{
108108
if (!array_key_exists('AWB', $options)) return;
109109

110-
$request = new Tracking();
110+
$request = new KnownTrackingRequest();
111111
$request->SiteID = $this->_user;
112112
$request->Password = $this->_password;
113113
$request->MessageReference = '12345678901234567890' . (string)time();
@@ -119,7 +119,7 @@ function get_tracking_info($options)
119119

120120
if ($this->log) file_put_contents('logs/trackingrequest_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['AWB'] . '.xml'), $request->toXML());
121121

122-
$client = new WebserviceClient($this->env);
122+
$client = new DHLWebClient($this->env);
123123
$xml = $client->call($request);
124124

125125
if ($this->log) file_put_contents('logs/trackingresponse_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['AWB'] . '.xml'), $xml);
@@ -130,6 +130,8 @@ function get_tracking_info($options)
130130

131131
function create_awb($options)
132132
{
133+
global $synchweb_version;
134+
133135
$shipment = new ShipmentRequest();
134136
$shipment->SiteID = $this->_user;
135137
$shipment->Password = $this->_password;
@@ -139,21 +141,21 @@ function create_awb($options)
139141
$shipment->RegionCode = $this->region;
140142
$shipment->RequestedPickupTime = 'Y';
141143
$shipment->LanguageCode = 'en';
142-
$shipment->PiecesEnabled = 'Y';
144+
$shipment->SoftwareName = 'Synchweb';
145+
$shipment->SoftwareVersion = (isset($synchweb_version)) ? $synchweb_version : '4.0';
143146
$shipment->Billing->ShippingPaymentType = $options['payee'];
144147
$shipment->Billing->ShipperAccountNumber = $options['accountnumber'];
145148
if ($options['payee'] != 'S') {
146149
$shipment->Billing->BillingAccountNumber = $options['accountnumber'];
147150
}
148-
$shipment->Billing->DutyPaymentType = 'R';
149-
150-
$shipment->Dutiable->DeclaredValue = $options['declaredvalue'];
151-
$shipment->Dutiable->DeclaredCurrency = 'GBP';
152151

153152
$shipment->Consignee->CompanyName = $options['receiver']['company'];
154-
foreach (split("\n", $options['receiver']['address']) as $l) {
155-
if ($l) $shipment->Consignee->addAddressLine($l);
156-
}
153+
154+
$reciever_address_lines = explode(PHP_EOL, rtrim($options['receiver']['address']));
155+
if (isset($reciever_address_lines[0])) $shipment->Consignee->addAddressLine1($reciever_address_lines[0]);
156+
if (isset($reciever_address_lines[1])) $shipment->Consignee->addAddressLine2($reciever_address_lines[1]);
157+
if (isset($reciever_address_lines[2])) $shipment->Consignee->addAddressLine3($reciever_address_lines[2]);
158+
157159
$shipment->Consignee->City = $options['receiver']['city'];
158160
$shipment->Consignee->PostalCode = $options['receiver']['postcode'];
159161
$shipment->Consignee->CountryName = $options['receiver']['country'];
@@ -162,22 +164,17 @@ function create_awb($options)
162164
$shipment->Consignee->Contact->PhoneNumber = $options['receiver']['phone'];
163165
$shipment->Consignee->Contact->Email = $options['receiver']['email'];
164166

165-
$shipment->ShipmentDetails->NumberOfPieces = sizeof($options['pieces']);
166167
$shipment->ShipmentDetails->WeightUnit = 'K';
167168
$shipment->ShipmentDetails->GlobalProductCode = $options['service'];
168169
$shipment->ShipmentDetails->Date = array_key_exists('date', $options) ? $options['date'] : date('Y-m-d');
169170
$shipment->ShipmentDetails->Contents = $options['description'];
170171
$shipment->ShipmentDetails->DimensionUnit = 'C';
171172
$shipment->ShipmentDetails->CurrencyCode = 'GBP';
172-
$shipment->ShipmentDetails->DoorTo = 'DD';
173-
// $shipment->ShipmentDetails->IsDutiable = 'Y';
174173

175174
if (array_key_exists('notification', $options)) $shipment->Notification->EmailAddress = $options['notification'];
176175
if (array_key_exists('message', $options)) $shipment->Notification->Message = $options['message'];
177176

178-
$weight = 0;
179177
foreach ($options['pieces'] as $i => $d) {
180-
$weight += $d['weight'];
181178

182179
$piece = new Piece();
183180
$piece->PieceID = ($i + 1);
@@ -188,13 +185,14 @@ function create_awb($options)
188185
$shipment->ShipmentDetails->addPiece($piece);
189186
}
190187

191-
$shipment->ShipmentDetails->Weight = $weight;
192-
193188
$shipment->Shipper->ShipperID = (string)rand(10000000, 9999999);
194189
$shipment->Shipper->CompanyName = $options['sender']['company'];
195-
foreach (split("\n", $options['sender']['address']) as $l) {
196-
if ($l) $shipment->Shipper->addAddressLine($l);
197-
}
190+
191+
$shipper_address_lines = explode(PHP_EOL, rtrim($options['sender']['address']));
192+
if (isset($shipper_address_lines[0])) $shipment->Shipper->addAddressLine1($shipper_address_lines[0]);
193+
if (isset($shipper_address_lines[1])) $shipment->Shipper->addAddressLine2($shipper_address_lines[1]);
194+
if (isset($shipper_address_lines[2])) $shipment->Shipper->addAddressLine3($shipper_address_lines[2]);
195+
198196
$shipment->Shipper->City = $options['sender']['city'];
199197
$shipment->Shipper->PostalCode = $options['sender']['postcode'];
200198
$shipment->Shipper->CountryCode = $this->_country_codes[$options['sender']['country']];
@@ -207,14 +205,13 @@ function create_awb($options)
207205

208206
if ($this->log) file_put_contents('logs/shipmentrequest_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['sender']['name'] . '.xml'), $shipment->toXML());
209207

210-
$client = new WebserviceClient($this->env);
208+
$client = new DHLWebClient($this->env);
211209
$xml = $client->call($shipment);
212210

213211
if ($this->log) file_put_contents('logs/shipmentresponse_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['sender']['name'] . '.xml'), $xml);
214212

215213
$response = new ShipmentResponse();
216214
$response->initFromXML($xml);
217-
// echo $response->toXML();
218215

219216
$pieces = array();
220217
foreach ($response->Pieces as $p) {
@@ -276,14 +273,13 @@ function request_pickup($options)
276273

277274
if ($this->log) file_put_contents('logs/pickuprequest_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['requestor']['name'] . '.xml'), $pickup->toXML());
278275

279-
$client = new WebserviceClient($this->env);
276+
$client = new DHLWebClient($this->env);
280277
$xml = $client->call($pickup);
281278

282279
if ($this->log) file_put_contents('logs/pickupresponse_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['requestor']['name'] . '.xml'), $xml);
283280

284281
$response = new BookPUResponse();
285282
$response->initFromXML($xml);
286-
// echo $response->toXML();
287283

288284
return array(
289285
'confirmationnumber' => $response->ConfirmationNumber,
@@ -312,14 +308,13 @@ function cancel_pickup($options)
312308

313309
if ($this->log) file_put_contents('logs/cancelpickuprequest_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['confirmationnumber'] . '.xml'), $cancelpickup->toXML());
314310

315-
$client = new WebserviceClient($this->env);
311+
$client = new DHLWebClient($this->env);
316312
$xml = $client->call($cancelpickup);
317313

318314
if ($this->log) file_put_contents('logs/cancelpickupresponse_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['confirmationnumber'] . '.xml'), $xml);
319315

320316
$response = new CancelPUResponse();
321317
$response->initFromXML($xml);
322-
// echo $response->toXML();
323318

324319
return array();
325320
}
@@ -364,7 +359,7 @@ function get_quote($options)
364359

365360
if ($this->log) file_put_contents('logs/quoterequest_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['sender']['city'] . '.xml'), $quote->toXML());
366361

367-
$client = new WebserviceClient($this->env);
362+
$client = new DHLWebClient($this->env);
368363
$xml = $client->call($quote);
369364

370365
if ($this->log) file_put_contents('logs/quoteresponse_' . date('Ymd-Hi') . '_' . str_replace(' ', '_', $options['sender']['city'] . '.xml'), $xml);
@@ -382,6 +377,8 @@ function get_quote($options)
382377
$del = explode('-', (string)$q->DeliveryDate);
383378

384379
$code = (string)$q->GlobalProductCode;
380+
381+
// Skip over medical express
385382
if ($code == 'C') continue;
386383

387384
array_push($products, array(

0 commit comments

Comments
 (0)