Add full support for USPS DataMatrix
This commit is contained in:
parent
7ae708c55b
commit
ce832f1120
@ -3,6 +3,10 @@
|
||||
class Carriers {
|
||||
|
||||
const CARRIER_REGEXES = [
|
||||
[
|
||||
"carrier" => "usps_gsbarcode", // USPS barcodes with GS character
|
||||
"pattern" => "/^\\x1D?420[0-9]{5,11}\\x1D?[0-9]{10,}\\x1D?$/"
|
||||
],
|
||||
[
|
||||
"carrier" => "ups_mi_datamatrix",
|
||||
"pattern" => "/^([^\\t]*\\t[^\\t]*){13}$/"
|
||||
@ -47,14 +51,6 @@ class Carriers {
|
||||
"carrier" => "usps",
|
||||
"pattern" => "/^420[0-9]{5}[0-9]+$/"
|
||||
],
|
||||
[
|
||||
"carrier" => "usps",
|
||||
"pattern" => "/^\\x1D?420[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}$/"
|
||||
|
@ -19,6 +19,8 @@ class Tracking {
|
||||
}
|
||||
|
||||
switch ($carriercode) {
|
||||
case "usps_gsbarcode":
|
||||
return Tracking_USPS_gsbarcode::track($code);
|
||||
case "ups_mi_datamatrix":
|
||||
return Tracking_UPS_MailInnovations_DataMatrix::track($code);
|
||||
case "fedex_pdf417":
|
||||
|
@ -30,7 +30,7 @@ class TrackingBarcode {
|
||||
public function getCarrier(): string {
|
||||
$carrier = "";
|
||||
foreach (Carriers::CARRIER_REGEXES as $p) {
|
||||
if (preg_match($p["pattern"]."i", $this->code)) {
|
||||
if (preg_match($p["pattern"], strtoupper($this->code))) {
|
||||
$carrier = $p["carrier"];
|
||||
break;
|
||||
}
|
||||
|
23
lib/Tracking_USPS_gsbarcode.lib.php
Normal file
23
lib/Tracking_USPS_gsbarcode.lib.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class Tracking_USPS_gsbarcode {
|
||||
|
||||
/**
|
||||
*
|
||||
* @global type $SETTINGS
|
||||
* @param string $code
|
||||
* @return \TrackingInfo
|
||||
* @throws TrackingException
|
||||
*/
|
||||
public static function track(string $code): TrackingInfo {
|
||||
if (strpos($code, "\x1D") === 0) {
|
||||
$code = substr($code, 1);
|
||||
}
|
||||
$codeparts = explode("\x1D", $code);
|
||||
|
||||
$realcode = $codeparts[1];
|
||||
|
||||
return Tracking::track($realcode, "usps");
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user