PHP code example of beziworld / laravel-globkurier

1. Go to this page and download the library: Download beziworld/laravel-globkurier library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

beziworld / laravel-globkurier example snippets


use Beziworld\GlobKurier\Data\ProductQuery;
use Beziworld\GlobKurier\Enums\CollectionType;
use Beziworld\GlobKurier\Facades\GlobKurier;

$query = new ProductQuery(
    length: 30, width: 20, height: 10, weight: 1.5,
    senderCountry: 'PL', receiverCountry: 'PL',         // ISO codes or GlobKurier ids
    senderPostCode: '00-001', receiverPostCode: '30-001',
    collectionTypes: [CollectionType::Pickup],
    deliveryTypes: [CollectionType::Point],
    addonCategories: ['CASH_ON_DELIVERY'],
);

$products = GlobKurier::products($query);              // list<Product>, every delivery time group
$product = GlobKurier::cheapestProduct($query, 'DPD');
$product->id;            // productId for add-ons, points, prices and the order
$product->grossPrice;    // "12.40" with the fuel surcharge

$addons = GlobKurier::addons($product->id, $query, cashOnDeliveryValue: 149.99, insuranceValue: 149.99);
$cod = $addons->cheapestFor('CASH_ON_DELIVERY', 149.99);
$insurance = $addons->cheapestFor('INSURANCE', 149.99);   // 

use Beziworld\GlobKurier\Data\Address;
use Beziworld\GlobKurier\Data\AddonSelection;
use Beziworld\GlobKurier\Data\OrderRequest;
use Beziworld\GlobKurier\Data\Pickup;

$sender = new Address('ACME Sp. z o.o.', 'Prosta', '1', '00-001', 'Warszawa', '500600700', '[email protected]');
$receiver = new Address('Anna Kowalska', 'Długa', '5', '30-001', 'Kraków', '600700800', '[email protected]', pointId: 'KRA01M');

$windows = GlobKurier::pickupTimeRanges($product->id, $sender, $receiver, today(), weight: 1.5);

$request = new OrderRequest(
    productId: $product->id,
    length: 30, width: 20, height: 10, weight: 1.5,
    sender: $sender,
    receiver: $receiver,
    content: 'Books',
    collectionType: CollectionType::Pickup,
    deliveryType: CollectionType::Point,
    pickup: Pickup::fromWindow($windows[0]),
    addons: [
        AddonSelection::insurance($insurance->id, 149.99),
        AddonSelection::cashOnDelivery($cod->id, 149.99, 'PL61109010140000071219812874', 'ACME Sp. z o.o.', 'Prosta 1, 00-001 Warszawa'),
    ],
    referenceNumber: 'ORDER-1001',
);

GlobKurier::validateOrder($request);                   // ApiException with fieldErrors() when invalid
$price = GlobKurier::orderPrice($request, cashOnDeliveryValue: 149.99, insuranceValue: 149.99);

$order = GlobKurier::createOrder($request);            // never repeated automatically
$order->number;    // "GK260520647801", used for tracking
$order->hash;      // used for labels, protocols, cancellation and GET /order
$order->price?->totalGross;

$pdf = GlobKurier::labels($order->hash);               // LabelFormat::ZebraPrinter for label printers
$protocol = GlobKurier::protocol([$order->hash]);

$order = [
    'shipment' => ['length' => 10, 'width' => 10, 'height' => 10, 'weight' => 1, 'quantity' => 1, 'integrationName' => 'inPost-Paczkomaty'],
    'senderAddress' => $sender,
    'receiverAddress' => $receiver,
    'content' => 'Books',
    'collectionType' => 'PICKUP',
    'deliveryType' => 'POINT',
    'addons' => ['INSURANCE' => ['value' => 100]],
];

$quote = GlobKurier::bestPriceQuote($order);           // Price
$placed = GlobKurier::bestPriceOrder($order);          // createFully: the carrier gets the order at once
$placed->trackingNumber;
$placed->label;                                        // PDF when the carrier returned it

$details = GlobKurier::order($hash);                   // or orderByNumber('GK...') when logged in
$details->status;                                      // OrderStatus::InTransit
$details->documentLink('WAYBILL');
$details->cashOnDelivery();                            // COD add-on with its payout status

GlobKurier::orderPickup($hash);                        // order the courier again
GlobKurier::cancelOrder($hash);                        // poll order() until the status is CANCELED

$tracking = GlobKurier::tracking('GK260520647801');
$tracking->latest?->type;                              // e.g. "IN_TRANSIT"
$tracking->waybillNumber();
$many = GlobKurier::trackingMany(['GK1', 'GK2']);       // one request

Schedule::command('globkurier:track', $openOrderNumbers)->hourly();

Event::listen(function (\Beziworld\GlobKurier\Events\ShipmentStatusChanged $event) {
    $event->tracking->number;
    $event->tracking->latest?->type;
    $event->previousStatus;
});

use Beziworld\GlobKurier\Enums\PointAddressType;

GlobKurier::points($product->id, ['city' => 'Kraków'], PointAddressType::Receiver);
GlobKurier::points('inPost-Paczkomaty', ['postCode' => '30-001', 'serviceCode' => 'APM']);
GlobKurier::point($product->id, 'KRA01M');

GlobKurier::countries();          // cached for a day
GlobKurier::countryId('DE');      // 23
GlobKurier::cities('PL', '30-001');
GlobKurier::carriers(deliveryTypes: [CollectionType::Point], addonCategories: ['CASH_ON_DELIVERY']);
GlobKurier::contents();
GlobKurier::request('GET', 'user/stats');   // any other endpoint

// config/globkurier.php: 'connections' => ['default' => [...], 'second' => ['email' => ..., 'password' => ...]]
GlobKurier::connection('second')->products($query);

GlobKurier::using(['email' => $tenant->gk_email, 'password' => $tenant->gk_password])->createOrder($request);