PrintLabels - webapix/mygls-sdk GitHub Wiki

Calls both PrepareLabels and GetPrintedLabels in one step. So, it validates parcel data for labels, adds valid parcel data to database, generates parcel numbers and PDF document containing labels

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

$account = new DefaultAccount();

$parcel = (new Parcel)
    ->setClientNumber($account->clientNumber())
    ->setPickupAddress(<class that extends \Webapix\GLS\Contracts\Address>)
    ->setDeliveryInfo(<class that extends \Webapix\GLS\Contracts\Contact>);

$client = new Client(new HttpClient);

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

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

if ($response->successfull()) {

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

    // get the parcels information: ParcelId, ParcelNumber ...
    $response->printLabelsInfo();

}

You can set the label format:

$request->typeOfPrinter('Thermo');

Possible values: A4_2x2, A4_4x1, Connect, Thermo