DHL-PHP-SDK
v0.4
A wrapper for the DHL-XML-API Version 2
test.php
Go to the documentation of this file.
1
<?php
2
3
require_once __DIR__.
'/vendor/autoload.php'
;
4
5
// Require the Main-Class (other classes will included by this file)
6
use
Petschko\DHL\BusinessShipment
;
7
use
Petschko\DHL\Credentials
;
8
use
Petschko\DHL\Receiver
;
9
use
Petschko\DHL\ReturnReceiver
;
10
use
Petschko\DHL\Sender
;
11
use
Petschko\DHL\Service
;
12
use
Petschko\DHL\ShipmentOrder
;
13
use
Petschko\DHL\ShipmentDetails
;
14
15
$testMode
= Credentials::TEST_NORMAL;
// Uses the normal test user
16
//$testMode = Credentials::DHL_BUSINESS_TEST_USER_THERMO; // Uses the thermo-printer test user
17
$version
=
'2.2'
;
// Can be specified or just left out (uses newest by default)
18
$reference
=
'1'
;
// You can use anything here (max 35 chars)
19
20
// Set this to true then you can skip set the "User", "Signature" and "EKP" (Just for test-Mode) else false or empty
21
$credentials
=
new
Credentials
(
$testMode
);
22
23
if
(!
$testMode
) {
24
$credentials
->setUser(
'Your-DHL-Account'
);
// Don't needed if initialed with Test-Mode
25
$credentials
->setSignature(
'Your-DHL-Account-Password'
);
// Don't needed if initialed with Test-Mode
26
$credentials
->setEkp(
'EKP-Account-Number'
);
// Don't needed if initialed with Test-Mode
27
}
28
29
// Set your API-Login
30
$credentials
->setApiUser(
''
);
// Test-Mode: Your DHL-Dev-Account (Developer-ID NOT E-Mail!!) | Production: Your Applications-ID
31
$credentials
->setApiPassword(
''
);
// Test-Mode: Your DHL-Dev-Account Password | Production: Your Applications-Token
32
33
// Set Service stuff (look at the class member - many settings here - just set them you need)
34
$service
=
new
Service
();
35
// Set stuff you want in that class - This is very optional
36
37
// Set Shipment Details
38
$shipmentDetails
=
new
ShipmentDetails
(
$credentials
->getEkp(10) .
'0101'
);
// Create a Shipment-Details with the first 10 digits of your EKP-Number and 0101 (?)
39
$shipmentDetails
->setShipmentDate(
'2018-09-20'
);
// Optional: Need to be in the future and NOT on a sunday | null or drop it, to use today
40
$shipmentDetails
->setNotificationEmail(
'mail@inform.me'
);
// Needed if you want inform the receiver via mail
41
//$shipmentDetails->setReturnAccountNumber($credentials->getEkp(10) . '0701'); // Needed if you want to print a return label
42
//$shipmentDetails->setReturnReference($reference); // Only needed if you want to print a return label
43
$shipmentDetails
->setService(
$service
);
// Optional, just needed if you add some services
44
// $shipmentDetails->setBank($bank); // Very optional, you need to add the Bank Object, whenever you need it here
45
46
// Set Sender
47
$sender
=
new
Sender
();
48
$sender
->setName(
'Peter Muster'
);
49
$sender
->setStreetName(
'Test Straße'
);
50
$sender
->setStreetNumber(
'12a'
);
51
$sender
->setZip(
'21037'
);
52
$sender
->setCity(
'Hamburg'
);
53
$sender
->setCountry(
'Germany'
);
54
$sender
->setCountryISOCode(
'DE'
);
55
// $sender->setEmail('peter@petschko.org'); // These are super optional, it will printed on the label, can set under receiver as well
56
// $sender->setPhone('015774121861');
57
// $sender->setContactPerson('Anna Muster');
58
59
// Set Receiver
60
$receiver
=
new
Receiver
();
61
$receiver
->setName(
'Test Empfänger'
);
62
$receiver
->setStreetName(
'Test Straße'
);
63
$receiver
->setStreetNumber(
'23b'
);
64
$receiver
->setZip(
'21037'
);
65
$receiver
->setCity(
'Hamburg'
);
66
$receiver
->setCountry(
'Germany'
);
67
$receiver
->setCountryISOCode(
'DE'
);
68
69
$returnReceiver
=
new
ReturnReceiver
();
// Needed if you want to print an return label
70
// If want to use it, please set Address etc of the return receiver to!
71
72
// Required just Credentials also accept Test-Mode and Version
73
$dhl
=
new
BusinessShipment
(
$credentials
,
/*Optional*/
$testMode
,
/*Optional*/
$version
);
74
75
// You can add your own API-File (if you want to use a remote one or your own) - else you don't need this
76
//$dhl->setCustomAPIURL('http://myserver.com/myAPIFile.wsdl');
77
78
// Don't forget to assign the created objects to the ShipmentOrder Object!
79
$shipmentOrder
=
new
ShipmentOrder
();
80
$shipmentOrder
->setSequenceNumber(
$reference
);
// Just needed to identify the shipment if you do multiple
81
$shipmentOrder
->setSender(
$sender
);
82
$shipmentOrder
->setReceiver(
$receiver
);
// You can set these Object-Types here: DHL_Filial, DHL_Receiver & DHL_PackStation
83
//$shipmentOrder->setReturnReceiver($returnReceiver); // Needed if you want print a return label
84
$shipmentOrder
->setShipmentDetails(
$shipmentDetails
);
85
$shipmentOrder
->setLabelResponseType(BusinessShipment::RESPONSE_TYPE_URL);
86
87
// Add the ShipmentOrder to the BusinessShipment Object, you can add up to 30 ShipmentOrder Objects in 1 call
88
$dhl
->addShipmentOrder(
$shipmentOrder
);
89
90
$response
=
$dhl
->createShipment();
// Creates the request
91
92
// For deletion you just need the shipment number and credentials
93
// $dhlDel = new BusinessShipment($credentials, $testMode, $version);
94
// $response_del = $dhlDel->deleteShipment('shipment_number'); // Deletes a Shipment
95
// $response_del = $dhlDel->deleteShipment(array('shipment_number1', 'shipment_number2')); // Deletes multiple Shipments (up to 30)
96
97
// To re-get the Label you can use the getShipmentLabel method - the shipment must be created with createShipment before
98
//$dhlReGetLabel = new BusinessShipment($credentials, $testMode, $version);
99
//$dhlReGetLabel->setLabelResponseType(DHL_BusinessShipment::RESPONSE_TYPE_B64); // Optional: Set the Label-Response-Type
100
//$reGetLabelResponse = $dhlReGetLabel->getLabel('shipment_number'); // ReGet a single Label
101
//$reGetLabelResponse = $dhlReGetLabel->getLabel(array('shipment_number1', 'shipment_number2')); // ReGet multiple Labels (up to 30)
102
103
// To do a Manifest-Request you can use the doManifest method - you have to provide a Shipment-Number
104
//$manifestDHL = new BusinessShipment($credentials, $testMode, $version);
105
//$manifestResponse = $manifestDHL->doManifest('shipment_number'); // Does Manifest on a Shipment
106
//$manifestResponse = $manifestDHL->doManifest(array('shipment_number1', 'shipment_number2')); // Does Manifest on multiple Shipments (up to 30)
107
108
// To do a Manifest-Request you can use the doManifest method - you have to provide a Shipment-Number
109
//$getManifestDHL = new BusinessShipment($credentials, $testMode, $version);
110
//$getManifestResponse = $getManifestDHL->getManifest('YYYY-MM-DD'); // Need to be in the past or today after doManifest()
111
112
// Get the result (just use var_dump to show all results)
113
if
(
$response
!==
false
)
114
var_dump(
$response
);
115
else
116
var_dump(
$dhl
->getErrors());
117
118
// You can show yourself also the XML-Request as string
119
var_dump(
$dhl
->getLastXML());
ReturnReceiver
Petschko\DHL\Receiver
Definition:
Receiver.php:23
$credentials
$credentials
Definition:
test.php:21
$sender
$sender
Definition:
test.php:47
Petschko\DHL\BusinessShipment
Definition:
BusinessShipment.php:26
Sender
ShipmentDetails
Petschko\DHL\ShipmentDetails
Definition:
ShipmentDetails.php:23
$testMode
$testMode
Definition:
test.php:15
ShipmentOrder
Petschko\DHL\ShipmentOrder
Definition:
ShipmentOrder.php:24
Petschko\DHL\Service
Definition:
Service.php:23
$shipmentDetails
$shipmentDetails
Definition:
test.php:38
$returnReceiver
$returnReceiver
Definition:
test.php:69
$version
$version
Definition:
test.php:17
Credentials
Service
Petschko\DHL\Credentials
Definition:
Credentials.php:21
$receiver
$receiver
Definition:
test.php:60
Receiver
$response
$response
Definition:
test.php:90
$shipmentOrder
$shipmentOrder
Definition:
test.php:79
BusinessShipment
Petschko\DHL\Sender
Definition:
Sender.php:23
$dhl
$dhl
Definition:
test.php:73
$service
$service
Definition:
test.php:34
Petschko\DHL\ReturnReceiver
Definition:
ReturnReceiver.php:23
$reference
$reference
Definition:
test.php:18
test.php
Generated by
1.8.12