Overview
  • Namespace
  • Class

Namespaces

  • Satabank
    • IPC

Classes

  • Satabank\IPC\Base
  • Satabank\IPC\Cart
  • Satabank\IPC\Config
  • Satabank\IPC\Customer
  • Satabank\IPC\Defines
  • Satabank\IPC\GetTxnStatus
  • Satabank\IPC\Helper
  • Satabank\IPC\IPCGetTxnLog
  • Satabank\IPC\Loader
  • Satabank\IPC\Purchase
  • Satabank\IPC\Refund
  • Satabank\IPC\Response

Exceptions

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