1
|
|
|
<?php namespace SimpleUPS\Track; |
2
|
|
|
|
3
|
|
|
use \SimpleUPS\UPS; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @internal |
7
|
|
|
*/ |
8
|
|
|
abstract class Request extends \SimpleUPS\Api\Request |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
const |
12
|
|
|
TYPE_SMALL_PACKAGE = '01', |
13
|
|
|
TYPE_FREIGHT = '02', |
14
|
|
|
TYPE_MAIL_INNOVATIONS = '03', |
15
|
|
|
REQUEST_INVALID_TRACKING_NUMBER = 151018, |
16
|
|
|
REQUEST_NO_TRACKING_INFORMATION = 151044; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Determine which API call will be made |
20
|
|
|
* @return string |
21
|
|
|
*/ |
22
|
|
|
public function getUrl() |
23
|
|
|
{ |
24
|
|
|
return $this->getDebug( |
25
|
|
|
) ? 'https://wwwcie.ups.com/ups.app/xml/Track' : 'https://onlinetools.ups.com/ups.app/xml/Track'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function handleResponseErrors(\SimpleXMLElement $xml) |
29
|
|
|
{ |
30
|
|
|
if ($xml->Response->ResponseStatusCode == Request::REQUEST_FAIL) { |
31
|
|
|
if ((int)$xml->Response->Error->ErrorCode == Request::REQUEST_INVALID_TRACKING_NUMBER) { |
32
|
|
|
throw new \SimpleUPS\Track\TrackingNumberNotFoundException( |
33
|
|
|
$xml->Response->Error->ErrorDescription, |
34
|
|
|
(int)$xml->Response->Error->ErrorCode, |
35
|
|
|
(int)$xml->Response->Error->ErrorSeverity |
36
|
|
|
); |
37
|
|
|
} else { |
38
|
|
|
if ((int)$xml->Response->Error->ErrorCode == Request::REQUEST_NO_TRACKING_INFORMATION) { |
39
|
|
|
throw new \SimpleUPS\Api\NoTrackingInformationException( |
40
|
|
|
$xml->Response->Error->ErrorDescription, |
41
|
|
|
(int)$xml->Response->Error->ErrorCode, |
42
|
|
|
(int)$xml->Response->Error->ErrorSeverity |
43
|
|
|
); |
44
|
|
|
} else { |
45
|
|
|
throw new \SimpleUPS\Api\ResponseErrorException( |
46
|
|
|
$xml->Response->Error->ErrorDescription, |
47
|
|
|
(int)$xml->Response->Error->ErrorCode, |
48
|
|
|
(int)$xml->Response->Error->ErrorSeverity |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} else { |
53
|
|
|
if (isset($xml->Shipment->ShipmentType->Code) && (string)$xml->Shipment->ShipmentType->Code != Request::TYPE_SMALL_PACKAGE) { |
54
|
|
|
throw new \SimpleUPS\Api\ResponseErrorException( |
55
|
|
|
'In order to track freight or mail innovations you must upgrade your ' . UPS::$libraryName . ' license', |
56
|
|
|
(int)$xml->Response->Error->ErrorCode, |
57
|
|
|
(int)$xml->Response->Error->ErrorSeverity |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |