From 53cac3b85b00f93c7e227ba8ebecf10962cbbf8d Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 29 Apr 2025 18:58:02 -0600 Subject: [PATCH] Fix UPS tracking --- lib/Tracking_UPS.lib.php | 17 ++++++++++++----- lib/UPSAPIs.lib.php | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Tracking_UPS.lib.php b/lib/Tracking_UPS.lib.php index 4ea289f..2b34d71 100644 --- a/lib/Tracking_UPS.lib.php +++ b/lib/Tracking_UPS.lib.php @@ -47,7 +47,7 @@ class Tracking_UPS { } $info->setCarrier("ups"); - $info->setService(new Service($trackinfo["service"]["code"], $trackinfo["service"]["description"])); + $info->setService(new Service($trackinfo["package"]["service"]["code"], $trackinfo["package"]["service"]["description"])); $info->setCarrierAttributionText(CarrierAssets::getAttribution(Carriers::getCarrierCode($info->getCarrier()))); $info->setCarrierLogo(CarrierAssets::getLogo(Carriers::getCarrierCode($info->getCarrier()))); @@ -60,7 +60,7 @@ class Tracking_UPS { } $current_status = new TrackingEntry( TrackingStatus::UPSEventTypeToStatus($current["status"]["type"]), - $current["status"]["description"] ?? "Unknown", + trim($current["status"]["description"] ?? "Unknown"), DateTime::createFromFormat('Ymd His', "$current[date] $current[time]")->format("c") ); @@ -74,9 +74,9 @@ class Tracking_UPS { $info->setCurrentStatus($current_status); } - foreach ($trackinfo["packageAddress"] as $address) { + foreach ($trackinfo["package"]["packageAddress"] as $address) { switch ($address["type"]) { - case "02": // ShipTo Address + case "DESTINATION": // ShipTo Address $to = new Location(); $to->city = $address["address"]["city"] ?? ""; $to->state = $address["address"]["stateProvince"] ?? ""; @@ -84,6 +84,13 @@ class Tracking_UPS { $to->country = $address["address"]["countryCode"] ?? ""; $info->setTo($to); break; + case "ORIGIN": + $from = new Location(); + $from->city = $address["address"]["city"] ?? ""; + $from->state = $address["address"]["stateProvince"] ?? ""; + $from->zip = $address["address"]["postalCode"] ?? ""; + $from->country = $address["address"]["countryCode"] ?? ""; + $info->setFrom($from); } } // @@ -115,7 +122,7 @@ class Tracking_UPS { } $info->appendHistoryEntry(new TrackingEntry( TrackingStatus::UPSEventTypeToStatus($history["status"]["type"]), - $history["status"]["description"] ?? "Unknown", + trim($history["status"]["description"] ?? "Unknown"), $datetimestring, $location )); diff --git a/lib/UPSAPIs.lib.php b/lib/UPSAPIs.lib.php index e4a1526..bc1e3f4 100644 --- a/lib/UPSAPIs.lib.php +++ b/lib/UPSAPIs.lib.php @@ -30,7 +30,7 @@ class UPSAPIs { curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials"); $response = curl_exec($ch); curl_close($ch); - + $data = json_decode($response, true); $memcache->set("logistics.tracking.ups_bearer_token", $data["access_token"], ($data["expires_in"] * 1) - 120); return $data["access_token"]; @@ -46,7 +46,7 @@ class UPSAPIs { $ch = curl_init(); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 45); - curl_setopt($ch, CURLOPT_URL, static::BASEURL . "/$endpoint"); + curl_setopt($ch, CURLOPT_URL, static::BASEURL . "/api/$endpoint"); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_ENCODING, "");