1. Go to this page and download the library: Download booni3/dhl-express-rest 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/ */
booni3 / dhl-express-rest example snippets
use Booni3\DhlExpressRest\DHL;
$dhl = DHL::make([
'user' => 'DHLUSER',
'pass' => 'DHLPASS',
'sandbox' => true, // false or omit for production
]);
use Booni3\DhlExpressRest\DHL;
use Booni3\DhlExpressRest\DTO\Address;
use Booni3\DhlExpressRest\DTO\Package;
use Booni3\DhlExpressRest\DTO\ShipmentCreator;
$shipment = new ShipmentCreator();
$shipment->setShipperAccountNumber('123456789');
$shipment->setProductCode('N');
$shipment->setShipper(
(new Address(
'John Smith',
'21 Apple Drive',
'',
'',
'Malmesbury',
'SN16 4TB',
'GB',
'business',
'My Awesome Company',
'07111111111',
'[email protected]'
))
->addVat('GB1234')
->addEORI('GB1234')
);
$shipment->setReceiver(new Address(
'Helen Jones',
'4 Example Drive',
'',
'',
'London',
'E14 8DW',
'GB',
'direct_consumer',
'-',
'07111111112',
'[email protected]'
));
$shipment->addReference('123456-custom-ref');
$shipment->addPackage(new Package(12.5, 20, 10, 10, 'Jumpers', 'order-ref-1244'));
$response = $dhl->shipments()->create($shipment);
$response->trackingNumber; // shipment tracking number
$response->trackingUrl; // DHL tracking URL
$response->labelData(); // decoded label data
use Booni3\DhlExpressRest\DTO\LineItem;
use Carbon\Carbon;
$shipment->setConsignmentDescription('Table legs');
$shipment->setCustomsDeclarable(true, true); // customs declarable, paperless trade
// DDP: adds value-added service DD and the duties/taxes billing account.
$shipment->setTermsDDP('123456789');
// IOSS: defaults to DAP unless you pass a different incoterm as the third argument.
// $shipment->setTermsIOSS('IM1234567890', 'GB');
$shipment->setInvoice('PS-1234', Carbon::now(), 'Adam Lambert');
$shipment->setExportDeclaration('sale', 'permanent', 'GBP');
$shipment->addExportLineItem(new LineItem(
'Black steel table legs',
84.95,
1,
9403999045,
'GB',
9.1
));