PHP code example of beziworld / laravel-dhl-express

1. Go to this page and download the library: Download beziworld/laravel-dhl-express 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/ */

    

beziworld / laravel-dhl-express example snippets


use Beziworld\DhlExpress\Data\Money;
use Beziworld\DhlExpress\Data\Parcel;
use Beziworld\DhlExpress\Data\Party;
use Beziworld\DhlExpress\Enums\LabelFormat;
use Beziworld\DhlExpress\Facades\DhlExpress;

$shipment = DhlExpress::shipment()
    ->to(new Party('Max Mustermann', 'Potsdamer Str. 1', 'Berlin', '10785', 'DE', phone: '+49301234', email: '[email protected]'))
    ->product('U')                                   // take the codes available for the lane from rates()
    ->parcel(new Parcel(weight: 1.5, length: 20, width: 15, height: 10, reference: 'ORDER-1'))
    ->description('Books')
    ->reference('ORDER-1')
    ->labelFormat(LabelFormat::Zpl)
    ->insurance(Money::of(200, 'EUR'))
    ->create();

$shipment->trackingNumber;            // waybill number, e.g. 1234567890
$shipment->packageTrackingNumbers;    // JD... piece numbers
$shipment->label()->content;          // decoded label
$shipment->trackingUrl;

use Beziworld\DhlExpress\Data\Customs;
use Beziworld\DhlExpress\Data\CustomsItem;

$shipment = DhlExpress::shipment()
    ->to(new Party('John Smith', '5th Avenue 1', 'New York', '10001', 'US', phone: '+12125550100', provinceCode: 'NY'))
    ->product('P')
    ->parcel(new Parcel(1.0, 30, 20, 10))
    ->description('Cotton T-shirts')
    ->incoterm('DAP')
    ->customs(new Customs(
        items: [new CustomsItem('Cotton T-shirt', quantity: 3, unitPrice: '12.00', netWeight: 0.6, originCountry: 'PL', hsCode: '610910')],
        currency: 'USD',
        invoiceNumber: 'FV/1/2026',
        exportReasonType: 'commercial_purpose_or_sale',
    ))
    ->create();

$shipment->document('invoice')?->content;   // commercial invoice generated by DHL

$rates = DhlExpress::shipment()->to($receiver)->parcel(new Parcel(1.5, 20, 15, 10))->rates();   // cheapest first

$rates[0]->productCode;          // U
$rates[0]->productName;          // EXPRESS WORLDWIDE EU
$rates[0]->total;                // Money in the billing currency (BILLC)
$rates[0]->estimatedDelivery;    // CarbonImmutable
$rates[0]->transitDays;

DhlExpress::products($shipper, $receiver, new Parcel(1.5, 20, 15, 10));   // products without prices

$shipment = DhlExpress::track('9356579890');

$shipment->status;           // TrackingStatus::Delivered, OutForDelivery, PickedUp, InTransit, Exception, Returned, Unknown
$shipment->deliveredAt();
$shipment->signedBy;
foreach ($shipment->events as $event) {   // newest first
    $event->occurredAt;      // local time with the GMT offset sent by DHL
    $event->typeCode;        // checkpoint code, e.g. PU, WC, OK
    $event->description;
    $event->location;        // service area, e.g. Berlin-DE
}

DhlExpress::trackMany(['9356579890', '4818240420']);
DhlExpress::proofOfDelivery('9356579890')->content;        // PDF
DhlExpress::shipmentImages('9356579890', now(), 'commercial-invoice');
DhlExpress::referenceData('trackingEventCode');            // full list of checkpoint codes

use Beziworld\DhlExpress\Data\PickupRequest;

$pickup = DhlExpress::schedulePickup(new PickupRequest(
    readyAt: now('Europe/Warsaw')->addDay()->setTime(14, 0),
    closeTime: '18:00',
    parcels: [new Parcel(1.5, 20, 15, 10)],
    productCode: 'U',
    location: 'reception',
));
DhlExpress::cancelPickup($pickup->number(), requestorName: 'Jan Nowak', reason: 'not needed');

DhlExpress::validateAddress('PL', '00-001', 'Warszawa', 'pickup');   // list<AddressMatch> with service areas

DhlExpress::connection('de')->shipment()->...;   // config/dhl-express.php connections
DhlExpress::using(['username' => $tenant->dhl_key, 'password' => $tenant->dhl_secret, 'account_number' => $tenant->dhl_account])->track('9356579890');