The DHL Business Customer Shipping API SDK package offers an interface to the following web services:
- Geschäftskundenversand 3.1.2
- PHP 7.1+ with SOAP extension
psr/log
: PSR-3 logger interfaces
phpunit/phpunit
: Testing framework
$ composer require dhl/sdk-api-bcs
$ composer remove dhl/sdk-api-bcs
$ ./vendor/bin/phpunit -c test/phpunit.xml
The DHL BCS API SDK supports the following features:
- Validate Shipment
- Create Shipment Order
- Delete Shipment Order
The DHL BCS API requires a two-level authentication (HTTP Basic Authentication and SOAP Header Authentication). The API SDK offers an authentication storage to pass credentials in.
$authStorage = new \Dhl\Sdk\Paket\Bcs\Auth\AuthenticationStorage('appId', 'appToken', 'user', 'signature');
Validate shipments for DHL Paket including the relevant shipping documents.
The library's components suitable for consumption comprise
- services:
- service factory
- shipment service
- data transfer object builder
- data transfer objects:
- authentication storage
- validation result with status message
$logger = new \Psr\Log\NullLogger();
$serviceFactory = new ServiceFactory();
$service = $serviceFactory->createShipmentService($authStorage, $logger, $sandbox = true);
$requestBuilder = new ShipmentOrderRequestBuilder();
$requestBuilder->setShipperAccount($billingNumber = '22222222220101');
$requestBuilder->setShipperAddress(
$company = 'DHL',
$country = 'DE',
$postalCode = '53113',
$city = 'Bonn',
$street = 'Charles-de-Gaulle-Straße',
$streetNumber = '20'
);
$requestBuilder->setRecipientAddress(
$recipientName = 'Jane Doe',
$recipientCountry = 'DE',
$recipientPostalCode = '53113',
$recipientCity = 'Bonn',
$recipientStreet = 'Sträßchensweg',
$recipientStreetNumber = '2'
);
$requestBuilder->setShipmentDetails($productCode = 'V01PAK', $shipmentDate = '2019-09-09');
$requestBuilder->setPackageDetails($weightInKg = 2.4);
$shipmentOrder = $requestBuilder->create();
$result = $service->validateShipments([$shipmentOrder]);
Create shipments for DHL Paket including the relevant shipping documents.
The library's components suitable for consumption comprise
- services:
- service factory
- shipment service
- data transfer object builder
- data transfer objects:
- authentication storage
- shipment with shipment/tracking number and label(s)
$logger = new \Psr\Log\NullLogger();
$serviceFactory = new ServiceFactory();
$service = $serviceFactory->createShipmentService($authStorage, $logger, $sandbox = true);
$requestBuilder = new ShipmentOrderRequestBuilder();
$requestBuilder->setShipperAccount($billingNumber = '22222222220101');
$requestBuilder->setShipperAddress(
$company = 'DHL',
$country = 'DE',
$postalCode = '53113',
$city = 'Bonn',
$street = 'Charles-de-Gaulle-Straße',
$streetNumber = '20'
);
$requestBuilder->setRecipientAddress(
$recipientName = 'Jane Doe',
$recipientCountry = 'DE',
$recipientPostalCode = '53113',
$recipientCity = 'Bonn',
$recipientStreet = 'Sträßchensweg',
$recipientStreetNumber = '2'
);
$requestBuilder->setShipmentDetails($productCode = 'V01PAK', $shipmentDate = '2019-09-09');
$requestBuilder->setPackageDetails($weightInKg = 2.4);
$shipmentOrder = $requestBuilder->create();
$shipments = $service->createShipments([$shipmentOrder]);
Cancel earlier created shipments.
The library's components suitable for consumption comprise of
- services:
- service factory
- shipment service
- data transfer objects:
- authentication storage
$logger = new \Psr\Log\NullLogger();
$serviceFactory = new ServiceFactory();
$service = $serviceFactory->createShipmentService($authStorage, $logger, $sandbox = true);
$shipmentNumber = '222201011234567890';
$cancelled = $service->cancelShipments([$shipmentNumber]);