Overview
  • Namespace
  • Class

Namespaces

  • Mypos
    • IPC

Classes

  • Mypos\IPC\Base
  • Mypos\IPC\Card
  • Mypos\IPC\CardStore
  • Mypos\IPC\Cart
  • Mypos\IPC\Config
  • Mypos\IPC\Customer
  • Mypos\IPC\Defines
  • Mypos\IPC\GetTxnStatus
  • Mypos\IPC\Helper
  • Mypos\IPC\IAPurchase
  • Mypos\IPC\IAStoreCard
  • Mypos\IPC\IAStoredCardUpdate
  • Mypos\IPC\IPCGetTxnLog
  • Mypos\IPC\Loader
  • Mypos\IPC\MandateManagement
  • Mypos\IPC\Purchase
  • Mypos\IPC\Refund
  • Mypos\IPC\RequestMoney
  • Mypos\IPC\Response
  • Mypos\IPC\Reversal

Exceptions

  • Mypos\IPC\IPC_Exception
  1 <?php
  2 
  3 namespace Mypos\IPC;
  4 
  5 /**
  6  * IPC Configuration class
  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      * Store private RSA key
 23      * @param string $privateKey
 24      * @return Config
 25      */
 26     public function setPrivateKey($privateKey){
 27         $this->privateKey = $privateKey;
 28         return $this;
 29     }
 30 
 31     /**
 32      * Store private RSA key
 33      * @return type
 34      */
 35     public function getPrivateKey(){
 36         return $this->privateKey;
 37     }
 38 
 39     /**
 40      * Store private RSA key as a filepath
 41      * @param string $path File path
 42      * @return Config
 43      * @throws IPC_Exception
 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      * IPC API public RSA key
 55      * @param string $publicKey
 56      * @return Config
 57      */
 58     public function setAPIPublicKey($publicKey){
 59         $this->APIPublicKey = $publicKey;
 60         return $this;
 61     }
 62 
 63     /**
 64      * IPC API public RSA key
 65      * @return string
 66      */
 67     public function getAPIPublicKey(){
 68         return $this->APIPublicKey;
 69     }
 70 
 71     /**
 72      * IPC API public RSA key as a filepath
 73      * @param string $path
 74      * @return Config
 75      * @throws IPC_Exception
 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      * Public RSA key using for encryption sensitive data
 89      * @param string $privateKey
 90      * @return Config
 91      */
 92     public function setEncryptPublicKey($key){
 93         $this->encryptPublicKey = $key;
 94         return $this;
 95     }
 96 
 97     /**
 98      * Public RSA key using for encryption sensitive data
 99      * @return type
100      */
101     public function getEncryptPublicKey(){
102         return $this->encryptPublicKey;
103     }
104 
105     /**
106      * Public RSA key using for encryption sensitive data
107      * @param string $path File path
108      * @return Config
109      * @throws IPC_Exception
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      * Keyindex used for signing request
122      * @param int $keyIndex
123      * @return Config
124      */
125     public function setKeyIndex($keyIndex){
126         $this->keyIndex = $keyIndex;
127         return $this;
128     }
129 
130     /**
131      *  Keyindex used for signing request
132      * @return type
133      */
134     public function getKeyIndex(){
135         return $this->keyIndex;
136     }
137 
138     /**
139      * Store ID
140      * @return int
141      */
142     public function getSid(){
143         return $this->sid;
144     }
145 
146     /**
147      * Store ID
148      * @param int $sid
149      * @return Config
150      */
151     public function setSid($sid){
152         $this->sid = $sid;
153         return $this;
154     }
155 
156     /**
157      * Wallet number
158      * @param string $wallet
159      * @return Config
160      */
161     public function setWallet($wallet){
162         $this->wallet = $wallet;
163         return $this;
164     }
165 
166     /**
167      * Wallet number
168      * @return string
169      */
170     public function getWallet(){
171         return $this->wallet;
172     }
173 
174     /**
175      * Language code (ISO 639-1)
176      * @param string $lang
177      * @return Config
178      */
179     public function setLang($lang){
180         $this->lang = $lang;
181         return $this;
182     }
183 
184     /**
185      * Language code (ISO 639-1)
186      * @return string
187      */
188     public function getLang(){
189         return $this->lang;
190     }
191 
192     /**
193      * API Version
194      * @param string $version
195      * @return Config
196      */
197     public function setVersion($version){
198         $this->version = $version;
199         return $this;
200     }
201 
202     /**
203      * API Version
204      * @return string
205      */
206     public function getVersion(){
207         return $this->version;
208     }
209 
210     /**
211      * IPC API URL
212      * @return string
213      */
214     public function getIpcURL(){
215         return $this->ipc_url;
216     }
217 
218     /**
219      * IPC API URL
220      * @param string $ipc_url
221      * @return Config
222      */
223     public function setIpcURL($ipc_url){
224         $this->ipc_url = $ipc_url;
225         return $this;
226     }
227 
228     /**
229      * Set myPOS developer key.
230      * @param string $developerKey
231      * @return Config
232      */
233     public function setDeveloperKey($developerKey){
234         $this->developerKey = $developerKey;
235         return $this;
236     }
237 
238     /**
239      * Store private RSA key
240      * @return type
241      */
242     public function getDeveloperKey(){
243         return $this->developerKey;
244     }
245 
246     /**
247      * Validate all set config details
248      * @return boolean
249      * @throws IPC_Exception
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 
API documentation generated by ApiGen