PHP code example of dhl / sdk-api-bcs
1. Go to this page and download the library: Download dhl/sdk-api-bcs 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-bcs example snippets
// BCS
$authStorage = new \Dhl\Sdk\Paket\Bcs\Auth\AuthenticationStorage('appId', 'appToken', 'user', 'signature');
// Parcel DE Shipping
$authStorage = new \Dhl\Sdk\Paket\Bcs\Auth\AuthenticationStorage('', 'apiKey', 'user', 'password');
$serviceFactory = new \Dhl\Sdk\Paket\Bcs\Service\ServiceFactory(
\Dhl\Sdk\Paket\Bcs\Api\ServiceFactoryInterface::API_TYPE_REST
);
$requestBuilder = new \Dhl\Sdk\Paket\Bcs\RequestBuilder\ShipmentOrderRequestBuilder(
\Dhl\Sdk\Paket\Bcs\Api\ShipmentOrderRequestBuilderInterface::REQUEST_TYPE_REST
);
$logger = new \Psr\Log\NullLogger();
$serviceFactory = new \Dhl\Sdk\Paket\Bcs\Service\ServiceFactory();
$service = $serviceFactory->createShipmentService($authStorage, $logger, $sandbox = true);
$requestBuilder = new \Dhl\Sdk\Paket\Bcs\RequestBuilder\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 = new \DateTime());
$requestBuilder->setPackageDetails($weightInKg = 2.4);
$shipmentOrder = $requestBuilder->create();
$result = $service->validateShipments([$shipmentOrder]);
$logger = new \Psr\Log\NullLogger();
$serviceFactory = new \Dhl\Sdk\Paket\Bcs\Service\ServiceFactory();
$service = $serviceFactory->createShipmentService($authStorage, $logger, $sandbox = true);
$orderConfiguration = new \Dhl\Sdk\Paket\Bcs\Service\ShipmentService\OrderConfiguration(
$printOnlyIfCodable = true,
$combinedPrinting = null,
$docFormat = \Dhl\Sdk\Paket\Bcs\Api\Data\OrderConfigurationInterface::DOC_FORMAT_PDF,
$printFormat = \Dhl\Sdk\Paket\Bcs\Api\Data\OrderConfigurationInterface::PRINT_FORMAT_A4
);
$requestBuilder = new \Dhl\Sdk\Paket\Bcs\RequestBuilder\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 = new \DateTime());
$requestBuilder->setPackageDetails($weightInKg = 2.4);
$shipmentOrder = $requestBuilder->create();
$shipments = $service->createShipments([$shipmentOrder], $orderConfiguration);
$logger = new \Psr\Log\NullLogger();
$serviceFactory = new \Dhl\Sdk\Paket\Bcs\Service\ServiceFactory();
$service = $serviceFactory->createShipmentService($authStorage, $logger, $sandbox = true);
$shipmentNumber = '222201011234567890';
$cancelled = $service->cancelShipments([$shipmentNumber]);