1 <?php
2
3 namespace Mypos\IPC;
4
5 /**
6 * Customer details class.
7 * Collect and validate client details
8 */
9 class Customer
10 {
11 private $email;
12 private $phone;
13 private $firstName;
14 private $lastName;
15 private $country;
16 private $city;
17 private $zip;
18 private $address;
19
20 /**
21 * Customer Phone number
22 *
23 * @return string
24 */
25 public function getPhone()
26 {
27 return $this->phone;
28 }
29
30 /**
31 * Customer Phone number
32 *
33 * @param string $phone
34 *
35 * @return Customer
36 */
37 public function setPhone($phone)
38 {
39 $this->phone = $phone;
40
41 return $this;
42 }
43
44 /**
45 * Customer country code ISO 3166-1
46 *
47 * @return string
48 */
49 public function getCountry()
50 {
51 return $this->country;
52 }
53
54 /**
55 * Customer country code ISO 3166-1
56 *
57 * @param string $country
58 *
59 * @return Customer
60 */
61 public function setCountry($country)
62 {
63 $this->country = $country;
64
65 return $this;
66 }
67
68 /**
69 * Customer city
70 *
71 * @return string
72 */
73 public function getCity()
74 {
75 return $this->city;
76 }
77
78 /**
79 * Customer city
80 *
81 * @param string $city
82 *
83 * @return Customer
84 */
85 public function setCity($city)
86 {
87 $this->city = $city;
88
89 return $this;
90 }
91
92 /**
93 * Customer ZIP code
94 *
95 * @return string
96 */
97 public function getZip()
98 {
99 return $this->zip;
100 }
101
102 /**
103 * Customer ZIP code
104 *
105 * @param string $zip
106 *
107 * @return Customer
108 */
109 public function setZip($zip)
110 {
111 $this->zip = $zip;
112
113 return $this;
114 }
115
116 /**
117 * Customer address
118 *
119 * @return string
120 */
121 public function getAddress()
122 {
123 return $this->address;
124 }
125
126 /**
127 * Customer address
128 *
129 * @param string $address
130 *
131 * @return Customer
132 */
133 public function setAddress($address)
134 {
135 $this->address = $address;
136
137 return $this;
138 }
139
140 /**
141 * Validate all set customer details
142 *
143 * @param string $paymentParametersRequired
144 *
145 * @return bool
146 * @throws IPC_Exception
147 */
148 public function validate($paymentParametersRequired)
149 {
150 if ($paymentParametersRequired == Purchase::PURCHASE_TYPE_FULL) {
151
152 if ($this->getFirstName() == null) {
153 throw new IPC_Exception('Invalid First name');
154 }
155
156 if ($this->getLastName() == null) {
157 throw new IPC_Exception('Invalid Last name');
158 }
159
160 if ($this->getEmail() == null || !Helper::isValidEmail($this->getEmail())) {
161 throw new IPC_Exception('Invalid Email');
162 }
163 }
164
165 return true;
166 }
167
168 /**
169 * Customer first name
170 *
171 * @return string
172 */
173 public function getFirstName()
174 {
175 return $this->firstName;
176 }
177
178 /**
179 * Customer first name
180 *
181 * @param string $firstName
182 *
183 * @return Customer
184 */
185 public function setFirstName($firstName)
186 {
187 $this->firstName = $firstName;
188
189 return $this;
190 }
191
192 /**
193 * Customer last name
194 *
195 * @return string
196 */
197 public function getLastName()
198 {
199 return $this->lastName;
200 }
201
202 /**
203 * Customer last name
204 *
205 * @param string $lastName
206 *
207 * @return Customer
208 */
209 public function setLastName($lastName)
210 {
211 $this->lastName = $lastName;
212
213 return $this;
214 }
215
216 /**
217 * Customer Email address
218 *
219 * @return string
220 */
221 public function getEmail()
222 {
223 return $this->email;
224 }
225
226 /**
227 * Customer Email address
228 *
229 * @param string $email
230 *
231 * @return Customer
232 */
233 public function setEmail($email)
234 {
235 $this->email = $email;
236
237 return $this;
238 }
239 }
240