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