1. Go to this page and download the library: Download daniellarusso/dhl-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
daniellarusso / dhl-php-sdk example snippets
// You can initial the Credentials-Object with true to pre-set the Test-Account
$credentials = new \DanielLarusso\DHL\Credentials(/* Optional: Test-Modus */ true);
// Now you just need to set your DHL-Developer-Data to it
$credentials
->setApiUser('myuser') // Set the USERNAME (not E-Mail!) of your DHL-Dev-Account
->setApiPassword('myPasswd'); // Set the Password of your DHL-Dev-Account
// Just create the Credentials-Object
$credentials = new \DanielLarusso\DHL\Credentials();
// Setup these Infos: (ALL Infos are Case-Sensitive!)
$credentials
->setUser('Your-DHL-Account') // DHL-Account (Same as if you Login with then to create Manual-Labels)
->setSignature('Your-DHL-Account-Password') // DHL-Account-Password
->setEpk('EPK-Account-Number') // Number of your Account (Provide at least the first 10 digits)
->setApiUser('appId') // Your Applications-ID (You can find it in your DHL-Dev-Account)
->setApiPassword('appToken'); // Your Applications-Token (You can find it also where you found the App-Id)
// Create the Object with the first 10 Digits of your Account-Number (EPK).
// You can use the \DanielLarusso\DHL\Credentials function "->getEko((int) amount)" to get just the first 10 digits if longer
$shipmentDetails = new \DanielLarusso\DHL\ShipmentDetails((string) $credentials->getEpk(10) . '0101'); // Ensure the 0101 at the end
// Setup details
// -- Product
/* Setup the Product-Type that you need. Possible Values are:
* PRODUCT_TYPE_NATIONAL_PACKAGE = 'V01PAK';
* PRODUCT_TYPE_INTERNATIONAL_PACKAGE = 'V53WPAK';
* PRODUCT_TYPE_EUROPA_PACKAGE = 'V54EPAK';
* PRODUCT_TYPE_SAME_DAY_PACKAGE = 'V06PAK';
* PRODUCT_TYPE_SAME_DAY_MESSENGER = 'V06TG';
* PRODUCT_TYPE_WISH_TIME_MESSENGER = 'V06WZ';
* PRODUCT_TYPE_AUSTRIA_PACKAGE = 'V86PARCEL';
* PRODUCT_TYPE_AUSTRIA_INTERNATIONAL_PACKAGE = 'V82PARCEL';
* PRODUCT_TYPE_CONNECT_PACKAGE = 'V87PARCEL';
*/
$shipmentDetails->setProduct((string) \DanielLarusso\DHL\ShipmentDetails::{ProductType}); // Default: PRODUCT_TYPE_NATIONAL_PACKAGE
// Example:
$shipmentDetails->setProduct((string) \DanielLarusso\DHL\ShipmentDetails::PRODUCT_TYPE_INTERNATIONAL_PACKAGE);
// or (the same)
$shipmentDetails->setProduct((string) 'V53WPAK');
// -- Date
// You can set a Shipment-Date you have to provide it in this Format: YYYY-MM-DD
// -> The Date MUST be Today or in the future AND NOT a Sunday
$shipmentDetails->setShipmentDate((string) '2017-01-30'); // Default: Today or 1 day higher if Today is a Sunday
// You can also use a timestamp as value, just set the 2nd param to true (Default is false)
$shipmentDetails->setShipmentDate((int) time(), /* useTimeStamp = false */ true);
// -- Return Account-Number (EPK)
// Provide your Return-Account-Number here. If not needed don't set it!
// Its usually the same Account-Number like your DHL-Account, just set the end to 0701
$shipmentDetails->setReturnAccountNumber((string) $credentials->getEpk(10) . 0701); // Default: null -> Disabled
// -- References
$shipmentDetails->setCustomerReference((string) 'freetext 35 len'); // Default: null -> Disabled
// Only used if return receiver is used (ONLY if you want to print a return label)
$shipmentDetails->setReturnReference((string) 'freetext 35 len'); // Default: null -> Disabled
// Sizes/Weight
$shipmentDetails->setWeight((float) $weightInKG); // Default: 5.0 (KG)
$shipmentDetails->setLength((int) $lengthInCM); // Default: null -> Unset
$shipmentDetails->setWidth((int) $widthInCM); // Default: null -> Unset
$shipmentDetails->setHeight((int) $heightInCM); // Default: null -> Unset
// -- Package-Type (ONLY NEEDED IN VERSION 1)
/* Sets the Type of the Package. Possible Values:
* PALETTE = 'PL';
* PACKAGE = 'PK';
*/
$shipmentDetails->setPackageType((string) \DanielLarusso\DHL\ShipmentDetails::{type}); // Default: PACKAGE
$sender = new \DanielLarusso\DHL\Sender();
$sender->setName((string) 'Organisation DanielLarusso'); // Can be a Person-Name or Company Name
// You can add the whole address with that setter if you want
$sender->setFullStreet((string) 'Oberer Landweg 12a');
// If you want to set the elements on your own use the setter for them
$sender->setStreetName((string) 'Oberer Landweg');
$sender->setStreetNumber((string) '12a');
$sender->setZip((string) '21035');
$sender->setCity((string) 'Hamburg');
$sender->setCountry((string) 'Germany');
$sender->setCountryISOCode((string) 'DE'); // 2 Chars ONLY
// You can specify the delivery location
$sender->setAddressAddition((string) 'Etage 1'); // Default: null -> Disabled
$sender->setDispatchingInfo((string) 'Additional dispatching info'); // Default: null -> Disabled
$sender->setState((string) 'State'); // Default: null -> Disabled
// You can add more Personal-Info
$sender->setName2((string) 'Name Line 2'); // Default: null -> Disabled
$sender->setName3((string) 'Name Line 3'); // Default: null -> Disabled
$sender->setPhone((string) '04073409677'); // Default: null -> Disabled
$sender->setEmail((string) '[email protected]'); // Default: null -> Disabled
// Mostly used in bigger Companies
$sender->setContactPerson((string) 'Peter Dragicevic'); // Default: null -> Disabled
/* Creates the Object:
* - 1st param is the \DanielLarusso\DHL\Credentials Object
* - 2nd param (Optional - Default: false) is a bool value if the testmodus is used. (true uses testmodus, false live)
* - 3rd param (Optional - Default: null -> newest) is a float value, that assigns the Version to use
*/
$dhl = new \DanielLarusso\DHL\BusinessShipment($credentials);
// Add all Required (For a CREATE-Shipment-Request) Classes
$dhl->setShipmentDetails($shipmentDetails); // \DanielLarusso\DHL\ShipmentDetails Object
$dhl->setSender($sender); // \DanielLarusso\DHL\Sender Object
$dhl->setReceiver($receiver); // \DanielLarusso\DHL\Receiver Object
// Add Optional-Classes (Drop the line if you don't need/set it)
$dhl->setReturnReceiver($returnReceiver); // \DanielLarusso\DHL\ReturnReceiver Object - Default: null - Disabled
$dhl->setService($service); // \DanielLarusso\DHL\Service Object - Default: null -> All is default
$dhl->setBank($bankObj); // \DanielLarusso\DHL\BankData Object - Default: null -> Disabled
// You can enable Logging if you want
$dhl->setLog((bool) true);
// Set a Sequence-Number if you need a referrence when you get the response
$dhl->setSequenceNumber((string) '1'); // Default: '1'
// You can let DHL send a Mail to the Receiver, if you want that set the Mail
$dhl->setReceiverEmail((string) '[email protected]'); // Default: null -> Disabled
/* You can get the Label as URL or as Base64-Data-String - set it how you want to have it
* Possible Values:
* RESPONSE_TYPE_URL = 'URL';
* RESPONSE_TYPE_B64 = 'B64';
*/
$dhl->setLabelResponseType((string) \DanielLarusso\DHL\BusinessShipment::RESPONSE_TYPE_URL); // Default: null -> Uses DHL-Default
// Returns false if the Request failed or \DanielLarusso\DHL\Response on success
$response = $dhl->createShipment();
if($response === false) {
// Do your Error-Handling here
// Just to show all Errors
var_dump($dhl->getErrors()); // Get the Error-Array
} else {
// Handle the Response here
// Just to show the whole Response-Object
var_dump($response);
}
// Create a \DanielLarusso\DHL\BusinessShipment Object with your credentials
$dhl = new \DanielLarusso\DHL\BusinessShipment($credentials);
// Send a deletetion Request
$response = $dhl->deleteShipment((string) 'shipment_number');
// As usual create a \DanielLarusso\DHL\BusinessShipment Object with your Credentials
$dhl = new \DanielLarusso\DHL\BusinessShipment($credentials);
// This is the only setting you can do here: (Change Label-Response Type) - Optional
$dhl->setLabelResponseType((string) \DanielLarusso\DHL\BusinessShipment::RESPONSE_TYPE_B64); // Default: null -> DHL-Default
// And here comes the Request
$response = $dhl->getShipmentLabel((string) 'shipmentNumber');
// Create a \DanielLarusso\DHL\BusinessShipment Object with your credentials
$dhl = new \DanielLarusso\DHL\BusinessShipment($credentials);
// Do the Manifest-Request
$dhl->doManifest((string) 'shipment_number');
(string) $response->getShipmentNumber(); // Returns the Shipment-Number of the Request or null
(string) $response->getLabel(); // Returns the Label URL or Base64-Label-String or null
(string) $response->getReturnLabel(); // Returns the ReturnLabel (URL/B64) or null
(string) $response->getSequenceNumber(); // Returns your provided sequence number or null
(int) $response->getStatusCode(); // Returns the Status-Code (Difference to DHL - Weak-Validation is 1 not 0)
(string) $response->getStatusText(); // Returns the Status-Text or null
(string) $response->getStatusMessage(); // Returns the Status-Message (More details) or null