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