Read Parcel2Go label hash from order links when Hash is empty
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 26s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Hickmeister
2026-10-11 20:36:04 +01:00
co-authored by Claude Sonnet 5.5
parent 504a867351
commit 51c6748894
4 changed files with 42 additions and 3 deletions
+3 -2
View File
@@ -225,8 +225,9 @@ class ShippingController extends Controller
abort_unless(ctype_digit($orderLineId), 404);
$orders = $parcel2Go->fetch('me/orders/detail')['Orders'] ?? [];
$order = collect($orders)->first(fn ($order) => (string) ($order['OrderLineId'] ?? '') === $orderLineId);
abort_unless($order && ! empty($order['Hash']), 404);
$pdf = $parcel2Go->labelPdf($orderLineId, $order['Hash']);
$hash = $order ? $parcel2Go->labelHash($order) : null;
abort_unless($hash, 404);
$pdf = $parcel2Go->labelPdf($orderLineId, $hash);
return response($pdf, 200, [
'Content-Type' => 'application/pdf',
+19
View File
@@ -163,6 +163,25 @@ class Parcel2Go
])->throw()->json() ?? [];
}
/**
* Parcel2Go leaves the order's Hash empty and puts the label hash in its "labels-a4" link instead.
*
* @param array<string, mixed> $order
*/
public function labelHash(array $order): ?string
{
if (filled($order['Hash'] ?? null)) {
return (string) $order['Hash'];
}
$link = collect($order['Links'] ?? [])->first(fn ($link): bool => is_array($link) && str_starts_with((string) ($link['Name'] ?? ''), 'labels-a4'))['Link'] ?? null;
if (! is_string($link)) {
return null;
}
parse_str((string) parse_url($link, PHP_URL_QUERY), $query);
return filled($query['hash'] ?? null) ? (string) $query['hash'] : null;
}
public function labelPdf(string $reference, string $hash): string
{
$token = $this->profileConnected() ? $this->profileAccessToken() : $this->accessToken();