1. Go to this page and download the library: Download kazistm/vargo 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/ */
// All providers share the same interface — swap freely
foreach ([DeliveryProviders::ELOGISTIA, DeliveryProviders::NOEST] as $provider) {
$driver = delivery_driver($provider, $credentials[$provider->value]);
$shipment = $driver->createShipment($payload);
}
use KaziSTM\Vargo\Services\DeliveryServiceManager;
$manager = delivery();
// Check if a provider is configured
$manager->supports('elogistia'); // bool
$manager->supports(DeliveryProviders::NOEST); // bool
// List all configured provider keys
$providers = $manager->availableProviders(); // ['yalidine', 'elogistia', ...]
// Fluent chaining
$driver = $manager
->provider(DeliveryProviders::ZR_EXPRESS)
->withCredentials(['api_key' => '...', 'tenant_id' => '...'])
->driver();
// One-line shorthand (equivalent)
$driver = $manager->using(DeliveryProviders::ZR_EXPRESS, ['api_key' => '...', 'tenant_id' => '...']);
use KaziSTM\Vargo\Facades\DeliveryManager;
// All DeliveryServiceManager methods available statically
DeliveryManager::supports('elogistia'); // bool
DeliveryManager::availableProviders(); // array
DeliveryManager::using($provider, $creds); // DeliveryDriver
DeliveryManager::provider($provider) // DeliveryServiceManager (chainable)
->withCredentials($creds)
->driver();
// Get capabilities for all or a specific provider
DeliveryManager::getProviderCapabilities(); // ['yalidine' => ['createShipment', ...], ...]
DeliveryManager::getProviderCapabilities('yalidine'); // ['createShipment', 'getTracking', ...]
/**
* Returns the DeliveryServiceManager singleton.
*/
function delivery(): DeliveryServiceManager;
/**
* Instantiates a driver for the given provider with credentials.
*
* @param DeliveryProviders|string $provider Enum case or string value (e.g. 'elogistia')
* @param array $credentials Provider-specific credentials
*/
function delivery_driver(DeliveryProviders|string $provider, array $credentials): AbstractDriver;
use KaziSTM\Vargo\Enums\DeliveryProviders;
// Get a human-readable label
echo DeliveryProviders::ELOGISTIA->getLabel(); // "Elogistia"
// Get the logo URL
echo DeliveryProviders::YALIDINE_EXPRESS->getLogo(); // asset('assets/logo/yalidine.png')
use KaziSTM\Vargo\Enums\DriverCapability;
$driver = delivery_driver(DeliveryProviders::NOEST, $credentials);
// Check a single capability
if (in_array(DriverCapability::VALIDATE_ORDER, $driver->getCapabilities())) {
$driver->validateShipment('TRACKING-123');
}
// Calling an unsupported method throws UnsupportedDriverFeatureException
use KaziSTM\Vargo\Enums\DeliveryMode;
DeliveryMode::HOME; // value: 1 — home delivery
DeliveryMode::STOP_DESK; // value: 2 — desk/stop-desk pickup
$states = $driver->getStates();
foreach ($states as $state) {
$state->id; // wilaya ID
$state->name; // wilaya name
}
// All communes
$communes = $driver->getMunicipalities();
// Filtered by wilaya
$communes = $driver->getMunicipalities(stateId: 16); // Wilaya 16 = Alger
$offices = $driver->getOffices(wilayaId: 31); // Oran offices
foreach ($offices as $office) {
$office->id;
$office->name;
$office->address;
$office->wilayaId;
}
// Download label as HTTP response (contains PDF/ZPL binary)
$response = $driver->downloadShipmentLabel('TRACKING-123');
// With a format hint (provider-specific, e.g. 'pdf', 'zpl')
$response = $driver->downloadShipmentLabel('TRACKING-123', format: 'pdf');
// Stream to browser
return response($response->body(), 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="label.pdf"',
]);
// Validate a single shipment
$result = $driver->validateShipment('TRACKING-123');
// Validate multiple shipments at once
$results = $driver->validateShipments([
'TRACKING-001',
'TRACKING-002',
]);
$result = $driver->requestReturn('TRACKING-123');
// Some providers accept a payload array instead of just a tracking number
$result = $driver->requestReturn([
'tracking_number' => 'TRACKING-123',
'reason' => 'Customer refused delivery',
]);
// Add an agent remark to a shipment
$result = $driver->addRemark('TRACKING-123', 'Customer not reachable, retry tomorrow');
// Get all remarks/updates for a shipment
$updates = $driver->getShipmentUpdates('TRACKING-123');
use KaziSTM\Vargo\DTOs\CreateShipmentData;
new CreateShipmentData(
originWilaya: string, // tring, // string, // tring, // ng = null, // your internal order ID
items: ?array = null, // product items
insured: ?bool = null,
declaredValue: int|float|null = null,
height: int|float|null = null, // cm
width: int|float|null = null, // cm
length: int|float|null = null, // cm
weight: int|float|null = null, // kg
freeShipping: ?bool = null,
stopdesk: ?bool = null, // true = stop desk delivery
stopdeskId: mixed = null, // office ID
exchange: ?bool = null, // true = exchange shipment
exchangeItems: mixed = null,
fragile: ?bool = null,
liquid: ?bool = null,
openable: ?bool = null, // can be opened on delivery
notes: ?string = null,
);
use KaziSTM\Vargo\DTOs\TrackShipmentData;
new TrackShipmentData(trackingNumber: 'ELG-001234');
// All tracking methods accept either the DTO or a plain string:
$driver->getTracking('ELG-001234');
$driver->getTracking(new TrackShipmentData('ELG-001234'));
$normalizerClass = $driver->getPackageStatusNormalizer();
// e.g. KaziSTM\Vargo\Services\Elogistia\Normalizers\ElogistiaPackageStatusNormalizer
// Get all raw statuses the provider uses
$statuses = $driver->getPackageStatuses();
// e.g. array of ElogistiaPackagesStatus enum cases
use KaziSTM\Vargo\Enums\DriverCapability;
$capabilities = $driver->getCapabilities();
// Using in_array
if (in_array(DriverCapability::REQUEST_RETURN, $capabilities)) {
$driver->requestReturn('TRACKING-123');
}
// Check before webhook operations
if (in_array(DriverCapability::CREATE_WEBHOOK_ENDPOINT, $capabilities)) {
$driver->createWebhookEndpoint([...]);
}
$driver = delivery_driver(DeliveryProviders::ELOGISTIA, [
'api_key' => 'possible-invalid-key',
]);
if ($driver->validateConnection()) {
// credentials are valid, proceed
} else {
// show configuration error to user
}
use KaziSTM\Vargo\Exceptions\ProviderRequestException;
use KaziSTM\Vargo\Exceptions\UnsupportedDriverFeatureException;
try {
$result = $driver->createShipment($payload);
} catch (ProviderRequestException $e) {
// The provider returned an error response
Log::error('Delivery provider error', ['message' => $e->getMessage()]);
} catch (UnsupportedDriverFeatureException $e) {
// Method not available for this driver
abort(422, $e->getMessage());
}