shippingAddress; $destinationLocationId = $overrides['locationId'] ?? null; if (! $destinationLocationId) { throw new BoxNowApiException('No Box Now locker (locationId) was provided for this shipment.'); } $response = $this->client->request('post', '/delivery-requests', [ 'orderNumber' => $order->reference.'-'.$order->id, 'invoiceValue' => number_format($order->total->decimal, 2, '.', ''), 'paymentMode' => 'prepaid', 'amountToBeCollected' => '0.00', 'origin' => [ 'contactNumber' => config('boxnow.sender.phone'), 'contactEmail' => config('boxnow.sender.email'), 'contactName' => config('boxnow.sender.name'), 'locationId' => config('boxnow.origin_location_id'), ], 'destination' => [ 'contactNumber' => $address->contact_phone, 'contactEmail' => $address->contact_email, 'contactName' => trim("{$address->first_name} {$address->last_name}"), 'locationId' => $destinationLocationId, ], 'items' => [ [ 'id' => (string) $order->id, 'name' => 'Order '.$order->reference, 'value' => '0.00', 'compartmentSize' => $overrides['compartmentSize'] ?? 1, 'weight' => $overrides['weight'] ?? 0, ], ], ]); $parcelId = (string) ($response['parcels'][0]['id'] ?? throw new BoxNowApiException( 'Box Now delivery request succeeded but returned no parcel id.', $response, )); return Shipment::create([ 'order_id' => $order->id, 'carrier' => 'box-now', 'tracking_reference' => $parcelId, 'meta' => [ 'delivery_request_id' => $response['id'] ?? null, 'locker_id' => $destinationLocationId, ], ]); } public function printLabel(Shipment $shipment): string { $bytes = $this->client->requestRaw("/parcels/{$shipment->tracking_reference}/label.pdf"); $shipment->update(['label_printed_at' => now()]); return $bytes; } public function cancelShipment(Shipment $shipment): void { $this->client->request('post', "/parcels/{$shipment->tracking_reference}:cancel"); $shipment->update(['cancelled_at' => now()]); } }