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

@ -29,7 +29,7 @@ class DhlShipmentService
// Get DHL configuration
$settingController = new SettingController;
$dhlConfig = $settingController->getDhlConfig();
\Log::info('dhlConfig', $dhlConfig);
Log::info('[DHL Service] Loaded DHL configuration', self::sanitizeDhlConfigForLog($dhlConfig));
// Check if queue should be used
$useQueue = $dhlConfig['use_queue'] ?? false;
if ($useQueue && $this->requiresSynchronousAddressValidation($options, $dhlConfig)) {
@ -115,7 +115,8 @@ class DhlShipmentService
// Prepare order data using helper
$orderData = DhlDataHelper::prepareOrderData($order, $weight, $options, $dhlConfig);
Log::info('orderData', $orderData);
Log::info('[DHL Service] Order data prepared for DHL API', self::sanitizeOrderDataForLog($orderData));
// Create the shipment directly
$result = $shippingService->createLabel($orderData);
@ -361,4 +362,65 @@ class DhlShipmentService
return null;
}
/**
* Build a redacted view of the DHL configuration for safe logging.
*
* Never include `api_key`, `username`, `password`, `api_secret` or the
* full billing number itself. Only return boolean presence flags and
* non-sensitive metadata.
*
* @param array<string, mixed> $dhlConfig
* @return array<string, mixed>
*/
public static function sanitizeDhlConfigForLog(array $dhlConfig): array
{
return [
'base_url' => $dhlConfig['base_url'] ?? null,
'sandbox' => $dhlConfig['sandbox'] ?? null,
'test_mode' => $dhlConfig['test_mode'] ?? null,
'has_api_key' => ! empty($dhlConfig['api_key']),
'has_username' => ! empty($dhlConfig['username']),
'has_password' => ! empty($dhlConfig['password']),
'has_api_secret' => ! empty($dhlConfig['api_secret']),
'use_queue' => (bool) ($dhlConfig['use_queue'] ?? false),
'default_product' => $dhlConfig['default_product'] ?? null,
'label_format' => $dhlConfig['label_format'] ?? null,
'print_format' => $dhlConfig['print_format'] ?? null,
'print_only_if_codeable' => (bool) ($dhlConfig['print_only_if_codeable'] ?? false),
'international_countries' => $dhlConfig['international_countries'] ?? [],
'account_numbers_configured' => array_keys(array_filter($dhlConfig['account_numbers'] ?? [])),
];
}
/**
* Build a redacted view of the order data prepared for DHL.
*
* Strips personally identifiable information like full names, addresses,
* phone numbers and e-mail addresses. Keeps the routing-relevant fields
* needed to debug a failing label generation.
*
* @param array<string, mixed> $orderData
* @return array<string, mixed>
*/
public static function sanitizeOrderDataForLog(array $orderData): array
{
$consigneeCountry = $orderData['consignee']['country'] ?? null;
$consigneePostal = $orderData['consignee']['postalCode'] ?? null;
return [
'order_id' => $orderData['order_id'] ?? null,
'product_code' => $orderData['product_code'] ?? null,
'weight_kg' => $orderData['weight_kg'] ?? null,
'label_format' => $orderData['label_format'] ?? null,
'print_format' => $orderData['print_format'] ?? null,
'print_only_if_codeable' => (bool) ($orderData['print_only_if_codeable'] ?? false),
'consignee_country' => $consigneeCountry,
'consignee_postal_prefix' => is_string($consigneePostal) && $consigneePostal !== ''
? mb_substr($consigneePostal, 0, 2)
: null,
'consignee_has_post_number' => ! empty($orderData['consignee']['postNumber']),
'has_reference' => ! empty($orderData['reference']),
];
}
}