forked from alex-LE/dhl-express-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_1.php
122 lines (102 loc) · 3.5 KB
/
test_1.php
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
118
119
120
121
122
<?php
require_once("vendor/autoload.php");
use nebbia\DHLExpress\Ship;
use nebbia\DHLExpress\Address;
use nebbia\DHLExpress\Shipper;
use nebbia\DHLExpress\Contact;
use nebbia\DHLExpress\Packages;
use nebbia\DHLExpress\Recipient;
use nebbia\DHLExpress\Commodities;
use nebbia\DHLExpress\Credentials;
use nebbia\DHLExpress\ShipmentInfo;
use nebbia\DHLExpress\SpecialService;
use nebbia\DHLExpress\ShipmentRequest;
use nebbia\DHLExpress\RequestedPackage;
use nebbia\DHLExpress\RequestedShipment;
use nebbia\DHLExpress\InternationalDetail;
$credentials = new Credentials(true);
$credentials
->setUsername('YOUR-USERNAME')
->setPassword('YOUR-PASSWORD');
$specialService = new SpecialService();
$specialService->setServiceType(SpecialService::SATURDAY_DELIVERY);
$shipmentInfo = new ShipmentInfo();
$shipmentInfo
->setDropOffType(ShipmentInfo::DROP_OFF_TYPE_REGULAR_PICKUP)
->setServiceType(ShipmentInfo::SERVICE_TYPE_DOMESTIC_EXPRESS)
->setAccount('YOUR-ACCOUNT')
->setCurrency('EUR')
->setUnitOfMeasurement(ShipmentInfo::UNIT_OF_MEASRUREMENTS_KG_CM)
->setLabelType(ShipmentInfo::LABEL_TYPE_PDF)
->setLabelTemplate(ShipmentInfo::LABEL_TEMPLATE_ECOM26_A6_002)
->addSpecialService($specialService);
$shipperContact = new Contact();
$shipperContact
->setPersonName('Max Mustermann')
->setCompanyName('Acme Inc.')
->setPhoneNumber('0123456789')
->setEmailAddress('max.mustermann@example.com');
$shipperAddress = new Address();
$shipperAddress
->setStreetLines('Hauptstrasse 1')
->setCity('Berlin')
->setPostalCode('10317')
->setCountryCode('DE');
$shipper = new Shipper();
$shipper
->setContact($shipperContact)
->setAddress($shipperAddress);
$recipientContact = new Contact();
$recipientContact
->setPersonName('Max Mustermann')
->setCompanyName('Acme Inc.')
->setPhoneNumber('0123456789')
->setEmailAddress('max.mustermann@example.com');
$recipientAddress = new Address();
$recipientAddress
->setStreetLines('Hauptstrasse 1')
->setCity('Berlin')
->setPostalCode('10317')
->setCountryCode('DE');
$recipient = new Recipient();
$recipient
->setContact($recipientContact)
->setAddress($recipientAddress);
$ship = new Ship();
$ship
->setShipper($shipper)
->setRecipient($recipient);
$package1 = new RequestedPackage();
$package1
->setWeight(2)
->setDimensions(1, 2, 3)
->setCustomerReferences('test 1');
$packages = new Packages();
$packages
->addRequestedPackage($package1);
$commodities = new Commodities();
$commodities->setDescription('Stuff');
// The InternationalDetail seems to be required even if its a domestic package
$internationalDetail = new InternationalDetail();
$internationalDetail
->setCommodities($commodities)
->setContent(InternationalDetail::CONTENT_DOCUMENTS);
$timestamp = new DateTime("now", new DateTimeZone("Europe/Berlin"));
$timestamp->modify('+3 days');
$requestedShipment = new RequestedShipment();
$requestedShipment
->setShipmentInfo($shipmentInfo)
->setShipTimestamp($timestamp)
->setPaymentInfo(RequestedShipment::PAYMENT_INFO_DELIVERED_AT_PLACE)
->setShip($ship)
->setPackages($packages)
->setInternationalDetail($internationalDetail);
$shipment = new ShipmentRequest($credentials);
$shipment->setRequestedShipment($requestedShipment);
$response = $shipment->send();
if ($response->isSuccessful()) {
print_r($response->getTrackingNumber());
file_put_contents('label_1.pdf', base64_decode($response->getLabel()));
} else {
print_r($response->getErrors());
}