You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
PHTML
52 lines
1.5 KiB
PHTML
3 years ago
|
<?php
|
||
|
|
||
|
class Tracking_HelenaExpress {
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @global type $SETTINGS
|
||
|
* @param string $code
|
||
|
* @return \TrackingInfo
|
||
|
* @throws TrackingException
|
||
|
*/
|
||
|
public static function track(string $code): TrackingInfo {
|
||
|
global $SETTINGS;
|
||
|
|
||
|
$barcode = new TrackingBarcode($code);
|
||
|
|
||
|
|
||
|
try {
|
||
|
$status = json_decode(file_get_contents("https://helena.express/tracker/api.php?code=" . $barcode->getCode()));
|
||
|
} catch (Exception $ex) {
|
||
|
throw new TrackingException("There was a server problem. This code cannot be tracked right now.");
|
||
|
}
|
||
|
|
||
|
if (empty($status->events) && empty($status->info->carrier)) {
|
||
|
throw new TrackingException("Unknown tracking code (best guess: " . Carriers::getCarrierName($barcode->getCarrier()) . ").");
|
||
|
}
|
||
|
|
||
|
$info = new TrackingInfo();
|
||
|
|
||
|
$info->setCode($barcode->getCode());
|
||
|
$info->setCarrier($status->info->carrier);
|
||
|
|
||
|
if (!empty($status->events)) {
|
||
|
$current_status = new TrackingEntry(
|
||
|
TrackingStatus::stringToStatus($status->events[0]->eventtype),
|
||
|
$status->events[0]->text,
|
||
|
$status->events[0]->timestring
|
||
|
);
|
||
|
|
||
|
$info->setCurrentStatus($current_status);
|
||
|
}
|
||
|
|
||
|
|
||
|
foreach ($status->events as $event) {
|
||
|
$info->appendHistoryEntry(new TrackingEntry(TrackingStatus::stringToStatus($event->eventtype), $event->text, $event->timestring));
|
||
|
}
|
||
|
|
||
|
return $info;
|
||
|
}
|
||
|
|
||
|
}
|