Fix UPS tracking

This commit is contained in:
Skylar Ittner 2025-04-29 18:58:02 -06:00
parent 27ca18dd86
commit 53cac3b85b
2 changed files with 14 additions and 7 deletions

View File

@ -47,7 +47,7 @@ class Tracking_UPS {
} }
$info->setCarrier("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->setCarrierAttributionText(CarrierAssets::getAttribution(Carriers::getCarrierCode($info->getCarrier())));
$info->setCarrierLogo(CarrierAssets::getLogo(Carriers::getCarrierCode($info->getCarrier()))); $info->setCarrierLogo(CarrierAssets::getLogo(Carriers::getCarrierCode($info->getCarrier())));
@ -60,7 +60,7 @@ class Tracking_UPS {
} }
$current_status = new TrackingEntry( $current_status = new TrackingEntry(
TrackingStatus::UPSEventTypeToStatus($current["status"]["type"]), TrackingStatus::UPSEventTypeToStatus($current["status"]["type"]),
$current["status"]["description"] ?? "Unknown", trim($current["status"]["description"] ?? "Unknown"),
DateTime::createFromFormat('Ymd His', "$current[date] $current[time]")->format("c") DateTime::createFromFormat('Ymd His', "$current[date] $current[time]")->format("c")
); );
@ -74,9 +74,9 @@ class Tracking_UPS {
$info->setCurrentStatus($current_status); $info->setCurrentStatus($current_status);
} }
foreach ($trackinfo["packageAddress"] as $address) { foreach ($trackinfo["package"]["packageAddress"] as $address) {
switch ($address["type"]) { switch ($address["type"]) {
case "02": // ShipTo Address case "DESTINATION": // ShipTo Address
$to = new Location(); $to = new Location();
$to->city = $address["address"]["city"] ?? ""; $to->city = $address["address"]["city"] ?? "";
$to->state = $address["address"]["stateProvince"] ?? ""; $to->state = $address["address"]["stateProvince"] ?? "";
@ -84,6 +84,13 @@ class Tracking_UPS {
$to->country = $address["address"]["countryCode"] ?? ""; $to->country = $address["address"]["countryCode"] ?? "";
$info->setTo($to); $info->setTo($to);
break; 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( $info->appendHistoryEntry(new TrackingEntry(
TrackingStatus::UPSEventTypeToStatus($history["status"]["type"]), TrackingStatus::UPSEventTypeToStatus($history["status"]["type"]),
$history["status"]["description"] ?? "Unknown", trim($history["status"]["description"] ?? "Unknown"),
$datetimestring, $datetimestring,
$location $location
)); ));

View File

@ -30,7 +30,7 @@ class UPSAPIs {
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials"); curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$response = curl_exec($ch); $response = curl_exec($ch);
curl_close($ch); curl_close($ch);
$data = json_decode($response, true); $data = json_decode($response, true);
$memcache->set("logistics.tracking.ups_bearer_token", $data["access_token"], ($data["expires_in"] * 1) - 120); $memcache->set("logistics.tracking.ups_bearer_token", $data["access_token"], ($data["expires_in"] * 1) - 120);
return $data["access_token"]; return $data["access_token"];
@ -46,7 +46,7 @@ class UPSAPIs {
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 45); 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_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, ""); curl_setopt($ch, CURLOPT_ENCODING, "");