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->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
));

View File

@ -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, "");