diff --git a/app/Http/Controllers/ShippingController.php b/app/Http/Controllers/ShippingController.php index 58d7acc..fbfd483 100644 --- a/app/Http/Controllers/ShippingController.php +++ b/app/Http/Controllers/ShippingController.php @@ -227,11 +227,12 @@ class ShippingController extends Controller $order = collect($orders)->first(fn ($order) => (string) ($order['OrderLineId'] ?? '') === $orderLineId); $hash = $order ? $parcel2Go->labelHash($order) : null; abort_unless($hash, 404); - $pdf = $parcel2Go->labelPdf($orderLineId, $hash); + $size = $request->query('size') === '4x6' ? '4x6' : 'a4'; + $pdf = $parcel2Go->labelPdf($orderLineId, $hash, $size === '4x6' ? 'Label4x6' : 'A4'); return response($pdf, 200, [ 'Content-Type' => 'application/pdf', - 'Content-Disposition' => 'attachment; filename="parcel2go-'.$orderLineId.'.pdf"', + 'Content-Disposition' => 'attachment; filename="parcel2go-'.$orderLineId.'-'.$size.'.pdf"', 'Cache-Control' => 'private, no-store', ]); } diff --git a/app/Services/Parcel2Go.php b/app/Services/Parcel2Go.php index 0cead32..195ff29 100644 --- a/app/Services/Parcel2Go.php +++ b/app/Services/Parcel2Go.php @@ -182,13 +182,14 @@ class Parcel2Go return filled($query['hash'] ?? null) ? (string) $query['hash'] : null; } - public function labelPdf(string $reference, string $hash): string + /** @param 'A4'|'Label4x6' $media */ + public function labelPdf(string $reference, string $hash, string $media = 'A4'): string { $token = $this->profileConnected() ? $this->profileAccessToken() : $this->accessToken(); $data = Http::withToken($token)->acceptJson()->connectTimeout(3)->timeout(20) ->get($this->url('labels/'.$reference), [ 'referenceType' => 'OrderLineId', 'detailLevel' => 'Labels', - 'labelMedia' => 'A4', 'labelFormat' => 'PDF', 'hash' => $hash, + 'labelMedia' => $media, 'labelFormat' => 'PDF', 'hash' => $hash, ])->throw()->json(); $encoded = $data['Base64EncodedLabels'][0] ?? ''; $pdf = is_string($encoded) ? base64_decode($encoded, true) : false; diff --git a/resources/views/shipping.blade.php b/resources/views/shipping.blade.php index 6a63bfe..bb3bb84 100644 --- a/resources/views/shipping.blade.php +++ b/resources/views/shipping.blade.php @@ -35,7 +35,7 @@
Current Parcel2Go progress and labels from your account history.
| Order | Courier | Service | Progress | Estimated delivery | Recipient | Destination | Label |
|---|---|---|---|---|---|---|---|
| {{ $order['OrderLineId'] ?? '—' }} | {{ $order['Courier'] ?? '—' }} | {{ $order['Service'] ?? '—' }} | $order['Tracking']['Delivered'] ?? false, 'bg-sky-500/10 text-sky-300' => ! ($order['Tracking']['Delivered'] ?? false)])>{{ ($order['Tracking']['Delivered'] ?? false) ? 'Delivered' : 'In transit' }} | {{ app(\App\Services\Display::class)->dateTime($order['EstimatedDeliveryDate'] ?? null) }} | {{ $order['DeliveryAddress']['ContactName'] ?? '—' }} | {{ app(\App\Services\Display::class)->flag($order['DeliveryAddress'] ?? []) }} | @if(app(\App\Services\Parcel2Go::class)->labelHash($order) && ! empty($order['OrderLineId']))Download PDF@elseUnavailable@endif |
| {{ $order['OrderLineId'] ?? '—' }} | {{ $order['Courier'] ?? '—' }} | {{ $order['Service'] ?? '—' }} | $order['Tracking']['Delivered'] ?? false, 'bg-sky-500/10 text-sky-300' => ! ($order['Tracking']['Delivered'] ?? false)])>{{ ($order['Tracking']['Delivered'] ?? false) ? 'Delivered' : 'In transit' }} | {{ app(\App\Services\Display::class)->dateTime($order['EstimatedDeliveryDate'] ?? null) }} | {{ $order['DeliveryAddress']['ContactName'] ?? '—' }} | {{ app(\App\Services\Display::class)->flag($order['DeliveryAddress'] ?? []) }} | @if(app(\App\Services\Parcel2Go::class)->labelHash($order) && ! empty($order['OrderLineId']))4×6A4@elseUnavailable@endif |
| {{ $historyAvailable ? 'No shipments in Parcel2Go account history.' : 'Shipment history is unavailable. Check the Client Credentials in Settings.' }} | |||||||