elcuro/qdl-php-client

Simple PHP client for QDL

dev-master 2024-05-23 22:01 UTC

README

About

A simple PHP client for the QDL (Slovak logistics company)

Installation

Install this package as a dependency using Composer.

composer require elcuro/qdl-php-client

Usage

Create QDL client

The client is not dependent on any specific HTTP client. It supports any PSR-18 compatible client. E.g.: Buzz client

You do also need to install a PSR-17 request/response factory. It uses that factory to create PSR-7 requests and responses. E.g.: nyholm/psr7

use Elcuro\QdlPhpClient\Client\Client;
use Nyholm\Psr7\Factory\Psr17Factory;
use Buzz\Client\Curl;

// We will use Buzz client and nyholm/psr7 factories
$factory = new Psr17Factory();

$client = new Client(
    new Curl($factory),
    $factory,
    $factory,
    'QDL_USERNAME',
    'QDL_PASSWORD'
);

Add/order/cancel shipments

use Elcuro\QdlPhpClient\Shipping\Shipment\Shipment;
use Elcuro\QdlPhpClient\Shipping\Shipment\ShipmentPackage;
use Elcuro\QdlPhpClient\Shipping\ShipmentManager;

// Create shipment manager
$shipmentManager = new ShipmentManager($client, new AddedShipmentFactory());

// Create shipment
$shipment = new Shipment();
$shipment
    ->setSenderId(1)
    ->setRecipientName('Fake user')
    //...
    ->addPackage(new ShipmentPackage(1))
;

// Add shipment
$addedShipment = $shipmentManager->addShipment($shipment);

// Order unordered shipments
$shipmentManager->order();

// Cancel shipment
$shipmentManager->cancelShipment($addedShipment->getId());

Labels and handover protocols

use Elcuro\QdlPhpClient\Document\DocumentFactory;
use Elcuro\QdlPhpClient\Document\DocumentFetcher;
use Elcuro\QdlPhpClient\Document\Label\LabelType;


// Create document fetcher
$documentFetcher = new DocumentFetcher($client, new DocumentFactory());

// Show label PDF
echo $documentFetcher->fetchLabel([30124122200010], LabelType::A4)->getPDF();

// or show handover protocol
echo $documentFetcher->fetchHandoverProtocol([30124122200010])->getPDF();

Tracking

use Elcuro\QdlPhpClient\Tracking\TrackLog\TrackLogsFactory;
use Elcuro\QdlPhpClient\Tracking\Tracker;

// Create tracker
$tracker = new Tracker($client, new TrackLogsFactory());

// Fetch track logs
$trackLogs = $tracker->trackShipment(30124122200010);

// Show track logs
foreach ($trackLogs as $trackLog) {
    sprintf(
        "Date: %s, Status: %s\n",
        $trackLog->getDate()->format('Y-m-d'),
        $trackLog->getName()
    );
}

Contributing

Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.

Copyright and License

elcuro/qdl-php-client is copyright © Juraj Jancuska and licensed for use under the terms of the MIT License (MIT). Please see LICENSE for more information.