feat(27-shipment-tracking-backend): infrastruktura sledzenia przesylek — statusy, tracking services, cron handler

Dwupoziomowy system statusow dostawy (normalized + raw z API), implementacje
trackingu dla InPost ShipX, Apaczka i Allegro WZA, cron handler odpytujacy
aktywne przesylki co 15 minut.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 20:33:44 +01:00
parent c59d431083
commit 228c0e96cf
17 changed files with 1365 additions and 27 deletions

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace App\Modules\Shipments;
use App\Modules\Settings\AllegroApiClient;
use App\Modules\Settings\AllegroTokenManager;
use Throwable;
final class AllegroTrackingService implements ShipmentTrackingInterface
{
public function __construct(
private readonly AllegroApiClient $apiClient,
private readonly AllegroTokenManager $tokenManager
) {
}
public function supports(string $provider): bool
{
return $provider === 'allegro_wza';
}
public function getDeliveryStatus(array $package): ?array
{
$shipmentId = trim((string) ($package['shipment_id'] ?? ''));
if ($shipmentId === '') {
return null;
}
return $this->fetchStatus($shipmentId);
}
private function fetchStatus(string $shipmentId): ?array
{
try {
[$accessToken, $env] = $this->tokenManager->resolveToken();
$details = $this->apiClient->getShipmentDetails($env, $accessToken, $shipmentId);
$rawStatus = strtoupper(trim((string) ($details['status'] ?? '')));
if ($rawStatus === '') {
return null;
}
return [
'status' => DeliveryStatus::normalize('allegro_wza', $rawStatus),
'status_raw' => $rawStatus,
'description' => DeliveryStatus::description('allegro_wza', $rawStatus),
];
} catch (Throwable) {
return null;
}
}
}