27-05-2026 DHL Modul v2.1 / Optimierung tracking

This commit is contained in:
Kevin Adametz 2026-05-27 18:51:23 +02:00
parent 036595be94
commit 2bdc9ada3c
33 changed files with 2367 additions and 2086 deletions

View file

@ -14,7 +14,7 @@ use Illuminate\Support\Facades\Log;
/**
* Job to create DHL shipments asynchronously
*
*
* This job handles the creation of DHL shipments in the background,
* preventing API timeouts and improving user experience.
*/
@ -37,11 +37,6 @@ class CreateShipmentJob implements ShouldQueue
*/
public $options;
/**
* @var array
*/
public $dhlConfig;
/**
* The number of times the job may be attempted.
*
@ -59,10 +54,16 @@ class CreateShipmentJob implements ShouldQueue
/**
* Create a new job instance.
*
* @param ShoppingOrder $shoppingOrder
* @param float $weight
* @param array $options
* @param array|null $dhlConfig
* IMPORTANT: We intentionally never serialize the DHL configuration into
* the queue payload because it contains the DHL API key, basic-auth
* password and billing numbers. Those values would otherwise sit
* unencrypted in Redis/the queue table. The config is reloaded inside
* {@see self::handle()} from the canonical settings source instead.
*
* The legacy `$dhlConfig` parameter is still accepted for backwards
* compatibility but is no longer persisted onto the job instance.
*
* @param array $dhlConfig Deprecated: ignored to avoid secrets in queue
*/
public function __construct(ShoppingOrder $shoppingOrder, float $weight = 1.0, array $options = [], array $dhlConfig = [])
{
@ -70,14 +71,6 @@ class CreateShipmentJob implements ShouldQueue
$this->weight = $weight;
$this->options = $options;
// Load DHL config once when creating the job
if (empty($dhlConfig)) {
$settingController = new \App\Http\Controllers\SettingController();
$this->dhlConfig = $settingController->getDhlConfig();
} else {
$this->dhlConfig = $dhlConfig;
}
// Set queue name based on priority
if (isset($options['priority']) && $options['priority'] === 'high') {
$this->onQueue('high-priority');
@ -98,18 +91,20 @@ class CreateShipmentJob implements ShouldQueue
'attempt' => $this->attempts(),
]);
// Use DHL configuration loaded in constructor
// Load DHL configuration here, never from the serialized job payload.
$dhlConfig = (new \App\Http\Controllers\SettingController)->getDhlConfig();
$dhlClient = new \Acme\Dhl\Support\DhlClient(
$this->dhlConfig['base_url'],
$this->dhlConfig['api_key'],
$this->dhlConfig['username'],
$this->dhlConfig['password']
$dhlConfig['base_url'],
$dhlConfig['api_key'],
$dhlConfig['username'],
$dhlConfig['password']
);
$shippingService = new \Acme\Dhl\Services\ShippingService($dhlClient);
// Prepare order data using helper
$orderData = DhlDataHelper::prepareOrderData($this->shoppingOrder, $this->weight, $this->options, $this->dhlConfig);
$orderData = DhlDataHelper::prepareOrderData($this->shoppingOrder, $this->weight, $this->options, $dhlConfig);
// Create the shipment using new package
$result = $shippingService->createLabel($orderData);
@ -121,9 +116,9 @@ class CreateShipmentJob implements ShouldQueue
]);
// Trigger follow-up actions if specified (if tracking number available)
if (isset($this->options['auto_track']) && $this->options['auto_track'] && !empty($result['trackingNumber'])) {
if (isset($this->options['auto_track']) && $this->options['auto_track'] && ! empty($result['trackingNumber'])) {
Log::info('[DHL Queue] Scheduling tracking update', [
'tracking_number' => $result['trackingNumber']
'tracking_number' => $result['trackingNumber'],
]);
// Note: TrackShipmentJob would need to be updated to work with tracking numbers
}
@ -149,8 +144,6 @@ class CreateShipmentJob implements ShouldQueue
/**
* Handle a job failure.
*
* @param Exception $exception
*/
public function failed(Exception $exception): void
{
@ -166,7 +159,6 @@ class CreateShipmentJob implements ShouldQueue
// - Create manual task for staff
}
/**
* Determine the time at which the job should timeout.
*