|
| 1 | +# GLS Tracking SDK |
| 2 | + |
| 3 | +## Installation |
| 4 | +### via Composer |
| 5 | + |
| 6 | +Add the **webit/gls-tracking** into **composer.json** |
| 7 | + |
| 8 | +```json |
| 9 | +{ |
| 10 | + "require": { |
| 11 | + "php": ">=5.3.2", |
| 12 | + "webit/gls-tracking": "^1.0" |
| 13 | + } |
| 14 | +} |
| 15 | +``` |
| 16 | + |
| 17 | +## Configuration / Usage |
| 18 | + |
| 19 | +### API Factory preparation |
| 20 | + |
| 21 | +```php |
| 22 | +use Doctrine\Common\Annotations\AnnotationRegistry; |
| 23 | +use JMS\Serializer\EventDispatcher\EventDispatcherInterface; |
| 24 | +use JMS\Serializer\SerializerBuilder; |
| 25 | +use Webit\GlsTracking\Model\Serialiser\TuDetailsResponseDeserialisationListener; |
| 26 | +use Webit\SoapApi\SoapClient\SoapClientFactory; |
| 27 | +use Webit\GlsTracking\Api\Factory\TrackingApiFactory; |
| 28 | +use Webit\SoapApi\Input\InputNormalizerSerializerBased; |
| 29 | +use Webit\SoapApi\Hydrator\HydratorSerializerBased; |
| 30 | +use Webit\GlsTracking\Api\Exception\ExceptionFactory; |
| 31 | +use Webit\SoapApi\Util\BinaryStringHelper; |
| 32 | +use Webit\SoapApi\SoapApiExecutorFactory; |
| 33 | +use Webit\GlsTracking\Model\UserCredentials; |
| 34 | + |
| 35 | +AnnotationRegistry::registerAutoloadNamespace( |
| 36 | + 'JMS\Serializer\Annotation', |
| 37 | + __DIR__.'/../vendor/jms/serializer/src' |
| 38 | +); |
| 39 | + |
| 40 | +$builder = SerializerBuilder::create(); |
| 41 | +$builder->addDefaultListeners(); |
| 42 | +$builder->configureListeners(function (EventDispatcherInterface $dispatcher) { |
| 43 | + $dispatcher->addSubscriber(new TuDetailsResponseDeserialisationListener()); |
| 44 | +}); |
| 45 | +$serializer = $builder->build(); |
| 46 | + |
| 47 | +$clientFactory = new SoapClientFactory(); |
| 48 | +$executorFactory = new SoapApiExecutorFactory(); |
| 49 | +$normalizer = new InputNormalizerSerializerBased($serializer); |
| 50 | +$hydrator = new HydratorSerializerBased($serializer, new BinaryStringHelper()); |
| 51 | +$exceptionFactory = new ExceptionFactory(); |
| 52 | + |
| 53 | +$apiFactory = new TrackingApiFactory($clientFactory, $executorFactory, $normalizer, $hydrator, $exceptionFactory); |
| 54 | + |
| 55 | +``` |
| 56 | + |
| 57 | +### Tracking API |
| 58 | + |
| 59 | +```php |
| 60 | + |
| 61 | +$credentials = new UserCredentials('user', 'pass'); |
| 62 | + |
| 63 | +$api = $apiFactory->createTrackingApi($credentials); |
| 64 | +$details = $api->getParcelDetails($parcelNo); |
| 65 | + |
| 66 | +/** @var \Webit\GlsTracking\Model\Event $event */ |
| 67 | +printf("Details of parcel \"%s\"\n", $parcelNo); |
| 68 | +foreach ($details->getHistory() as $event) { |
| 69 | + printf( |
| 70 | + "%s - Status: %s (%s), Location: %s, %s (%s)\n", |
| 71 | + $event->getDate(), |
| 72 | + $event->getCode(), |
| 73 | + $event->getDescription(), |
| 74 | + $event->getLocationName(), |
| 75 | + $event->getCountryName(), |
| 76 | + $event->getLocationCode() |
| 77 | + ); |
| 78 | +} |
| 79 | +printf("Received by: %s\n", $details->getSignature()); |
| 80 | + |
| 81 | +$pod = $api->getProofOfDelivery($parcelNo); |
| 82 | +printf("Proof of delivery filename: %s\n", $pod->getFileName()); |
| 83 | +``` |
| 84 | + |
| 85 | +### Tracking Url Provider |
| 86 | + |
| 87 | +```php |
| 88 | +use Webit\GlsTracking\UrlProvider\TrackingUrlProviderFactory; |
| 89 | +$factory = new TrackingUrlProviderFactory(); |
| 90 | + |
| 91 | +/** @var array $config */ |
| 92 | + |
| 93 | +$username = 'username'; |
| 94 | + |
| 95 | +$urlProvider = $factory->createTrackingUrlProvider(); |
| 96 | + |
| 97 | +$reference = 'parcel-no'; |
| 98 | + |
| 99 | +$url = $urlProvider->getStandardTrackingUrl($reference, 'EN', 'EN'); |
| 100 | + |
| 101 | +printf("Url for tracking \"%s\" (encrypted): %s\n", $reference, $url); |
| 102 | + |
| 103 | +$url = $urlProvider->getEncryptedTrackingUrl($credentials, $reference, $config['language']); |
| 104 | + |
| 105 | +printf("Url for tracking \"%s\" (encrypted): %s\n", $reference, $url); |
| 106 | + |
| 107 | +$customerReference = 'customer-ref'; |
| 108 | +$customerNo = 'customer-no'; |
| 109 | +$url = $urlProvider->getEncryptedCustomerReferenceTrackingUrl($credentials, $customerReference, $customerNo, $config['language']); |
| 110 | + |
| 111 | +printf("Url for tracking \"%s\" with customer \"%s\": %s\n", $customerReference, $customerNo, $url); |
| 112 | +``` |
| 113 | + |
| 114 | +### Examples |
| 115 | + |
| 116 | +To configure the examples: |
| 117 | + * Copy ***examples/config.php.dist*** to ***examples/config.php*** |
| 118 | + * Change the values accordingly |
| 119 | + |
| 120 | + |
| 121 | +Run: |
| 122 | + ```bash |
| 123 | + php examples/details.php |
| 124 | + php examples/url-provider.php |
| 125 | + ``` |
| 126 | + |
0 commit comments