1
|
|
|
<?php namespace SimpleUPS\AddressValidate; |
2
|
|
|
|
3
|
|
|
use \SimpleUPS\Api\MissingParameterException; |
4
|
|
|
|
5
|
|
|
use \SimpleUPS\UPS; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* A request/response handler for validating a street address |
9
|
|
|
* @internal |
10
|
|
|
* @link https://www.ups.com/upsdeveloperkit/downloadresource?loc=en_US |
11
|
|
|
*/ |
12
|
|
|
class Request extends \SimpleUPS\Api\Request |
13
|
|
|
{ |
14
|
|
|
private |
15
|
|
|
/* @var Address $address */ |
16
|
|
|
$address; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param null $debug |
20
|
|
|
*/ |
21
|
|
|
public function __construct($debug = null) |
22
|
|
|
{ |
23
|
|
|
parent::__construct($debug); |
24
|
|
|
|
25
|
|
|
$this->responseClass = false; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Determine which API call will be made |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
public function getUrl() |
33
|
|
|
{ |
34
|
|
|
return $this->getDebug() ? 'https://wwwcie.ups.com/ups.app/xml/XAV' : 'https://onlinetools.ups.com/ups.app/xml/XAV'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Build the validate address request |
39
|
|
|
* @return string |
40
|
|
|
* @throws \SimpleUPS\Api\MissingParameterException |
41
|
|
|
*/ |
42
|
|
|
public function buildXml() |
43
|
|
|
{ |
44
|
|
|
if (serialize($this->getAddress()) == serialize(new Address())) { |
45
|
|
|
throw new MissingParameterException( |
46
|
|
|
'Address requires a Country code and a City, a State\Province code or a Postal code' |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if ($this->getAddress()->getCountryCode() === null) { |
51
|
|
|
throw new MissingParameterException('Address requires a Country code'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$dom = new \DomDocument('1.0'); |
55
|
|
|
$dom->formatOutput = $this->getDebug(); |
56
|
|
|
$dom->appendChild($addressRequest = $dom->createElement('AddressValidationRequest')); |
57
|
|
|
$addressRequestLang = $dom->createAttribute('xml:lang'); |
58
|
|
|
$addressRequestLang->value = parent::getXmlLang(); |
|
|
|
|
59
|
|
|
$addressRequest->appendChild($request = $dom->createElement('Request')); |
60
|
|
|
$request->appendChild($transactionReference = $dom->createElement('TransactionReference')); |
61
|
|
|
$transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext())); |
62
|
|
|
|
63
|
|
|
$request->appendChild($dom->createElement('RequestAction', 'XAV')); |
64
|
|
|
$request->appendChild($dom->createElement('RequestOption', '3')); |
65
|
|
|
|
66
|
|
|
$addressRequest->appendChild($address = $dom->createElement('AddressKeyFormat')); |
67
|
|
|
|
68
|
|
|
$address->appendChild($dom->createElement('AddressLine', $this->getAddress()->getStreet())); |
69
|
|
|
if ($this->getAddress()->getAddressLine2()) { |
70
|
|
|
$address->appendChild($dom->createElement('AddressLine', $this->getAddress()->getAddressLine2())); |
71
|
|
|
if ($this->getAddress()->getAddressLine3()) { |
72
|
|
|
$address->appendChild($dom->createElement('AddressLine', $this->getAddress()->getAddressLine3())); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
if ($this->getAddress()->getCity() != null) { |
76
|
|
|
$address->appendChild($dom->createElement('PoliticalDivision2', $this->getAddress()->getCity())); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($this->getAddress()->getStateProvinceCode() != null) { |
80
|
|
|
$address->appendChild( |
81
|
|
|
$dom->createElement('PoliticalDivision1', $this->getAddress()->getStateProvinceCode()) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if ($this->getAddress()->getPostalCode() != null) { |
86
|
|
|
$address->appendChild($dom->createElement('PostcodePrimaryLow', $this->getAddress()->getPostalCode())); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$address->appendChild($dom->createElement('CountryCode', $this->getAddress()->getCountryCode())); |
90
|
|
|
$xml = parent::buildAuthenticationXml() . $dom->saveXML(); |
|
|
|
|
91
|
|
|
|
92
|
|
|
return $xml; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return Response|\SimpleUPS\Api\Response|\SimpleXMLElement |
97
|
|
|
*/ |
98
|
|
View Code Duplication |
public function sendRequest() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$xml = parent::sendRequest(); |
101
|
|
|
|
102
|
|
|
$responseClass = new \SimpleUPS\AddressValidate\Response($this->getAddress()); |
103
|
|
|
$response = $responseClass->fromXml($xml); |
|
|
|
|
104
|
|
|
|
105
|
|
|
return $response; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param Address $address |
110
|
|
|
* |
111
|
|
|
* @return Request |
112
|
|
|
*/ |
113
|
|
|
public function setAddress(Address $address) |
114
|
|
|
{ |
115
|
|
|
$this->address = $address; |
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return Address |
121
|
|
|
*/ |
122
|
|
|
public function getAddress() |
123
|
|
|
{ |
124
|
|
|
return $this->address; |
125
|
|
|
} |
126
|
|
|
} |
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.