Skip to content

GLS ADE and GLS Track & Trace API Symfony 2 integration

License

Notifications You must be signed in to change notification settings

gokuale/gls-bundle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

WebitGlsBundle

GLS ADE and GLS Track & Trace API Symfony 2 integration

Installation

via Composer

Add the webit/gls-bundle into composer.json

{
    "require": {
        "php":              ">=5.3.2",
        "webit/gls-bundle": "dev-master"
    },
    "autoload": {
        "psr-0": {
            "Acme": "src/"
        }
    }
}

Register bundle in Kernel

Add following lines:

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Webit\Bundle\SoapApiBundle\WebitSoapApiBundle(),
    new Webit\Bundle\GlsBundle\WebitGlsBundle(),
    // ...
);

Configuration

You can define as much accounts as you need (ADE Accounts and Track & Trace as well)

webit_gls:
   ade_accounts:
       my-production-account:
           username: my-ade-username
           password: my-ade-password
           test_mode: false
       my-test-account:
           username: my-ade-test-username
           password: my-ade-test-password
           test_mode: true
      track_accounts:
          my-account:
              username: my-track-and-trace-username
              password: my-track-and-trace-password
              test_mode: false

Usage

To use GLS APIs you need AccountManager ('webit_gls.account_manager'), ApiProvider ('webit_gls.api_provider'), and TrackingUrlProvider ('webit_gls.tracking.url_provider'). You can get them directly from Service Container or inject them to your class.

<?php
namespace Acme\Bundle\AcmeBundle\Controller;
 
use Webit\Bundle\GlsBundle\Api\ApiProviderInterface;
use Webit\Bundle\GlsBundle\Account\AccountManagerInterface;
use Webit\GlsTracking\UrlProvider\TrackingUrlProvider;

class MyController
{
 
    /**
     * @var AccountManagerInterface
     */
    private $accountManager;
    
    /**
     * @var ApiProviderInterface
     */
    private $apiProvider;

    /**
     * @var TrackingUrlProvider
     */
    private $trackingUrlProvider;

    public function __construct(
        AccountManagerInterface $accountManager,
        ApiProviderInterface $apiProvider,
        TrackingUrlProvider $trackingUrlProvider
    ) {
        $this->accountManager = $accountManager;
        $this->apiProvider = $apiProvider;
        $this->trackingUrlProvider = $trackingUrlProvider;
    }
    
    public function consignmentPrepareAction()
    {
        /** @var \Webit\Bundle\GlsBundle\Account\AdeAccount */
        $account = $this->accountManager->getAdeAccount('my-test-account');
        
        /** @var \Webit\GlsAde\Api\ConsignmentPrepareApi */
        $consignmentPrepareApi = $this->apiProvider->getConsignmentPrepareApi($account);
        
        // do your stuff with API
    }
    
    public function checkParcelStatusAction()
    {
        /** @var \Webit\Bundle\GlsBundle\Account\TrackAccount */
        $account = $this->accountManager->getTrackAccount('my-account');
            
        /** @var \Webit\GlsTracking\Api\TrackingApi */
        $trackingApi = $this->apiProvider->getTrackingApi($account);
            
        // do your stuff with API
    }

    public function getTrackingUrlAction($reference, $country = 'EN')
    {
        $url = $trackingUrlProvider->getStandardTrackingUrl($reference, $country);

        // do your stuff with URL
    }
}

To learn how to use GLS APIs see:

About

GLS ADE and GLS Track & Trace API Symfony 2 integration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 95.1%
  • Gherkin 4.9%