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  * Process IPC method: IPCPurchase.
  7  * Collect, validate and send API params
  8  */
  9 class Purchase extends Base{
 10 
 11     /**
 12      * @var Cart
 13      */
 14     private $cart;
 15 
 16     /**
 17      * @var Customer
 18      */
 19     private $customer;
 20     private $url_ok, $url_cancel, $url_notify;
 21     private $currency = 'EUR', $note, $orderID;
 22 
 23     /**
 24      * Return purchase object
 25      * @param Config $cnf
 26      */
 27     public function __construct(Config $cnf){
 28         $this->setCnf($cnf);
 29     }
 30 
 31     /**
 32      * Purchase identifier - must be unique
 33      * @param string $orderID
 34      * @return Purchase
 35      */
 36     public function setOrderID($orderID){
 37         $this->orderID = $orderID;
 38         return $this;
 39     }
 40 
 41     /**
 42      * Purchase identifier
 43      * @return string
 44      */
 45     public function getOrderID(){
 46         return $this->orderID;
 47     }
 48 
 49     /**
 50      * Optional note to purchase
 51      * @param string $note
 52      * @return Purchase
 53      */
 54     public function setNote($note){
 55         $this->note = $note;
 56         return $this;
 57     }
 58 
 59     /**
 60      * Optional note to purchase
 61      * @return string
 62      */
 63     public function getNote(){
 64         return $this->note;
 65     }
 66 
 67     /**
 68      * ISO-4217 Three letter currency code 
 69      * @param string $currency
 70      * @return Purchase
 71      */
 72     public function setCurrency($currency){
 73         $this->currency = $currency;
 74         return $this;
 75     }
 76 
 77     /**
 78      * ISO-4217 Three letter currency code 
 79      * @return string
 80      */
 81     public function getCurrency(){
 82         return $this->currency;
 83     }
 84 
 85     /**
 86      * Cart object
 87      * @param Cart $cart
 88      * @return Purchase
 89      */
 90     public function setCart(Cart $cart){
 91         $this->cart = $cart;
 92         return $this;
 93     }
 94 
 95     /**
 96      * Cart object
 97      * @return Cart
 98      */
 99     public function getCart(){
100         return $this->cart;
101     }
102 
103     /**
104      * Customer object
105      * @param Customer $customer
106      * @return Purchase
107      */
108     public function setCustomer(Customer $customer){
109         $this->customer = $customer;
110         return $this;
111     }
112 
113     /**
114      * @return Customer
115      */
116     public function getCustomer(){
117         return $this->customer;
118     }
119 
120     /**
121      * Merchant Site URL where client comes after successful payment
122      * @param string $urlOk
123      * @return Config
124      */
125     public function setUrlOk($urlOk){
126         $this->url_ok = $urlOk;
127         return $this;
128     }
129 
130     /**
131      * Merchant Site URL where client comes after successful payment
132      * @return string
133      */
134     public function getUrlOk(){
135         return $this->url_ok;
136     }
137 
138     /**
139      * Merchant Site URL where client comes after unsuccessful payment
140      * @param string $urlCancel
141      * @return Config
142      */
143     public function setUrlCancel($urlCancel){
144         $this->url_cancel = $urlCancel;
145         return $this;
146     }
147 
148     /**
149      * Merchant Site URL where client comes after unsuccessful payment
150      * @return string
151      */
152     public function getUrlCancel(){
153         return $this->url_cancel;
154     }
155 
156     /**
157      * Merchant Site URL where IPC posts Purchase Notify requests
158      * @param string $urlNotify
159      * @return Config
160      */
161     public function setUrlNotify($urlNotify){
162         $this->url_notify = $urlNotify;
163         return $this;
164     }
165 
166     /**
167      * Merchant Site URL where IPC posts Purchase Notify requests
168      * @var string 
169      */
170     public function getUrlNotify(){
171         return $this->url_notify;
172     }
173 
174     /**
175      * Initiate API request
176      * @return boolean
177      */
178     public function process(){
179         $this->validate();
180 
181         $this->_addPostParam('IPCmethod', 'IPCPurchase');
182         $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
183         $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
184         $this->_addPostParam('SID', $this->getCnf()->getSid());
185         $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
186         $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
187         $this->_addPostParam('Source', Defines::SOURCE_PARAM);
188 
189         $this->_addPostParam('Currency', $this->getCurrency());
190         $this->_addPostParam('Amount', $this->cart->getTotal());
191 
192         $this->_addPostParam('OrderID', $this->getOrderID());
193         $this->_addPostParam('URL_OK', $this->getUrlOk());
194         $this->_addPostParam('URL_Cancel', $this->getUrlCancel());
195         $this->_addPostParam('URL_Notify', $this->getUrlNotify());
196 
197         $this->_addPostParam('customeremail', $this->getCustomer()->getEmail());
198         $this->_addPostParam('customerphone', $this->getCustomer()->getPhone());
199         $this->_addPostParam('customerfirstnames', $this->getCustomer()->getFirstName());
200         $this->_addPostParam('customerfamilyname', $this->getCustomer()->getLastName());
201         $this->_addPostParam('customercountry', $this->getCustomer()->getCountry());
202         $this->_addPostParam('customercity', $this->getCustomer()->getCity());
203         $this->_addPostParam('customerzipcode', $this->getCustomer()->getZip());
204         $this->_addPostParam('customeraddress', $this->getCustomer()->getAddress());
205 
206         $this->_addPostParam('Note', $this->getNote());
207         $this->_addPostParam('CartItems', $this->cart->getItemsCount());
208         $items = $this->cart->getCart();
209 
210         $i = 1;
211         foreach($items as $v){
212             $this->_addPostParam('Article_' . $i, $v['name']);
213             $this->_addPostParam('Quantity_' . $i, $v['quantity']);
214             $this->_addPostParam('Price_' . $i, $v['price']);
215             $this->_addPostParam('Amount_' . $i, $v['price'] * $v['quantity']);
216             $this->_addPostParam('Currency_' . $i, $this->getCurrency());
217             $i++;
218         }
219 
220         $this->_processHtmlPost();
221         return true;
222     }
223 
224     /**
225      * Validate all set purchase details
226      * @return boolean
227      * @throws IPC_Exception
228      */
229     public function validate(){
230 
231         if($this->getUrlCancel() == null || !Helper::isValidURL($this->getUrlCancel())){
232             throw new IPC_Exception('Invalid Cancel URL');
233         }
234 
235         if($this->getUrlNotify() == null || !Helper::isValidURL($this->getUrlNotify())){
236             throw new IPC_Exception('Invalid Notify URL');
237         }
238 
239         if($this->getUrlOk() == null || !Helper::isValidURL($this->getUrlOk())){
240             throw new IPC_Exception('Invalid Success URL');
241         }
242 
243         try{
244             $this->getCnf()->validate();
245         }catch(Exception $ex){
246             throw new IPC_Exception('Invalid Config details: ' . $ex->getMessage());
247         }
248 
249         try{
250             $this->getCart()->validate();
251         }catch(Exception $ex){
252             throw new IPC_Exception('Invalid Cart details: ' . $ex->getMessage());
253         }
254 
255         try{
256             $this->getCustomer()->validate();
257         }catch(Exception $ex){
258             throw new IPC_Exception('Invalid Customer details: ' . $ex->getMessage());
259         }
260 
261 
262         return true;
263     }
264 
265 }
266 
API documentation generated by ApiGen