PHP code example of webit / gls-tracking

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

    

webit / gls-tracking example snippets


use Doctrine\Common\Annotations\AnnotationRegistry;
use Webit\GlsTracking\Api\Factory\TrackingApiFactory;
use Webit\GlsTracking\Model\UserCredentials;

$loader = include __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

if (is_file(__DIR__ .'/config.php') == false) {
    throw new \LogicException(
        'Missing 

$credentials = new UserCredentials('user', 'pass');

$api = $apiFactory->createTrackingApi($credentials);
$details = $api->getParcelDetails($parcelNo);

/** @var \Webit\GlsTracking\Model\Event $event */
printf("Details of parcel \"%s\"\n", $parcelNo);
foreach ($details->getHistory() as $event) {
    printf(
        "%s - Status: %s (%s), Location: %s, %s (%s)\n",
        $event->getDate(),
        $event->getCode(),
        $event->getDescription(),
        $event->getLocationName(),
        $event->getCountryName(),
        $event->getLocationCode()
    );
}
printf("Received by: %s\n", $details->getSignature());

$pod = $api->getProofOfDelivery($parcelNo);

printf("Proof of delivery filename: %s\n", $pod->getFileName());
file_put_contents('/your/docs/dir/' . $pod->getFileName(), $pod->getFile());

use Webit\GlsTracking\UrlProvider\TrackingUrlProviderFactory;
$factory = new TrackingUrlProviderFactory();

/** @var array $config */

$username = 'username';

$urlProvider = $factory->createTrackingUrlProvider();

$reference = 'parcel-no';

$url = $urlProvider->getStandardTrackingUrl($reference, 'EN', 'EN');

printf("Url for tracking \"%s\" (encrypted): %s\n", $reference, $url);

$url = $urlProvider->getEncryptedTrackingUrl($credentials, $reference, $config['language']);

printf("Url for tracking \"%s\" (encrypted): %s\n", $reference, $url);

$customerReference = 'customer-ref';
$customerNo = 'customer-no';
$url = $urlProvider->getEncryptedCustomerReferenceTrackingUrl($credentials, $customerReference, $customerNo, $config['language']);

printf("Url for tracking \"%s\" with customer \"%s\": %s\n", $customerReference, $customerNo, $url);
bash
 php examples/details.php
 php examples/url-provider.php