Skip to content
Zsolt Kaveczki edited this page Sep 15, 2020 · 2 revisions

This library provides a fluid interface for constructing requests to the MyGLS REST API Service.

use GuzzleHttp\Client as HttpClient;
use Webapix\GLS\Client;
use Webapix\GLS\Models\Parcel;
use Webapix\GLS\Services\SMS;
use Webapix\GLS\Requests\PrintLabels;

$parcel = (new Parcel)
    ->setClientNumber($account->clientNumber())
    ->setPickupAddress(<class that extends \Webapix\GLS\Contracts\Address>)
    ->setDeliveryInfo(<class that extends \Webapix\GLS\Contracts\Contact>)
    ->when($order->cutomerWantsSmsAlert(), function (Parcel $parcel) use ($order) {
        return $parcel->addService(
            new SMS($order->phone_number, 'Your package (#ParcelNr#) is on its way to GLS facility!')
        );
    });

$client = new Client(new HttpClient);

$request = PrintLabels;
$request->addParcel($parcel);

/** @var \Webapix\GLS\Responses\PrintLabels $response */
$response = $client->on($account)->request($request);

if ($response->successfull()) {

    // get the pdf
    $response->getPdf()
}