Offer 4x6 label downloads alongside A4
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 1m48s
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 1m48s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
51c6748894
commit
dff81caaea
@@ -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',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user