-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_2.php
123 lines (104 loc) · 3.51 KB
/
test_2.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
123
<?php
require_once("vendor/autoload.php");
use belenka\DHLExpress\Ship;
use belenka\DHLExpress\Address;
use belenka\DHLExpress\Shipper;
use belenka\DHLExpress\Contact;
use belenka\DHLExpress\Packages;
use belenka\DHLExpress\Recipient;
use belenka\DHLExpress\Commodities;
use belenka\DHLExpress\Credentials;
use belenka\DHLExpress\ShipmentInfo;
use belenka\DHLExpress\ShipmentRequest;
use belenka\DHLExpress\RequestedPackage;
use belenka\DHLExpress\RequestedShipment;
use belenka\DHLExpress\InternationalDetail;
$credentials = new Credentials(true);
$credentials
->setUsername('YOUR-USERNAME')
->setPassword('YOUR-PASSWORD');
$shipmentInfo = new ShipmentInfo();
$shipmentInfo
->setDropOffType(ShipmentInfo::DROP_OFF_TYPE_REGULAR_PICKUP)
->setServiceType(ShipmentInfo::SERVICE_TYPE_DOMESTIC_EXPRESS_BEFORE_0900)
->setAccount('YOUR-ACCOUNT')
->setCurrency('EUR')
->setUnitOfMeasurement(ShipmentInfo::UNIT_OF_MEASRUREMENTS_KG_CM)
->setLabelType(ShipmentInfo::LABEL_TYPE_PDF)
->setLabelTemplate(ShipmentInfo::LABEL_TEMPLATE_ECOM26_A6_002);
$shipperContact = new Contact();
$shipperContact
->setPersonName('Max Mustermann')
->setCompanyName('Acme Inc.')
->setPhoneNumber('0123456789')
->setEmailAddress('[email protected]');
$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('[email protected]');
$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');
$package2 = new RequestedPackage();
$package2
->setWeight(2)
->setDimensions(1, 2, 3)
->setCustomerReferences('test 2');
$packages = new Packages();
$packages
->addRequestedPackage($package1)
->addRequestedPackage($package2);
$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_2.pdf', base64_decode($response->getLabel()));
} else {
print_r($response->getErrors());
}