PHP code example of dhl / sdk-api-parcel-de
1. Go to this page and download the library: Download dhl/sdk-api-parcel-de 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/ */
dhl / sdk-api-parcel-de example snippets
$authStorage = new \Dhl\Sdk\ParcelDe\Shipping\Auth\AuthenticationStorage('apiKey', 'user', 'password');
$logger = new \Psr\Log\NullLogger();
$serviceFactory = new \Dhl\Sdk\ParcelDe\Shipping\Service\ServiceFactory();
$service = $serviceFactory->createShipmentService($authStorage, $logger, $sandbox = true);
$requestBuilder = new \Dhl\Sdk\ParcelDe\Shipping\RequestBuilder\ShipmentOrderRequestBuilder();
$requestBuilder->setShipperAccount($billingNumber = '33333333330101');
$requestBuilder->setShipperAddress(
company: 'DHL',
country: 'DEU',
postalCode: '53113',
city: 'Bonn',
street: 'Charles-de-Gaulle-Straße',
streetNumber: '20'
);
$requestBuilder->setRecipientAddress(
recipientName: 'Jane Doe',
recipientCountry: 'DEU',
recipientPostalCode: '53113',
recipientCity: 'Bonn',
recipientStreet: 'Sträßchensweg',
recipientStreetNumber: '2'
);
$requestBuilder->setShipmentDetails(productCode: 'V01PAK', shipmentDate: new \DateTimeImmutable('2023-02-23'));
$requestBuilder->setPackageDetails(weightInKg: 2.4);
$shipmentOrder = $requestBuilder->create();
$result = $service->validateShipments([$shipmentOrder]);
$logger = new \Psr\Log\NullLogger();
$serviceFactory = new \Dhl\Sdk\ParcelDe\Shipping\Service\ServiceFactory();
$service = $serviceFactory->createShipmentService($authStorage, $logger, sandbox: true);
$orderConfiguration = new \Dhl\Sdk\ParcelDe\Shipping\Service\ShipmentService\OrderConfiguration(
mustEncode: true,
combinedPrinting: null,
docFormat: \Dhl\Sdk\ParcelDe\Shipping\Api\Data\OrderConfigurationInterface::DOC_FORMAT_PDF,
printFormat: \Dhl\Sdk\ParcelDe\Shipping\Api\Data\OrderConfigurationInterface::PRINT_FORMAT_A4
);
$requestBuilder = new \Dhl\Sdk\ParcelDe\Shipping\RequestBuilder\ShipmentOrderRequestBuilder();
$requestBuilder->setShipperAccount(billingNumber: '33333333330101');
$requestBuilder->setShipperAddress(
company: 'DHL',
country: 'DEU',
postalCode: '53113',
city: 'Bonn',
streetName: 'Charles-de-Gaulle-Straße',
streetNumber: '20'
);
$requestBuilder->setRecipientAddress(
name: 'Jane Doe',
countryCode: 'DEU',
postalCode: '53113',
city: 'Bonn',
streetName: 'Sträßchensweg',
streetNumber: '2'
);
$requestBuilder->setShipmentDetails(productCode: 'V01PAK', shipmentDate: new \DateTimeImmutable('2023-02-23'));
$requestBuilder->setPackageDetails(weightInKg: 2.4);
$shipmentOrder = $requestBuilder->create();
$shipments = $service->createShipments([$shipmentOrder], $orderConfiguration);
$logger = new \Psr\Log\NullLogger();
$serviceFactory = new \Dhl\Sdk\ParcelDe\Shipping\Service\ServiceFactory();
$service = $serviceFactory->createShipmentService($authStorage, $logger, sandbox: true);
$shipmentNumber = '333301011234567890';
$cancelled = $service->cancelShipments([$shipmentNumber]);