ekyna/gls-uni-box
PHP library for managing shipments via the GLS Uni Box API. Provides tools to integrate GLS shipping workflows into your PHP applications, including creating and tracking shipments through the Uni Box service.
Installation Add the package via Composer:
composer require ekyna/gls-uni-box
Register the service provider in config/app.php:
'providers' => [
// ...
Ekyna\GlsUniBox\GlsUniBoxServiceProvider::class,
],
Configuration Publish the config file:
php artisan vendor:publish --provider="Ekyna\GlsUniBox\GlsUniBoxServiceProvider"
Update .env with your GLS credentials:
GLS_UNIBOX_USERNAME=your_username
GLS_UNIBOX_PASSWORD=your_password
GLS_UNIBOX_ACCOUNT_NUMBER=your_account_number
First Use Case: Creating a Shipment
Inject the Ekyna\GlsUniBox\GlsUniBox facade or service into a controller:
use Ekyna\GlsUniBox\Facades\GlsUniBox;
public function createShipment(Request $request) {
$shipment = GlsUniBox::createShipment([
'sender' => [
'name' => 'Sender Name',
'address' => 'Sender Street',
'postcode' => '1234AB',
'city' => 'Sender City',
'country' => 'NL',
],
'recipient' => [
'name' => 'Recipient Name',
'address' => 'Recipient Street',
'postcode' => '5678CD',
'city' => 'Recipient City',
'country' => 'NL',
],
'parcels' => [
[
'weight' => 1.5,
'description' => 'Sample package',
],
],
'service' => 'GLS_EXPRESS', // or 'GLS_STANDARD'
]);
return response()->json($shipment);
}
Shipment Management
GlsUniBox::createShipment() with sender/recipient/parcel details.$tracking = GlsUniBox::getTrackingInfo('TRACKING_NUMBER');
$label = GlsUniBox::generateLabel('SHIPMENT_ID');
Storage::put('public/gls_labels/' . $label['filename'], $label['content']);
Batch Processing Loop through orders and generate shipments in bulk:
foreach ($orders as $order) {
GlsUniBox::createShipment($this->formatShipmentData($order));
}
Event-Driven Integration Listen for shipment events (e.g., after creation) using Laravel events:
// In a service class
event(new ShipmentCreated($shipmentData));
API Wrapper Abstraction Extend the base client for custom logic:
class CustomGlsClient extends \Ekyna\GlsUniBox\GlsUniBox {
public function customShipmentFlow($data) {
$shipment = $this->createShipment($data);
// Add custom post-processing
return $this->updateOrderStatus($shipment['id']);
}
}
ShipmentJob::dispatch($shipmentData)->delay(now()->addMinutes(5));
retry helper or a package like spatie/laravel-retryable.\Log::debug('GLS API Response', ['data' => $response]);
$tracking = Cache::remember("gls_tracking_{$trackingNumber}", now()->addHours(1), function () use ($trackingNumber) {
return GlsUniBox::getTrackingInfo($trackingNumber);
});
API Rate Limits
GuzzleHttp\Client with retry middleware or a dedicated queue worker.Data Validation
$validated = $request->validate([
'weight' => 'required|numeric|min:0.1|max:30',
'postcode' => 'required|string|max:10',
]);
Label Generation Issues
Environment-Specific Config
.env can lead to leaks. Use Laravel’s env() or a secrets manager..env to the server and use Laravel Forge/Vault for production.Deprecation Risks
if (config('gls.use_new_api')) {
$this->useNewApiClient();
}
GLS_UNIBOX_DEBUG=true in .env to log raw API requests/responses.$response = new Response('<xml>...</xml>');
Http::fake($response);
$shipment = GlsUniBox::createShipment($data);
400 for invalid postcodes).Custom API Endpoints Extend the client to support non-standard endpoints:
class ExtendedGlsClient extends GlsUniBox {
public function getCustomReport($params) {
return $this->request('GET', '/custom/report', $params);
}
}
Webhook Listeners Implement a webhook endpoint to handle GLS status updates:
Route::post('/gls/webhook', function (Request $request) {
$payload = $request->xml();
// Parse and process GLS webhook data
});
Database Sync Sync GLS shipments to a local database table:
$shipment = GlsUniBox::createShipment($data);
\App\Models\Shipment::create([
'gls_id' => $shipment['id'],
'tracking_number' => $shipment['tracking_number'],
// ...
]);
Multi-Account Support Dynamically switch accounts based on context:
GlsUniBox::setAccount('account_2');
$shipment = GlsUniBox::createShipment($data);
How can I help you explore Laravel packages today?