PHP code example of beziworld / laravel-polkurier

1. Go to this page and download the library: Download beziworld/laravel-polkurier 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-polkurier example snippets


use Beziworld\Polkurier\Data\Address;
use Beziworld\Polkurier\Data\OrderRequest;
use Beziworld\Polkurier\Data\Pack;
use Beziworld\Polkurier\Enums\Service;
use Beziworld\Polkurier\Facades\Polkurier;

$carriers = Polkurier::carriers(details: true);         // list<Carrier>
$dpd = Polkurier::carrier('DPD');
$dpd?->supportsCod();
$dpd?->supportsService('ROD');
$dpd?->additionalFields();                               // carrier specific order fields

$quote = new OrderRequest(
    sender: Address::postcode('63-400'),
    recipient: Address::postcode('60-001'),
    packs: [new Pack(length: 30, width: 20, height: 10, weight: 2.5)],
    services: [Service::SmsNotification],
);

foreach (Polkurier::valuation($quote) as $price) {
    $price->carrier;        // "DPD"
    $price->priceGross;     // "14.76"
    $price->available;      // false with $price->unavailableMessage when the carrier cannot take it
}

$best = Polkurier::cheapest($quote);

use Beziworld\Polkurier\Data\Cod;
use Beziworld\Polkurier\Data\Pickup;
use Beziworld\Polkurier\Enums\CodReturnTime;

$order = Polkurier::createOrder(new OrderRequest(
    sender: new Address('Jan Kowalski', 'Kurierska', '1', '63-400', 'Ostrów Wielkopolski', '500600700', '[email protected]', company: 'ACME'),
    recipient: new Address('Anna Nowak', 'Poznańska', '12', '60-001', 'Poznań', '600700800', '[email protected]', pointId: 'POZ01M'),
    packs: [new Pack(30, 20, 10, 2.5)],
    courier: 'INPOST_PACZKOMAT',
    description: 'Books',
    cod: new Cod('149.99', 'PL61109010140000071219812874', CodReturnTime::OneDay),
    insurance: 200,
    pickup: Pickup::dropOff(),                 // or Pickup::at('2026-11-12', '10:00', '14:00') or Pickup::multi()
    externalApplicationId: 'my-shop',
    externalOrderId: 'A-1001',
));

$order->orderNumber;   // "1234-10"
$order->waybill();     // "13299300045383"
$order->priceGross;    // "12.30"

$pdf = Polkurier::label($order->orderNumber);              // or label(['1234-10', '1234-11']) merged into one PDF
$protocol = Polkurier::protocol(['1234-10', '1234-11']);

Polkurier::cancelOrder('1234-10');                         // orders waiting for payment or confirmed

use Beziworld\Polkurier\Enums\ShipmentType;

$day = Polkurier::pickupHours('DPD', '2026-11-12', '63-400');     // PickupDate: available, windows
$days = Polkurier::pickupDates('DPD', ShipmentType::Box, '63-400'); // next five working days

// Orders created with Pickup::multi() share one courier pickup:
$waiting = Polkurier::orders(['status' => 'PZ']);
$result = Polkurier::multiPickup(['1234-56', '1234-78'], '2026-11-12', '10:00', '15:00');
$result->failed;   // ['1234-78' => 'error message']

$status = Polkurier::status('1234-10');
$status->code;            // OrderStatus::InTransit
$status->trackingUrl;

$details = Polkurier::order('1234-10');
$details->waybills;       // default waybill first
$details->isPaid;
$details->items;          // itemised price
$details->cod?->status;   // CodStatus::Paid
$details->cod?->operations;  // payouts, compensations and fees
$details->cod?->paidOut();   // "70.00"

$page = Polkurier::orders(['date_from' => now()->subWeek(), 'courier' => 'DPD'], page: 1, pageSize: 100);

// routes/console.php
Schedule::command('polkurier:poll-statuses --pages=2')->everyFifteenMinutes();

// a listener
Event::listen(function (\Beziworld\Polkurier\Events\OrderStatusChanged $event) {
    $event->order->number;
    $event->order->statusCode;     // new status
    $event->previousStatus;        // e.g. "OC"
});

use Beziworld\Polkurier\Enums\PointFunction;

$lockers = Polkurier::points('INPOST_PACZKOMAT', search: 'Poznań', functions: [PointFunction::Cod], limit: 50);
$point = Polkurier::point('INPOST_PACZKOMAT', 'POZ01M');

Polkurier::countries('UPS_EX');       // ['DE' => 'Niemcy', ...]
Polkurier::supportedCountries();      // list<Country> with provinces
Polkurier::cities('63-400');          // ['Ostrów Wielkopolski', ...]
Polkurier::mapToken();                // JWT for the Polkurier points map widget (valid 4 hours)

use Beziworld\Polkurier\Data\AddressBookEntry;
use Beziworld\Polkurier\Data\BankAccount;
use Beziworld\Polkurier\Enums\AddressType;

Polkurier::addresses(AddressType::Sender);
Polkurier::saveAddress(new AddressBookEntry(AddressType::Sender, $address, name: 'Warehouse', default: true));

$session = Polkurier::requestTwoFactorCode();          // SMS code to the account phone
Polkurier::saveBankAccount(new BankAccount('PL61109010140000071219812874', 'Main'), $session->token, $codeFromUser);

Polkurier::packTemplates();

// config/polkurier.php: 'connections' => ['default' => [...], 'second' => ['login' => ..., 'token' => ...]]
Polkurier::connection('second')->createOrder($request);

// credentials stored per tenant
Polkurier::using(['login' => $tenant->polkurier_login, 'token' => $tenant->polkurier_token])->valuation($quote);