Download the PHP package omobude/dhl-symfony-bundle without Composer
On this page you can find all versions of the php package omobude/dhl-symfony-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dhl-symfony-bundle
DHL Symfony Bundle
Modern Symfony 7+ bundle for DHL API integration. Create shipment labels, view and download DHL shipments label with ease using OAuth authentication.
Features
- ๐ Create DHL shipments
- ๐ฆ Download shipping labels (PDF)
- ๐ OAuth 2.0 authentication with automatic token management
- โก Token caching for optimal performance
- ๐งช Sandbox mode for testing
- ๐ Comprehensive logging support
- ๐ฏ Type-safe models with PHP 8.2+
- ๐ฌ๐ง Northern Ireland clearance declaration support (Windsor Framework / UKIMS)
- ๐ Modern Symfony 7 integration
Requirements
- PHP 8.2 or higher
- Symfony 7.0 or higher
- Symfony Cache component
- DHL Developer Account (Sign up here)
Table of Contents
- Installation
- Getting DHL Credentials
- Usage
- Creating a Shipment
- Northern Ireland Shipments (Clearance Declaration)
- Downloading a Label
- Configuration Reference
- Switching to Production
- Troubleshooting
- Contributing
- License
Installation
Step 1: Install the Bundle
Step 2: Register the Bundle (If Not Auto-Registered)
If Symfony Flex doesn't automatically register the bundle, manually add it to config/bundles.php:
Note: With Symfony Flex, this step is usually automatic. Only add this manually if you encounter the error: "There is no extension able to load the configuration for 'omobude_dhl'".
Step 3: Configure Environment Variables
Add your DHL credentials to your .env file:
Step 4: Create Bundle Configuration
Create the file config/packages/omobude_dhl.yaml:
Step 5: Clear Cache
Getting DHL Credentials
For Sandbox (Testing)
- Go to DHL Developer Portal
- Sign up for a free account
- Create a new application
- Navigate to your application settings
- Copy your Client ID and Client Secret
- Use these credentials in your
.envfile
For Production
- Contact DHL to request production API access
- Complete any required business verification
- Receive your production Client ID and Client Secret
- Update your production environment variables
- Set
sandbox: falsein your configuration
Usage
Creating a Shipment
Northern Ireland Shipments (Clearance Declaration)
Shipments delivered to Northern Ireland (postcodes starting with BT) require an additional clearance declaration under the Windsor Framework / UK Internal Market Scheme (UKIMS). The bundle automatically detects Northern Ireland postcodes and will throw a BadRequestHttpException if a clearance declaration is missing.
When is a Clearance Declaration Required?
| Destination | Postcode Prefix | Clearance Declaration |
|---|---|---|
| Great Britain (England, Scotland, Wales) | Most UK postcodes | โ Not required |
| Northern Ireland | BT |
โ Required |
Building a Clearance Declaration
A clearance declaration is composed of two model classes:
ClearanceDeclarationโ top-level customs information for the shipmentClearanceItemโ line-item details for each product in the shipment
ClearanceDeclaration Fields
| Field | Type | Required | Description |
|---|---|---|---|
shipmentMovementType |
string | Yes | Movement type โ B2C (business to consumer) or B2B (business to business) |
totalValue |
float | Yes | Total declared value of goods (excluding shipping costs) |
numberOfItems |
int | Yes | Total number of items across all line items |
items |
ClearanceItem[] |
Yes | Array of ClearanceItem objects, one per line item |
sendersEORINumber |
string | No | Sender's EORI (Economic Operators Registration and Identification) number |
sendersUKIMSNumber |
string | No | Sender's UKIMS (UK Internal Market Scheme) authorisation number |
Note on EORI / UKIMS: Although marked optional in the model, most B2C movements into Northern Ireland under the Windsor Framework will require a valid UKIMS number to qualify for the green-lane "not at risk" treatment. Check your DHL contract and current HMRC guidance before omitting these fields.
ClearanceItem Fields
| Field | Type | Required | Description |
|---|---|---|---|
descriptionOfGoods |
string | Yes | Plain-English description of the goods (e.g. "Cotton T-Shirt") |
unitQuantity |
int | Yes | Quantity of this item being shipped |
commodityCode |
string | No | HS / commodity tariff code (e.g. "6109100010"). Strongly recommended for customs clearance |
Validation Behaviour
The bundle enforces clearance declaration rules at the point of calling toArray() on ShipmentData (which happens automatically inside DhlApiClient::createShipment()):
- โ NI postcode + clearance declaration present โ shipment proceeds
- โ NI postcode + no clearance declaration โ throws
BadRequestHttpException - โ GB postcode + no clearance declaration โ shipment proceeds
- โ GB postcode + clearance declaration present โ shipment proceeds (declaration is included)
Always catch BadRequestHttpException separately if you want to surface clear validation errors to your users before the request hits the DHL API.
Downloading a Label
Checking Sandbox Mode
Configuration Reference
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
client_id |
string | Yes | - | Your DHL OAuth Client ID |
client_secret |
string | Yes | - | Your DHL OAuth Client Secret |
sandbox |
boolean | Yes | Enable sandbox/testing mode |
DHL Product Codes
Common product codes for orderedProduct:
| Code | Service | Delivery Time |
|---|---|---|
1 |
DHL Parcel | Next day |
48 |
DHL Parcel Neighbour | 48 hours |
Recipient Types
Valid values for recipientType:
residential- Home deliverybusiness- Business address
Address Types
Valid values for addressType:
doorstep- Standard deliveryneighbour- Deliver to neighbour if recipient not available
Shipment Movement Types
Valid values for ClearanceDeclaration::$shipmentMovementType:
B2C- Business to consumerB2B- Business to business
Switching to Production
Step 1: Update Environment Variables
Update your production .env file:
Step 3: Clear Production Cache
Step 4: Test in Production
Always test with a single shipment first to ensure everything works correctly.
Troubleshooting
Bundle Not Registered
Problem: "There is no extension able to load the configuration for 'omobude_dhl'"
Solution:
-
Ensure the bundle is registered in
config/bundles.php: - Clear the cache:
php bin/console cache:clear - Verify installation:
composer show omobude/dhl-symfony-bundle
Authentication Errors
Problem: "Authentication failed" or "Invalid credentials"
Solution:
- Verify your Client ID and Client Secret are correct
- Ensure you're using sandbox credentials with
sandbox: true - Check that credentials are properly set in
.env - Try clearing the token cache:
php bin/console cache:clear
Configuration Errors
Problem: "The child config 'client_id' under 'omobude_dhl' must be configured"
Solution:
- Ensure
config/packages/omobude_dhl.yamlexists - Verify the configuration syntax is correct
- Check that environment variables are defined in
.env - Run
php bin/console debug:config omobude_dhlto verify
Northern Ireland Clearance Errors
Problem: BadRequestHttpException: Clearance declaration is required for Northern Ireland deliveries (postcode: BT1 5GS).
Solution:
- The destination postcode starts with
BT(Northern Ireland), so aClearanceDeclarationmust be passed toShipmentData - See the Northern Ireland Shipments section for a full example
- Make sure your
ClearanceDeclarationincludes a validshipmentMovementType,totalValue,numberOfItems, and at least oneClearanceItem - For most B2C movements, also include a valid UKIMS number via
sendersUKIMSNumber
Token Caching Issues
Problem: "Cached token expired" or authentication errors after some time
Solution:
- The bundle automatically refreshes tokens
- Clear cache if issues persist:
php bin/console cache:clear - Check cache directory permissions:
var/cache/should be writable - Verify
symfony/cacheis installed
API Errors
Problem: DHL API returns error codes
Solution:
- Check DHL API Documentation for error codes
- Enable logging to see detailed error messages
- Verify all required fields are provided
- Ensure addresses are in the correct format
Debugging
Enable detailed logging:
Check logs:
Verify bundle configuration:
Environment-Specific Configuration
Development
Staging
Production
Security Best Practices
- Never commit credentials - Add
.envto.gitignore - Use environment variables - Store credentials in environment, not code
- Separate environments - Use different credentials for dev/staging/prod
- Monitor access logs - Check DHL dashboard for unusual activity
- Use HTTPS only - The bundle uses HTTPS by default
- Limit permissions - Only grant necessary access to DHL accounts
Recommended .gitignore
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Write tests for your changes
- Ensure all tests pass:
./vendor/bin/phpunit - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Coding Standards
- Follow PSR-12 coding standards
- Use PHP 8.2+ features (typed properties, readonly, etc.)
- Write PHPDoc comments for all public methods
- Add tests for new features
License
This bundle is released under the MIT License. See the LICENSE file for details.
Author
Omobude Kelly
- GitHub: @komobude2021
- Email: [email protected]
Support
Need help? Here are your options:
- ๐ Read the Documentation
- ๐ Report Issues
- ๐ฌ GitHub Discussions
- ๐ง Email Support
- ๐ DHL API Documentation
Acknowledgments
- Built for the Symfony community
- Powered by DHL API
- Inspired by modern Symfony best practices
Made with โค๏ธ for the Symfony community
If this bundle helped you, please consider giving it a โญ on GitHub!
All versions of dhl-symfony-bundle with dependencies
psr/log Version ^3.0
symfony/cache Version ^7.0
symfony/framework-bundle Version ^7.0
symfony/http-client Version ^7.0
symfony/dependency-injection Version ^7.0
symfony/config Version ^7.0