-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_4.php
131 lines (111 loc) · 3.95 KB
/
test_4.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
124
125
126
127
128
129
130
131
<?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\DocumentImage;
use belenka\DHLExpress\SpecialService;
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');
$specialService = new SpecialService();
$specialService->setServiceType(SpecialService::PAPERLESS_TRADE);
$invoice = new DocumentImage();
$invoice->setDocumentImageFormat(DocumentImage::DOCUMENT_IMAGE_FORMAT_PDF);
$invoice->setDocumentImageType(DocumentImage::DOCUMENT_IMAGE_TYPE_COMMERCIAL_INVOICE);
$invoice->setDocumentImage(base64_encode(file_get_contents('commercial_invoice.pdf')));
$shipmentInfo = new ShipmentInfo();
$shipmentInfo
->setDropOffType(ShipmentInfo::DROP_OFF_TYPE_REGULAR_PICKUP)
->setServiceType(ShipmentInfo::SERVICE_TYPE_EXPRESS_WORLDWIDE_NON_DOC)
->setAccount('YOUR-ACCOUNT')
->setCurrency('EUR')
->setUnitOfMeasurement(ShipmentInfo::UNIT_OF_MEASRUREMENTS_KG_CM)
->setLabelType(ShipmentInfo::LABEL_TYPE_PDF)
->setLabelTemplate(ShipmentInfo::LABEL_TEMPLATE_ECOM26_A6_002)
->setPaperlessTradeEnabled(true)
->addSpecialService($specialService)
->addDocumentImage($invoice);
$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('Zentralstrasse 50-62')
->setCity('Zürich')
->setPostalCode('8003')
->setCountryCode('CH');
$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')
->setCustomsValue(10);
// The InternationalDetail seems to be required even if its a domestic package
$internationalDetail = new InternationalDetail();
$internationalDetail
->setCommodities($commodities)
->setContent(InternationalDetail::CONTENT_NON_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_4.pdf', base64_decode($response->getLabel()));
} else {
print_r($response->getErrors());
}