glsgroup / sdk-api-parcel-processing
GLS Web API for Parcel Processing SDK
Installs: 3 977
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 8
Forks: 2
Open Issues: 0
Requires
- php: ^7.2.0 || ^8.0.0
- ext-json: *
- netresearch/jsonmapper: ^4.0.0
- php-http/discovery: ^1.10.0
- php-http/httplug: ^2.2.0
- php-http/logger-plugin: ^1.2.1
- psr/http-client: ^1.0.1
- psr/http-client-implementation: ^1.0.0
- psr/http-factory: ^1.0.0
- psr/http-factory-implementation: ^1.0.0
- psr/http-message: ^1.0.0
- psr/http-message-implementation: ^1.0.0
- psr/log: ^1.1.0
Requires (Dev)
- nyholm/psr7: ^1.0.0
- php-http/mock-client: ^1.5.0
- phpstan/phpstan: ^1.5.0
- phpunit/phpunit: ^8.0.0 || ^9.0.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2022-07-31 08:36:36 UTC
README
The GLS Parcel Processing API SDK package offers an interface to the following web services:
- GLS Web API for Parcel Processing
- GLS Web API for Parcel Cancellation
Requirements
System Requirements
- PHP 7.2+ with JSON extension
Package Requirements
netresearch/jsonmapper
: Mapper for deserialization of JSON response messages into PHP objectsphp-http/discovery
: Discovery service for HTTP client and message factory implementationsphp-http/httplug
: Pluggable HTTP client abstractionphp-http/logger-plugin
: HTTP client logger plugin for HTTPlugpsr/http-client
: PSR-18 HTTP client interfacespsr/http-factory
: PSR-7 HTTP message factory interfacespsr/http-message
: PSR-7 HTTP message interfacespsr/log
: PSR-3 logger interfaces
Virtual Package Requirements
psr/http-client-implementation
: Any package that provides a PSR-18 compatible HTTP clientpsr/http-factory-implementation
: Any package that provides PSR-7 compatible HTTP message factoriespsr/http-message-implementation
: Any package that provides PSR-7 HTTP messages
Development Package Requirements
nyholm/psr7
: PSR-7 HTTP message factory & message implementationphpunit/phpunit
: Testing frameworkphp-http/mock-client
: HTTPlug mock client implementationphpstan/phpstan
: Static analysis toolsquizlabs/php_codesniffer
: Static analysis tool
Installation
$ composer require glsgroup/sdk-api-parcel-processing
Uninstallation
$ composer remove glsgroup/sdk-api-parcel-processing
Testing
$ ./vendor/bin/phpunit -c test/phpunit.xml
Features
The GLS Parcel Processing API SDK supports the following features:
- Create shipments with labels
- Cancel parcels
Create Shipments
Create shipments with one or more parcels and retrieve shipping labels. Value-added services may be ordered per parcel. Return shipment labels can be requested either standalone ("return only") or together with the regular "way-to" label.
Public API
The library's components suitable for consumption comprise
- services:
- service factory
- shipment service
- data transfer object builders
- data transfer objects:
- shipment with parcels
- exceptions
Usage
$logger = new \Psr\Log\NullLogger(); $serviceFactory = new \GlsGroup\Sdk\ParcelProcessing\Service\ServiceFactory(); $service = $serviceFactory->createShipmentService('basicAuthUser', 'basicAuthPass', $logger, $sandbox = true); // REGULAR SHIPMENT $requestBuilder = new \GlsGroup\Sdk\ParcelProcessing\RequestBuilder\ShipmentRequestBuilder(); $requestBuilder->setShipperAccount($shipperId = '98765 43210'); $requestBuilder->setRecipientAddress( $country = 'DE', $postalCode = '36286', $city = 'Neuenstein', $street = 'GLS-Germany-Straße 1 - 7', $name = 'Jane Doe' ); $requestBuilder->addParcel($parcelWeightA = 0.95); $requestBuilder->addParcel($parcelWeightB = 1.2); $request = $requestBuilder->create(); $shipment = $service->createShipment($request); // work with the web service response, e.g. persist label foreach ($shipment->getLabels() as $i => $label) { file_put_contents("/tmp/{$shipment->getConsignmentId()}-{$i}.pdf", $label); } // RETURN SHIPMENT $requestBuilder = new \GlsGroup\Sdk\ParcelProcessing\RequestBuilder\ReturnShipmentRequestBuilder(); $requestBuilder->setShipperAccount($shipperId = '98765 43210'); $requestBuilder->setShipperAddress( $country = 'DE', $postalCode = '36286', $city = 'Neuenstein', $street = 'GLS-Germany-Straße 1 - 7', $name = 'Jane Doe' ); $requestBuilder->setRecipientAddress( $country = 'DE', $postalCode = '36286', $city = 'Neuenstein', $street = 'GLS Germany-Straße 1 - 7', $company = 'GLS Germany' ); $requestBuilder->addParcel($weight = 0.95, $qrCode = true); $request = $requestBuilder->create(); $shipment = $service->createShipment($request);
Cancel Parcels
Cancel one or more parcels.
Public API
The library's components suitable for consumption comprise
- services:
- service factory
- cancellation service
- exceptions
Usage
$logger = new \Psr\Log\NullLogger(); $serviceFactory = new \GlsGroup\Sdk\ParcelProcessing\Service\ServiceFactory(); $service = $serviceFactory->createCancellationService('basicAuthUser', 'basicAuthPass', $logger, $sandbox = true); $cancelledIds = $service->cancelParcels([$parcelIdA = '12345', $parcelIdB = '54321']);