diff --git a/lib/Carriers.lib.php b/lib/Carriers.lib.php index c2719d6..c97339a 100644 --- a/lib/Carriers.lib.php +++ b/lib/Carriers.lib.php @@ -152,6 +152,14 @@ class Carriers { ] ]; + const CARRIER_TRACKING_URLS = [ + "usps" => "https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1={{number}}", + "ups" => "https://wwwapps.ups.com/WebTracking/processInputRequest?tracknum={{number}}", + "fedex" => "https://www.fedex.com/fedextrack/?trknbr={{number}}", + "dhl_express" => "https://mydhl.express.dhl/us/en/tracking.html#/results?id={{number}}", + "helena_express" => "https://helena.express/track#{{number}}" + ]; + public static function getCarrierName(string $carrier): string { // scan by internal ID foreach (Carriers::CARRIERS as $id => $info) { @@ -184,4 +192,12 @@ class Carriers { return ""; } + + public static function getCarrierTrackingUrl($carrier, $code) { + if (!empty(Carriers::CARRIER_TRACKING_URLS[$carrier])) { + return str_replace("{{number}}", $code, Carriers::CARRIER_TRACKING_URLS[$carrier]); + } + return false; + } + } diff --git a/lib/TrackingInfo.lib.php b/lib/TrackingInfo.lib.php index a9828ef..b558f8e 100644 --- a/lib/TrackingInfo.lib.php +++ b/lib/TrackingInfo.lib.php @@ -95,6 +95,7 @@ class TrackingInfo { "carrier" => [ "code" => Carriers::getCarrierCode($this->getCarrier()), "name" => Carriers::getCarrierName($this->getCarrier()), + "trackingurl" => Carriers::getCarrierTrackingUrl($this->getCarrier(), $this->getCode()), "attribution" => $this->attributionText, "logo" => $this->carrierImageUrl ],