dinas/shipping-sdk-laravel
Laravel SDK for the Dinas Shipping API. Send requests to REST endpoints and receive/verify incoming webhooks. Webhook events are logged and dispatched as Laravel jobs for async updates like shipment status changes and document availability.
Installation:
composer require dinas/shipping-sdk-laravel
Add to .env:
DINAS_SHIPPING_TOKEN=your-api-token
DINAS_SHIPPING_SECRET=your-webhook-secret
Webhook Setup:
Route::dinasShippingWebhooks('dinas-shipping/webhook');
app/Providers/AppServiceProvider.php:
$middleware->validateCsrfTokens(except: ['dinas-shipping/webhook']);
php artisan vendor:publish --tag="shipping-sdk-laravel-migrations"
php artisan migrate
php artisan webhook:dinas-shipping -i
First Use Case: Fetch cars with pending status:
use Dinas\Shipping\Facades\Shipping;
$cars = Shipping::getCars(['status' => \Dinas\ShippingSdk\Model\StockStatus::PENDING]);
Data Sync:
getCars() to retrieve data, then syncCars() to update records.Shipping::holdCars(['ABC123', 'DEF456'], ['date' => '2026-03-15']);
Media Management:
storeCarPhotos() or storeCarDocuments() with URLs/files.onResolve to handle API job completion:
Shipping::storeCarPhotos($photos, onResolve: fn($context) => {
if ($context->isFailed()) Log::error($context->message);
});
Webhook Handling:
Echo.private(`App.Models.User.${userId}`)
.listen('.shipping.job.resolved', (e) => { ... });
Voyage Tracking:
getVoyages() with pagination:
$voyages = Shipping::getVoyages(['per_page' => 25]);
Shipping facade:
public function __construct(private Shipping $shipping) {}
Shipping::cars() for granular control over API endpoints.StoreResult objects for bulk operations:
$result = Shipping::storeCarPhotos($photos);
if (!$result->ok) {
foreach ($result->validationErrors as $field => $messages) {
// Handle errors
}
}
Webhook Verification:
DINAS_SHIPPING_SECRET matches the API’s registered secret.webhook_calls table for failed signatures.Async Job Callbacks:
WebhookJob status tracking to avoid duplicate executions.Rate Limiting:
Shipping::setHttpClient($client->withOptions(['timeout' => 30]));
CSRF Exclusion:
/dinas-shipping/webhook from CSRF validation will block webhooks.config/dinas-shipping-sdk.php:
'debug' => env('APP_DEBUG', false),
php artisan webhook:dinas-shipping to list registered webhooks.$response = Shipping::cars()->getCars(...);
Log::debug($response->getBody());
Custom HTTP Client:
Shipping::setHttpClient($client->withMiddleware([new MyMiddleware()]));
Webhook Events:
WebhookCall model to add custom logic:
class CustomWebhookCall extends \Spatie\WebhookClient\Models\WebhookCall {
protected static function booted() {
static::created(fn($call) => {
// Custom logic
});
}
}
Broadcasting:
AppServiceProvider:
Shipping::setBroadcastingEnabled(false);
Pruning:
delete_after_days in config to control WebhookJob retention:
'webhook_jobs' => [
'delete_after_days' => 90, // Extend to 90 days
],
routes/console.php:
Schedule::command('model:prune --model="Dinas\Shipping\Models\WebhookJob"')->weekly();
How can I help you explore Laravel packages today?