rafalli / dpd-info-services-bundle
Symfony 7.4 Bundle integrating DPD InfoServices SOAP API for tracking packages
Package info
github.com/rafalli/dpd-info-services-bundle
Type:symfony-bundle
pkg:composer/rafalli/dpd-info-services-bundle
Requires
- php: >=8.1
- ext-soap: *
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
- symfony/translation: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.5 || ^11.0
- symfony/phpunit-bridge: ^6.4 || ^7.0 || ^8.0
README
Installation
Install the package via Composer:
composer require rafalli/dpd-info-services-bundle
Configuration
- Create a configuration file
rafalli_dpd_info_services.yamlin your Symfony project:
rafalli_dpd_info_services: wsdl_url: '%env(DPD_WSDL_URL)%' channel: '%env(int:DPD_CHANNEL)%' username: '%env(DPD_USERNAME)%' password: '%env(DPD_PASSWORD)%'
- Add your DPD credentials to your
.envfile:
DPD_WSDL_URL="https://dpdinfoservices.dpd.com.pl/DPDInfoServicesObjEventsService/DPDInfoServicesObjEvents?wsdl"
DPD_CHANNEL=12345
DPD_USERNAME=your_login
DPD_PASSWORD=your_password
Usage
Basic Interaction
Inject the DpdInfoServiceClientInterface and use the following pattern to handle tracking updates:
use Rafalli\DpdInfoServicesBundle\Dto\Request\RetrievalContextDto; use Rafalli\DpdInfoServicesBundle\Dto\Response\DpdEventDto; use Rafalli\DpdInfoServicesBundle\Exception\DpdApiException; use Rafalli\DpdInfoServicesBundle\Service\DpdInfoServiceClientInterface; // Inject the interface via constructor public function __construct( private readonly DpdInfoServiceClientInterface $dpdClient ) {} // Fetch and process events try { $response = $this->dpdClient->fetchNewEvents(new RetrievalContextDto(limit: 100)); foreach ($response->events as $event) { // $event is an instance of DpdEventDto // Access data: $event->waybill, $event->eventCode, $event->newWaybill } // Confirm processing (Required by DPD API to clear the queue) if ($response->requiresConfirmation()) { $this->dpdClient->markAsProcessed($response->confirmId); } } catch (DpdApiException $e) { // Handle connection or API errors }
Checking a Single Waybill
To check the history of a specific parcel without affecting the global event queue:
$history = $this->dpdClient->getWaybillHistory('0000000000000U');
Delivery Tracking Utility
If you only need to know whether a parcel was successfully delivered (and exactly when), you can use the built-in WaybillDeliveryTrackerInterface which provides clean and easy-to-use domain logic.
use Rafalli\DpdInfoServicesBundle\Service\WaybillDeliveryTrackerInterface; public function __construct( private readonly WaybillDeliveryTrackerInterface $deliveryTracker ) {} public function checkStatus(string $waybill): void { // Returns true if the parcel is marked as delivered (including COD deliveries) if ($this->deliveryTracker->isDelivered($waybill)) { } } public function checkDeliveryDate(string $waybill): void { // Returns the DateTimeImmutable object of the exact delivery moment $date = $this->deliveryTracker->getDeliveryDate($waybill); }
Translations
The bundle provides an EventCode Enum that integrates with Symfony's Translation component. You can render translated descriptions directly in Twig:
{# Translation Domain: rafalli_dpd_info_services #} {{ eventDto.eventCode.translationKey | trans({}, 'rafalli_dpd_info_services') }}
Error Handling
All SOAP-related errors or validation issues throw a Rafalli\DpdInfoServicesBundle\Exception\DpdApiException. This exception encapsulates the original SoapFault, making it easy to debug while keeping your application domain clean.
License
MIT License