PHP code example of slince / shipment-tracking-foundation

1. Go to this page and download the library: Download slince/shipment-tracking-foundation 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/ */

    

slince / shipment-tracking-foundation example snippets



$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());
}


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):