slince / shipment-tracking-foundation
A flexible and shipment tracking library for multi carriers.
Installs: 1 011
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=5.6.0
- guzzlehttp/guzzle: ^6.0
Requires (Dev)
- phpunit/phpunit: ^5.0|^6.0
This package is auto-updated.
Last update: 2024-11-08 19:53:39 UTC
README
A flexible and shipment tracking library for multi carriers.
Basic Usage
$tracker = new Slince\ShipmentTracking\DHLECommerce\DHLECommerceTracker(CLIENT_ID, PASSWORD); try { $shipment = $tracker->track('CNAQV100168101'); if ($shipment->isDelivered()) { echo "Delivered"; } echo $shipment->getOrigin(); echo $shipment->getDestination(); print_r($shipment->getEvents()); //print the shipment events } catch (Slince\ShipmentTracking\Exception\TrackException $exception) { exit('Track error: ' . $exception->getMessage()); }
How to create your own tracker?
All shipment trackers must implement Slince\ShipmentTracking\Foundation\TrackerInterface
, and will usually extend Slince\ShipmentTracking\Foundation\HttpAwareTracker
for basic functionality if the carrier's api is based on
HTTP
namespace My\Tracker; use Slince\ShipmentTracking\Foundation\HttpAwareTracker; use Slince\ShipmentTracking\Foundation\Shipment; class MyTracker extends HttpAwareTracker { /** * {@inheritdoc} */ public function track($trackingNumber) { $response = $this->getHttpClient()->get('/../endpoint', [ 'query' => [ 'tracking_number' => $trackingNumber ] ]); return static::buildShipment($response): } /** * @return Shipment */ public function buildShipment($response) { //.... } } $tracker = new MyTracker(); $shipment = $tracker->track('foo-tracking-number'); print_r($shipment):
You can extend all existing classes if you need.
Shipment trackers:
The following carriers are available:
License
The MIT license. See MIT