Fix: Updates to OrderFullfilmentServices and box now clients, order views and checkout services

This commit is contained in:
2026-09-18 00:54:43 +03:00
parent dcdc998eee
commit 12aaa43f10
15 changed files with 450 additions and 18 deletions
@@ -61,6 +61,20 @@ class BoxNowClient
return $response->json() ?? [];
}
/**
* List available APM (locker) destinations — the data behind Box Now's
* own Destination Map widget, which only works against their
* Production environment (not Stage/sandbox). Used to build a plain
* locker picker on the storefront checkout instead, working against
* whichever environment is configured.
*
* @return array<int, array<string, mixed>>
*/
public function destinations(array $query = []): array
{
return $this->locationRequest('/destinations', $query)['data'] ?? [];
}
/**
* Fetch raw bytes (e.g. a PDF label) rather than JSON.
*/
@@ -67,7 +67,7 @@ class BoxNowFulfillmentService implements CarrierFulfillmentInterface, SupportsT
'locationId' => config('boxnow.origin_location_id'),
],
'destination' => [
'contactNumber' => $address->contact_phone,
'contactNumber' => $this->internationalPhone($address->contact_phone),
'contactEmail' => $address->contact_email,
'contactName' => trim("{$address->first_name} {$address->last_name}"),
'locationId' => $destinationLocationId,
@@ -105,6 +105,37 @@ class BoxNowFulfillmentService implements CarrierFulfillmentInterface, SupportsT
return $shipments->first();
}
/**
* Box Now rejects any contactNumber not in full international format
* (error P405 — confirmed in practice: a plain Greek mobile like
* "6955994563" 400s with {"code":"P405"}). Checkout collects phone
* numbers in local format, with no international-format enforcement of
* its own — this store is Greece-only (see CheckoutController::
* STORE_COUNTRY_ISO3), so a bare local number is assumed Greek and
* prefixed accordingly, same convention ACS's own sender config already
* uses (config('boxnow.sender.phone') is documented as "+30..." there
* too). A number already carrying a country code (leading "+" or "00")
* is passed through unchanged.
*/
private function internationalPhone(?string $phone): ?string
{
if ($phone === null) {
return null;
}
$digitsOnly = preg_replace('/[^\d+]/', '', $phone);
if (str_starts_with($digitsOnly, '+')) {
return $digitsOnly;
}
if (str_starts_with($digitsOnly, '00')) {
return '+'.substr($digitsOnly, 2);
}
return '+30'.ltrim($digitsOnly, '0');
}
public function printLabel(Shipment $shipment): string
{
$bytes = $this->client->requestRaw("/parcels/{$shipment->tracking_reference}/label.pdf");