sonnenglas/mydhl-php-sdk

Unofficial PHP SDK for MyDHL REST API (DHL Express)

0.3.2 2023-01-16 18:39 UTC

README

PHP library for using DHL Express REST API (MyDHL API).

Status: CircleCI

Note: It supports only the latest REST API provided by DHL. No SOAP API support.

Supported services:

Usage:

diff

Retrieve rates

use Sonnenglas\MyDHL\MyDHL;
use Sonnenglas\MyDHL\ValueObjects\RateAddress;
use Sonnenglas\MyDHL\ValueObjects\Package;

$testMode = true;
$myDhl = new MyDHL('username', 'password', $testMode);

$rateService = $myDhl->getRateService();

$originAddress = new RateAddress(
    countryCode: 'DE',
    postalCode: '10117',
    cityName: 'Berlin',
);

$destinationAddress = new RateAddress(
    countryCode: 'DE',
    postalCode: '20099',
    cityName: 'Hamburg',
);

$package = new Package(
    weight: 10, // kg
    height: 20, // cm
    length: 10, // cm
    width: 30, // cm
);

$shippingDate = new DateTimeImmutable('2021-01-15 12:00:00');

$rates = $rateService->setAccountNumber('99999999')
    ->setOriginAddress($originAddress)
    ->setDestinationAddress($destinationAddress)
    ->setPlannedShippingDate($shippingDate)
    ->setPackage($package)
    ->setNextBusinessDay(false)
    ->setCustomsDeclarable(false)
    ->getRates();

All usage examples: