1
|
|
|
<?php namespace SimpleUPS\RegionValidate; |
2
|
|
|
|
3
|
|
|
use \SimpleUPS\Api\MissingParameterException; |
4
|
|
|
|
5
|
|
|
use \SimpleUPS\Address; |
6
|
|
|
|
7
|
|
|
use \SimpleUPS\UPS; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @internal |
11
|
|
|
*/ |
12
|
|
|
class Request extends \SimpleUPS\Api\Request |
13
|
|
|
{ |
14
|
|
|
private |
15
|
|
|
/* @var Address $address */ |
16
|
|
|
$address; |
17
|
|
|
|
18
|
|
|
public function __construct($debug = null) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($debug); |
21
|
|
|
|
22
|
|
|
$this->responseClass = false; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Determine which API call will be made |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
public function getUrl() |
30
|
|
|
{ |
31
|
|
|
return $this->getDebug() ? 'https://wwwcie.ups.com/ups.app/xml/AV' : 'https://onlinetools.ups.com/ups.app/xml/AV'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Build the validate address request |
36
|
|
|
* @return string |
37
|
|
|
* @throws \SimpleUPS\Api\MissingParameterException |
38
|
|
|
*/ |
39
|
|
|
public function buildXml() |
40
|
|
|
{ |
41
|
|
|
if (serialize($this->getAddress()) == serialize(new Address())) { |
42
|
|
|
throw new MissingParameterException( |
43
|
|
|
'Address requires a Country code, Postal code, and either a City or State\Province code' |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if ($this->getAddress()->getCountryCode() === null) { |
48
|
|
|
throw new MissingParameterException('Address requires a Country code'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if ($this->getAddress()->getPostalCode() === null) { |
52
|
|
|
throw new MissingParameterException('Address requires a Postal code'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$dom = new \DomDocument('1.0'); |
56
|
|
|
$dom->formatOutput = $this->getDebug(); |
57
|
|
|
$dom->appendChild($addressRequest = $dom->createElement('AddressValidationRequest')); |
58
|
|
|
$addressRequestLang = $dom->createAttribute('xml:lang'); |
59
|
|
|
$addressRequestLang->value = parent::getXmlLang(); |
|
|
|
|
60
|
|
|
$addressRequest->appendChild($request = $dom->createElement('Request')); |
61
|
|
|
$request->appendChild($transactionReference = $dom->createElement('TransactionReference')); |
62
|
|
|
$transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext())); |
63
|
|
|
$transactionReference->appendChild($dom->createElement('XpciVersion', $this->getXpciVersion())); |
64
|
|
|
|
65
|
|
|
$request->appendChild($dom->createElement('RequestAction', 'AV')); |
66
|
|
|
$addressRequest->appendChild($address = $dom->createElement('Address')); |
67
|
|
|
|
68
|
|
|
if ($this->getAddress()->getCity() != null) { |
69
|
|
|
$address->appendChild($dom->createElement('City', $this->getAddress()->getCity())); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if ($this->getAddress()->getStateProvinceCode() != null) { |
73
|
|
|
$address->appendChild( |
74
|
|
|
$dom->createElement('StateProvinceCode', $this->getAddress()->getStateProvinceCode()) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if ($this->getAddress()->getPostalCode() != null) { |
79
|
|
|
$address->appendChild($dom->createElement('PostalCode', $this->getAddress()->getPostalCode())); |
80
|
|
|
} |
81
|
|
|
$address->appendChild($dom->createElement('CountryCode', $this->getAddress()->getCountryCode())); |
82
|
|
|
|
83
|
|
|
$xml = parent::buildAuthenticationXml() . $dom->saveXML(); |
|
|
|
|
84
|
|
|
|
85
|
|
|
return $xml; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Send a request to the API and get region rankings for the provided address |
90
|
|
|
* @return Response |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
public function sendRequest() |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
$xml = parent::sendRequest(); |
95
|
|
|
|
96
|
|
|
$responseClass = new \SimpleUPS\RegionValidate\Response($this->getAddress()); |
97
|
|
|
$response = $responseClass->fromXml($xml); |
|
|
|
|
98
|
|
|
|
99
|
|
|
return $response; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param \SimpleUPS\Address $address |
104
|
|
|
*/ |
105
|
|
|
public function setAddress(Address $address) |
106
|
|
|
{ |
107
|
|
|
$this->address = $address; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return Address |
112
|
|
|
*/ |
113
|
|
|
public function getAddress() |
114
|
|
|
{ |
115
|
|
|
return $this->address; |
116
|
|
|
} |
117
|
|
|
} |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.