From 3d142dc51ffd1396395f1c1a09ea41a9dfa3be53 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 14 Jan 2023 23:47:56 -0700 Subject: [PATCH] Add carrier barcode regex for USPS DataMatrix --- lib/Carriers.lib.php | 8 ++++++++ lib/TrackingBarcode.lib.php | 2 +- lib/Tracking_UPS_MailInnovations_DataMatrix.lib.php | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Carriers.lib.php b/lib/Carriers.lib.php index da8d326..47ef134 100644 --- a/lib/Carriers.lib.php +++ b/lib/Carriers.lib.php @@ -47,6 +47,14 @@ class Carriers { "carrier" => "usps", "pattern" => "/^420[0-9]{5}[0-9]+$/" ], + [ + "carrier" => "usps", + "pattern" => "/^\\x1D420[0-9]{5,11}\\x1D[0-9]{10,}\\x1D?$/" + ], + [ + "carrier" => "usps", + "pattern" => "/^420[0-9]{5,11}\\x1D[0-9]{10,}\\x1D?$/" + ], [ "carrier" => "fedex", "pattern" => "/^[0-9]{15}$/" diff --git a/lib/TrackingBarcode.lib.php b/lib/TrackingBarcode.lib.php index 09c25b3..044f48b 100644 --- a/lib/TrackingBarcode.lib.php +++ b/lib/TrackingBarcode.lib.php @@ -16,8 +16,8 @@ class TrackingBarcode { */ public function getSanitized(): string { $code = strtoupper($this->code); - $code = trim($code); $code = preg_replace("/[^0-9A-Z]/", "", $code); + $code = trim($code); return $code; } diff --git a/lib/Tracking_UPS_MailInnovations_DataMatrix.lib.php b/lib/Tracking_UPS_MailInnovations_DataMatrix.lib.php index 184ea63..c5e3e60 100644 --- a/lib/Tracking_UPS_MailInnovations_DataMatrix.lib.php +++ b/lib/Tracking_UPS_MailInnovations_DataMatrix.lib.php @@ -34,7 +34,7 @@ class Tracking_UPS_MailInnovations_DataMatrix { } else { $realcode = $codeparts[13]; - $info = Tracking::track($realcode); + $info = Tracking::track($realcode, "usps"); // Set detailed destination address from code data $to = $info->getTo(); @@ -48,7 +48,7 @@ class Tracking_UPS_MailInnovations_DataMatrix { $to->country = (new League\ISO3166\ISO3166)->numeric($codeparts[9])['alpha2']; $info->setTo($to); - $info->setService(new Service("", "UPS Mail Innovations")); + $info->setService(new Service("", "Parcel Select/UPS Mail Innovations")); } return $info;