1 <?php
2
3 namespace Mypos\IPC;
4
5 6 7
8 class Config{
9
10 private $privateKey = null;
11 private $APIPublicKey = null;
12 private $encryptPublicKey = null;
13 private $keyIndex = null;
14 private $sid;
15 private $wallet;
16 private $lang = 'en';
17 private $version = '1.3';
18 private $ipc_url = 'https://www.mypos.eu/vmp/checkout';
19 private $developerKey;
20
21 22 23 24 25
26 public function setPrivateKey($privateKey){
27 $this->privateKey = $privateKey;
28 return $this;
29 }
30
31 32 33 34
35 public function getPrivateKey(){
36 return $this->privateKey;
37 }
38
39 40 41 42 43 44
45 public function setPrivateKeyPath($path){
46 if(!is_file($path) || !is_readable($path)){
47 throw new IPC_Exception('Private key not found in:' . $path);
48 }
49 $this->privateKey = file_get_contents($path);
50 return $this;
51 }
52
53 54 55 56 57
58 public function setAPIPublicKey($publicKey){
59 $this->APIPublicKey = $publicKey;
60 return $this;
61 }
62
63 64 65 66
67 public function getAPIPublicKey(){
68 return $this->APIPublicKey;
69 }
70
71 72 73 74 75 76
77 public function setAPIPublicKeyPath($path){
78 if(!is_file($path) || !is_readable($path)){
79 throw new IPC_Exception('Public key not found in:' . $path);
80 }
81 $this->APIPublicKey = file_get_contents($path);
82 return $this;
83 }
84
85
86
87 88 89 90 91
92 public function setEncryptPublicKey($key){
93 $this->encryptPublicKey = $key;
94 return $this;
95 }
96
97 98 99 100
101 public function getEncryptPublicKey(){
102 return $this->encryptPublicKey;
103 }
104
105 106 107 108 109 110
111 public function setEncryptPublicKeyPath($path){
112 if(!is_file($path) || !is_readable($path)){
113 throw new IPC_Exception('Key not found in:' . $path);
114 }
115 $this->encryptPublicKey = file_get_contents($path);
116 return $this;
117 }
118
119
120 121 122 123 124
125 public function setKeyIndex($keyIndex){
126 $this->keyIndex = $keyIndex;
127 return $this;
128 }
129
130 131 132 133
134 public function getKeyIndex(){
135 return $this->keyIndex;
136 }
137
138 139 140 141
142 public function getSid(){
143 return $this->sid;
144 }
145
146 147 148 149 150
151 public function setSid($sid){
152 $this->sid = $sid;
153 return $this;
154 }
155
156 157 158 159 160
161 public function setWallet($wallet){
162 $this->wallet = $wallet;
163 return $this;
164 }
165
166 167 168 169
170 public function getWallet(){
171 return $this->wallet;
172 }
173
174 175 176 177 178
179 public function setLang($lang){
180 $this->lang = $lang;
181 return $this;
182 }
183
184 185 186 187
188 public function getLang(){
189 return $this->lang;
190 }
191
192 193 194 195 196
197 public function setVersion($version){
198 $this->version = $version;
199 return $this;
200 }
201
202 203 204 205
206 public function getVersion(){
207 return $this->version;
208 }
209
210 211 212 213
214 public function getIpcURL(){
215 return $this->ipc_url;
216 }
217
218 219 220 221 222
223 public function setIpcURL($ipc_url){
224 $this->ipc_url = $ipc_url;
225 return $this;
226 }
227
228 229 230 231 232
233 public function setDeveloperKey($developerKey){
234 $this->developerKey = $developerKey;
235 return $this;
236 }
237
238 239 240 241
242 public function getDeveloperKey(){
243 return $this->developerKey;
244 }
245
246 247 248 249 250
251 public function validate(){
252 if($this->getKeyIndex() == null || !is_numeric($this->getKeyIndex())){
253 throw new IPC_Exception('Invalid Key Index');
254 }
255
256 if($this->getIpcURL() == null || !Helper::isValidURL($this->getIpcURL())){
257 throw new IPC_Exception('Invalid IPC URL');
258 }
259
260 if($this->getSid() == null || !is_numeric($this->getSid())){
261 throw new IPC_Exception('Invalid SID');
262 }
263
264 if($this->getWallet() == null || !is_numeric($this->getWallet())){
265 throw new IPC_Exception('Invalid Wallet number');
266 }
267
268 if($this->getVersion() == null){
269 throw new IPC_Exception('Invalid IPC Version');
270 }
271
272 if(!openssl_get_privatekey($this->getPrivateKey())){
273 throw new IPC_Exception('Invalid Private key');
274 }
275 return true;
276 }
277
278 }
279