Download the PHP package quitenoisemaker/shipping-tracker without Composer
On this page you can find all versions of the php package quitenoisemaker/shipping-tracker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package shipping-tracker
ShippingTracker
A Laravel package to simplify shipment tracking and webhook handling for Africa and Europe logistics. Supports providers like Cargoplug, Sendbox, and DHL, with an open-source spirit welcoming contributions.
Features
- Track shipments with a unified interface via DTOs.
- Handle webhooks from couriers effortlessly.
- Store tracking history in a
shippingstable. - Queue webhook processing with the
databasedriver. - Extensible for custom providers.
- Normalize provider-specific statuses (e.g., "In transit" ->
in_transit) - [New] CLI commands for tracking and health checks.
- [New]
FakeShippingProviderfor easy testing.
Requirements
- PHP 8.1, 8.2, or 8.3
- Laravel 10 or 11
- Composer
Installation
-
Install via Composer:
-
Publish the configuration and migrations:
-
Run migrations to create the
shipping_webhooksandjobstables: -
Add Environment Variables
Update your
.envfile:
Configuration
The config/shipping-tracker.php file allows you to:
- Set the default provider (e.g.,
dhl). - Define provider classes and their API credentials.
- Add new providers by mapping keys to their implementation classes.
Note: Providers like (Sendbox and Cargoplug) do not use tracking number prefixes or webhook signatures. The package caches successful provider matches for known tracking numbers to optimize tracking. New tracking numbers trigger a full provider search, and explicit provider selection via use() is respected without affecting the cache.
Example:
Usage
Tracking a Shipment
Track a single shipment. If no provider is specified, the package tries all configured providers, caching the successful provider for the tracking number. New tracking numbers trigger a full provider search.
Explicitly specify a provider to bypass automatic resolution and caching:
The response is a strict TrackingResult object, not an array.
Tracking Multiple Shipments
Track multiple shipments in one call (client-side, as providers do not support batch API calls):
The response is an array keyed by tracking number, with results or error messages.
CLI Commands (New in v2.0)
Track a shipment directly from your terminal:
Check API Health: Validate your configuration and API keys for all providers:
Testing with Fakes
You can use the FakeShippingProvider to test your application without making real API calls.
Tracking History
Shipment updates from webhooks are stored in the shipments table, including tracking_number, provider, status, location, estimated_delivery, and history.
Retrieve a shipment’s history:
Or use the convenience method:
Handling Webhooks
Webhooks are validated for required fields. *
- Default required fields for Cargoplug and Sendbox:
-
- tracking_number
-
- status
- DHL specific required field:
-
- self (the subscription URL, always starting with https://api-eu.dhl.com)
-
- scope
- The package is extensible for signature-based validation for providers that support webhook signing.
Register the webhook URL (e.g., https://your-app.com/api/shipping/webhooks/sendbox) with your provider.
Status Normalization
ShippingTracker normalizes provider statuses using StatusMapper in both webhooks and API tracking (track method). It handles case and space variations (e.g., Cargoplug's "In Transit" → in_transit, "PAID" → paid). Examples:
- Sendbox:
delivery_started→in_transit,delivered→delivered - Cargoplug:
received_abroad→in_transit,In Transit→in_transit,delivered→delivered - DHL:
CUSTOMER PICKUP→delivered,PACKAGE SCREENED SUCCESSFULLY→in_transit,ATTEMPTED DELIVERY→on_hold
Extending the Package
Create a custom provider:
-
Create a class implementing
Quitenoisemaker\ShippingTracker\Contracts\ShippingProvider: -
Register it in
config/shipping-tracker.php: - Use it:
Troubleshooting
- API Credential Errors:
- Ensure
CARGOPLUG_API_KEYandSENDBOX_API_KEYare set in.env. - Verify keys with your provider’s dashboard.
- Test with:
php artisan tinkerand$tracker->use('cargoplug')->track('test_number').
- Ensure
- Webhook Not Received:
- Confirm the webhook URL is correct (e.g.,
your-app.com/shipping/webhook). - Check
shipping_webhookstable for entries. - Ensure the queue worker is running:
php artisan queue:work. - Verify your server allows POST requests (e.g., no firewall blocks).
- Confirm the webhook URL is correct (e.g.,
- Queue Issues:
- Ensure
QUEUE_CONNECTION=databasein.env. - Check
jobstable exists:php artisan migrate. - Clear cache:
php artisan config:cache.
- Ensure
- Test Failures:
- Run
composer installto ensure dependencies. - Check
phpunit.xmlfor correct database settings. - Share errors with the community (see Contributing).
- Run
Testing
Run tests with:
Changelog
v2.0.0 (Latest)
- [Breaking]
track()now returnsTrackingResultDTO instead of an array. - Added
shipping:trackandshipping:check-statusArtisan commands. - Added
FakeShippingProviderfor testing. - Added
checkHealth()toShippingProviderInterface. - Implemented lazy loading for providers to improve robustness.
v1.2.0
- Added DHL integration for tracking and webhook handling.
- Normalized DHL statuses.
v1.0.0
- Initial release.
- Supports Cargoplug and Sendbox providers.
- Features tracking, webhook handling, and history storage.
Contributing
We love open source! Join us by contributing at github.com/quitenoisemaker/shipping-tracker. See CONTRIBUTING.md for how to submit issues or pull requests.
License
MIT License. See LICENSE for details.
All versions of shipping-tracker with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0
illuminate/cache Version ^9.0|^10.0|^11.0|^12.0
illuminate/events Version ^9.0|^10.0|^11.0|^12.0
illuminate/log Version ^9.0|^10.0|^11.0|^12.0
guzzlehttp/guzzle Version ^7.9