Skip to content

Commit eb01dd0

Browse files
commit
0 parents  commit eb01dd0

File tree

156 files changed

+12170
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+12170
-0
lines changed

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "elitedevsolution/dhl-api",
3+
"description": "PHP library to communicate with the DHL XML Services.",
4+
"require": {
5+
"php": ">=7.0"
6+
},
7+
"license": "MIT",
8+
"autoload": {
9+
"psr-4": {
10+
"Mtc\\Dhl\\": "src/"
11+
}
12+
},
13+
"authors": [
14+
{
15+
"name": "Elite Dev Solution",
16+
"email": "fstorm707@gmail.com"
17+
}
18+
]
19+
}

docs/pickup.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Example request:
2+
```php
3+
$pickup = new BookPURequest();
4+
$pickup->SiteID = 'ACCOUNT_NUMBER';
5+
$pickup->Password = 'PASSWORD';
6+
$pickup->MessageTime = Carbon::now()->format(Carbon::ATOM);
7+
$pickup->MessageReference = 'reference_28_to_32_characters';
8+
9+
$pickup->Requestor->AccountNumber = 'SHIPPER_ACCOUNT';
10+
$pickup->Requestor->AccountType = 'D';
11+
$pickup->Requestor->CompanyName = $address->organisation;
12+
$pickup->Requestor->RequestorContact->PersonName = $address->contact_name;
13+
$pickup->Requestor->RequestorContact->Phone = $address->contact_phone;
14+
15+
// DHL REGION based on the Toolkit documentation for the pickup country
16+
$pickup->RegionCode = $dhl_region;
17+
18+
$pickup->Place->LocationType = 'B';
19+
$pickup->Place->CompanyName = $address->organisation;
20+
$pickup->Place->Address1 = $address->address1;
21+
$pickup->Place->Address2 = $address->address2;
22+
$pickup->Place->PackageLocation = 'Ask receptionist';
23+
$pickup->Place->City = $address->city;
24+
$pickup->Place->CountryCode = $address->country;
25+
$pickup->Place->PostalCode = $address->postcode;
26+
27+
$pickup->Pickup->PickupDate = $pickup_time;
28+
$pickup->Pickup->ReadyByTime = '13:00';
29+
$pickup->Pickup->CloseTime = '17:00';
30+
31+
$pickup->PickupContact->PersonName = $address->contact_name;
32+
$pickup->PickupContact->Phone = $address->contact_phone;
33+
34+
$pickup->ShipmentDetails->AccountType = 'D';
35+
$pickup->ShipmentDetails->AccountNumber = 'SHIPPER_ACCOUINT';
36+
$pickup->ShipmentDetails->BillToAccountNumber = 'BILLING_ACCOUNT';
37+
38+
$pickup->ShipmentDetails->AWBNumber = $tracking_number;
39+
$pickup->ShipmentDetails->NumberOfPieces = $package_count;
40+
$pickup->ShipmentDetails->GlobalProductCode = $shipment_product_code;
41+
$pickup->ShipmentDetails->Weight = $package_weight;
42+
$pickup->ShipmentDetails->WeightUnit = 'K';
43+
$pickup->ShipmentDetails->DoorTo = 'DD';
44+
$pickup->ShipmentDetails->DimensionUnit = 'C';
45+
46+
$client = new Web($this->getEnvironment());
47+
$xml_response = $client->call($pickup);
48+
```
49+
50+
If you need XML request for the DHL certification you can obtain by calling the following code
51+
```php
52+
$request_xml = $pickup->toXml();
53+
```

docs/quote.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Example request:
2+
```php
3+
$tracking = new KnownTrackingRequest();
4+
$tracking->SiteID = 'ACCOUNT_NUIMBER';
5+
$tracking->Password = 'PASSWORD';
6+
$tracking->MessageReference = 'reference_28_to_32_chars';
7+
$tracking->MessageTime = Carbon::now()->format(Carbon::ATOM);
8+
$tracking->LanguageCode = 'en';
9+
$tracking->AWBNumber = $tracking_number;
10+
$tracking->LevelOfDetails = 'ALL_CHECK_POINTS';
11+
$tracking->PiecesEnabled = 'S';
12+
13+
$client = new Web($this->getEnvironment());
14+
$xml_response = $client->call($tracking);
15+
```
16+
17+
If you need XML request for the DHL certification you can obtain by calling the following code
18+
```php
19+
$request_xml = $tracking->toXml();
20+
```

docs/route.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Example request:
2+
```php
3+
$router = new RouteRequest();
4+
$router->MessageTime = Carbon::now()->format(Carbon::ATOM);
5+
$router->MessageReference = 'reference_28_to_30_chars';
6+
$router->SiteID = 'SITE_ID';
7+
$router->Password = 'PASSWORD';
8+
$router->OriginCountryCode = 'GB';
9+
$router->RequestType = 'O';
10+
11+
$router->Address1 = 'mtc media, Unit 35';
12+
$router->Address2 = 'Shed 26, City Quay';
13+
$router->Address3 = '';
14+
$router->PostalCode = 'DD1 3JA';
15+
$router->City = 'Dundee';
16+
$router->Division = '';
17+
$router->CountryCode = 'GB';
18+
$router->RegionCode = 'EU';
19+
$router->CountryName = 'United Kingdom';
20+
21+
$client = new Web('staging/production');
22+
$xml_response = $client->call($router);
23+
```
24+
25+
If you need XML request for the DHL certification you can obtain by calling the following code
26+
```php
27+
$request_xml = $router->toXml();
28+
```

docs/shipment.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
Example request:
2+
```php
3+
$shipment = new ShipmentRequest();
4+
$shipment->SiteID = $order->auth->account_number;
5+
$shipment->Password = $order->auth->password;
6+
$shipment->MessageTime = Carbon::now()->format(Carbon::ATOM);
7+
$shipment->MessageReference = substr($reference, 0, 30);
8+
$shipment->LanguageCode = 'en';
9+
$shipment->PiecesEnabled = 'Y';
10+
$shipment->Reference->ReferenceID = $client->account . '-' . $order->id;
11+
12+
$shipment->Billing->ShipperAccountNumber = $order->auth->shipper_account;
13+
$shipment->Billing->ShippingPaymentType = 'S';
14+
$shipment->Billing->BillingAccountNumber = $order->auth->billing_account;
15+
16+
// Outside EU changes Tax info
17+
if (!Country::isEu($shipping_address->country)) {
18+
$shipment->Billing->DutyPaymentType = 'R';
19+
}
20+
21+
$contact_name = $shipping_address->first_name . ' ' . $shipping_address->last_name;
22+
$shipment->Consignee->CompanyName = $shipping_address->organisation ?? '--';
23+
$shipment->Consignee->Contact->PersonName = $contact_name;
24+
$shipment->Consignee->addAddressLine(substr($shipping_address->address1, 0, 35));
25+
$shipment->Consignee->addAddressLine(substr($shipping_address->address2, 0, 35));
26+
$shipment->Consignee->City = $shipping_address->city;
27+
$shipment->Consignee->PostalCode = $shipping_address->postcode;
28+
$shipment->Consignee->Division = $shipping_address->state ?? '';
29+
$shipment->Consignee->CountryCode = $shipping_address->country;
30+
$shipment->Consignee->CountryName = Country::getNameFromCode($shipping_address->country);
31+
$shipment->Consignee->Contact->PhoneNumber = $order->info->contact_no;
32+
$shipment->Consignee->Contact->Email = $order->info->email;
33+
$shipment->Consignee->Contact->PhoneExtension = '';
34+
$shipment->Consignee->Contact->FaxNumber = '';
35+
$shipment->Consignee->Contact->Telex = '';
36+
$shipment->RegionCode = Country::getDHLRegionCode($shipping_address->country);
37+
38+
$order_value = $order->order_cost - $order->delivery_cost > 0 ? $order->order_cost - $order->delivery_cost : 1.0;
39+
$shipment->Dutiable->DeclaredValue = $order_value;
40+
$shipment->Dutiable->DeclaredCurrency = 'GBP';
41+
$shipment->Dutiable->TermsOfTrade = 'DDP';
42+
43+
$shipment->Shipper->ShipperID = $order->auth->shipper_id;
44+
$shipment->Shipper->RegisteredAccount = $order->auth->shipper_account_number;
45+
$shipment->Shipper->CompanyName = $collection_address->organisation;
46+
$shipment->Shipper->addAddressLine($collection_address->address1);
47+
$shipment->Shipper->addAddressLine($collection_address->address2);
48+
$shipment->Shipper->City = $collection_address->city;
49+
$shipment->Shipper->PostalCode = $collection_address->postcode;
50+
$shipment->Shipper->CountryCode = $collection_address->country;
51+
$shipment->Shipper->CountryName = Country::getNameFromCode($collection_address->country);
52+
53+
$shipment->Shipper->Contact->PersonName = $collection_address->contact_name;
54+
$shipment->Shipper->Contact->PhoneNumber = $collection_address->contact_phone;
55+
$shipment->Shipper->Contact->Email = $collection_address->contact_email;
56+
$shipment->Shipper->Contact->PhoneExtension = '';
57+
$shipment->Shipper->Contact->FaxNumber = '';
58+
$shipment->Shipper->Contact->Telex = '';
59+
60+
// Delivery Service is obtained via Quote request which will find valid services for shipment
61+
$shipment->ShipmentDetails->GlobalProductCode = $delivery_service->code;
62+
$shipment->ShipmentDetails->LocalProductCode = $delivery_service->format;
63+
64+
if (Country::isEu($shipping_address->country) === false) {
65+
$shipment->ShipmentDetails->DoorTo = 'DD';
66+
}
67+
$shipment->ShipmentDetails->Contents = 'Shipment Description';
68+
$shipment->ShipmentDetails->CurrencyCode = 'GBP';
69+
$shipment->ShipmentDetails->WeightUnit = 'K';
70+
$shipment->ShipmentDetails->Weight = collect($packages)->sum('weight');
71+
$shipment->ShipmentDetails->Date = Carbon::now()->format('Y-m-d');
72+
$shipment->ShipmentDetails->DimensionUnit = 'C';
73+
$shipment->ShipmentDetails->InsuredAmount = $order->insurance_total ?? 0;
74+
$shipment->ShipmentDetails->PackageType = $order->package_type ?? 'PA';
75+
$shipment->ShipmentDetails->IsDutiable = Country::isEu($shipping_address->country) ? 'Y' : 'N';
76+
77+
$shipment->ShipmentDetails->AdditionalProtection = new AdditionalProtection();
78+
$shipment->ShipmentDetails->DOSFlag = 'N';
79+
$shipment->ShipmentDetails->CustData = $contact_name;
80+
81+
// Information about Packages in shipment
82+
$shipment->ShipmentDetails->NumberOfPieces = count($packages);
83+
foreach ($packages as $package_id => $package) {
84+
$piece = new Piece();
85+
$piece->PieceID = $client->account . $order->id . $package_id;
86+
$piece->PackageType = $order->package_type ?? 'CP';
87+
$piece->Weight = $package['weight'];
88+
$piece->DimWeight = $package['weight'];
89+
$shipment->ShipmentDetails->addPiece($piece);
90+
}
91+
92+
$shipment->EProcShip = 'N';
93+
$shipment->LabelImageFormat = 'PDF';
94+
$shipment->Label->LabelTemplate = '8X4_PDF';
95+
96+
$client = new Web($this->getEnvironment());
97+
$xml_response = $client->call($shipment);
98+
```
99+
100+
If you need XML request for the DHL certification you can obtain by calling the following code
101+
```php
102+
$request_xml = $shipment->toXml();
103+
```

docs/tracking.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Example request:
2+
```php
3+
$sample = new GetQuote();
4+
$sample->SiteID = 'ACCOUNT_NUMBER';
5+
$sample->Password = 'PASSWORD';
6+
$sample->MessageTime = Carbon::now()->format(Carbon::ATOM);
7+
$sample->MessageReference = 'reference_28_to_32_chars';
8+
9+
$sample->BkgDetails->Date = date('Y-m-d');
10+
$sample->BkgDetails->PaymentCountryCode = 'GB';
11+
$sample->BkgDetails->DimensionUnit = 'CM';
12+
$sample->BkgDetails->WeightUnit = 'KG';
13+
$sample->BkgDetails->ReadyTime = 'PT10H21M';
14+
$sample->BkgDetails->ReadyTimeGMTOffset = '+01:00';
15+
$sample->BkgDetails->PaymentAccountNumber = 'SHIPPER_ACCOUNT_NUMBER';
16+
17+
foreach ($packages as $index => $package) {
18+
$piece = new PieceType();
19+
$piece->PieceID = $index + 1;
20+
$piece->Height = $package['height'];
21+
$piece->Depth = $package['length'];
22+
$piece->Width = $package['width'];
23+
$piece->Weight = $package['weight'];
24+
$sample->BkgDetails->addPiece($piece);
25+
}
26+
27+
$sample->From->CountryCode = 'GB';
28+
$sample->From->Postalcode = 'DD13JA';
29+
30+
$sample->To->City = $address->city;
31+
$sample->To->Postalcode = $address->postcode;
32+
$sample->To->CountryCode = $address->country;
33+
$sample->BkgDetails->IsDutiable = Country::isEu($address->country) ? 'N' : 'Y';
34+
35+
if (!Country::isEu($address->country)) {
36+
$order_value = $order->order_cost - $order->delivery_cost > 0 ? $order->order_cost - $order->delivery_cost : 1.0;
37+
$sample->Dutiable->DeclaredValue = $order_value;
38+
$sample->Dutiable->DeclaredCurrency = 'GBP';
39+
}
40+
41+
$client = new Web($this->getEnvironment());
42+
$xml_response = $client->call($sample);
43+
```
44+
45+
If you need XML request for the DHL certification you can obtain by calling the following code
46+
```php
47+
$request_xml = $sample->toXml();
48+
```

readme.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# DHL API
2+
3+
* [Installation](#installation)
4+
* [Usage](#usage)
5+
6+
## Installation
7+
8+
Package should be installed through composer:
9+
10+
```bash
11+
composer require mtcmedia/dhl-api
12+
```
13+
14+
Package requires a php min version of 7.0, however it has has been developed and tested on php 7.2.*
15+
16+
## Usage
17+
18+
You will need Sandbox account to start setup.
19+
You can request your unique credentials by registering for the XML Portal https://xmlportal.dhl.com/register
20+
21+
DHL Documentation: http://xmlpitest-ea.dhl.com/toolkit/Toolkit.zip
22+
23+
DHL XML Services Test Harness: https://xmlpi-validation.dhl.com/serviceval/jsps/main/Main_menu.jsp
24+
25+
DHL XML Services Test server for customer certification: https://xmlpitest-ea.dhl.com/XMLShippingServlet
26+
27+
[Quote Requests (v6.1)](docs/quote.md)
28+
29+
[Route Requests (v1.0)](docs/route.md)
30+
31+
[Shipment Requests (v6.2)](docs/shipment.md)
32+
33+
[Pickup Request (v1.0)](docs/pickup.md)
34+
35+
[Tracking Requests (v1.0)](docs/tracking.md)
36+
37+
38+
## Contributing
39+
40+
Please see [CONTRIBUTING](contributing.md) for details.
41+
42+
### Security
43+
44+
If you discover any security-related issues, please email [opensource@mtcmedia.co.uk](mailto:opensource@mtcmedia.co.uk) instead of using the issue tracker.
45+
46+
## License
47+
48+
The package is provided under MIT License. Please see [License File](license.md) for more information.

0 commit comments

Comments
 (0)