Read Parcel2Go label hash from order links when Hash is empty
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 26s
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:
co-authored by
Claude Sonnet 5.5
parent
504a867351
commit
51c6748894
@@ -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',
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user