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  * Process IPC method: IPCIAPurchase.
  7  * Collect, validate and send API params
  8  */
  9 class IAPurchase extends Base
 10 {
 11 
 12     /**
 13      * @var Cart
 14      */
 15     private $cart;
 16 
 17     /**
 18      * @var Card
 19      */
 20     private $card;
 21 
 22 
 23     private $currency = 'EUR', $note, $orderID, $accountSettlement;
 24 
 25     /**
 26      * Return purchase object
 27      * @param Config $cnf
 28      */
 29     public function __construct(Config $cnf)
 30     {
 31         $this->setCnf($cnf);
 32     }
 33 
 34     /**
 35      * Purchase identifier - must be unique
 36      * @param string $orderID
 37      * @return Purchase
 38      */
 39     public function setOrderID($orderID)
 40     {
 41         $this->orderID = $orderID;
 42         return $this;
 43     }
 44 
 45     /**
 46      * Purchase identifier
 47      * @return string
 48      */
 49     public function getOrderID()
 50     {
 51         return $this->orderID;
 52     }
 53 
 54     /**
 55      * Optional note to purchase
 56      * @param string $note
 57      * @return Purchase
 58      */
 59     public function setNote($note)
 60     {
 61         $this->note = $note;
 62         return $this;
 63     }
 64 
 65     /**
 66      * Optional note to purchase
 67      * @return string
 68      */
 69     public function getNote()
 70     {
 71         return $this->note;
 72     }
 73 
 74     /**
 75      * ISO-4217 Three letter currency code
 76      * @param string $currency
 77      * @return Purchase
 78      */
 79     public function setCurrency($currency)
 80     {
 81         $this->currency = $currency;
 82         return $this;
 83     }
 84 
 85     /**
 86      * ISO-4217 Three letter currency code
 87      * @return string
 88      */
 89     public function getCurrency()
 90     {
 91         return $this->currency;
 92     }
 93 
 94     /**
 95      * Cart object
 96      * @param Cart $cart
 97      * @return Purchase
 98      */
 99     public function setCart(Cart $cart)
100     {
101         $this->cart = $cart;
102         return $this;
103     }
104 
105     /**
106      * Cart object
107      * @return Cart
108      */
109     public function getCart()
110     {
111         return $this->cart;
112     }
113 
114     /**
115      * Card object
116      * @return Card
117      */
118     public function getCard()
119     {
120         return $this->card;
121     }
122 
123     /**
124      * Card object
125      * @param Card $card
126      */
127     public function setCard($card)
128     {
129         $this->card = $card;
130     }
131 
132     /**
133      * Account for payment settlement
134      * @return string
135      */
136     public function getAccountSettlement()
137     {
138         return $this->accountSettlement;
139     }
140 
141     /**
142      * Account for payment settlement
143      * @param string $accountSettlement
144      */
145     public function setAccountSettlement($accountSettlement)
146     {
147         $this->accountSettlement = $accountSettlement;
148     }
149 
150     /**
151      * Initiate API request
152      * @return Response
153      */
154     public function process()
155     {
156         $this->validate();
157 
158         $this->_addPostParam('IPCmethod', 'IPCIAPurchase');
159         $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
160         $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
161         $this->_addPostParam('SID', $this->getCnf()->getSid());
162         $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
163         $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
164         $this->_addPostParam('Source', Defines::SOURCE_PARAM);
165 
166         $this->_addPostParam('OrderID', $this->getOrderID());
167         $this->_addPostParam('Amount', $this->getCart()->getTotal());
168         $this->_addPostParam('Currency', $this->getCurrency());
169 
170         if ($this->getCard()->getCardToken()) {
171             $this->_addPostParam('CardToken', $this->getCard()->getCardToken());
172         } else {
173             $this->_addPostParam('CardType', $this->getCard()->getCardType());
174             $this->_addPostParam('PAN', $this->getCard()->getCardNumber(), true);
175             $this->_addPostParam('CardholderName', $this->getCard()->getCardHolder());
176             $this->_addPostParam('ExpDate', $this->getCard()->getExpDate(), true);
177             $this->_addPostParam('CVC', $this->getCard()->getCvc(), true);
178             $this->_addPostParam('ECI', $this->getCard()->getEci());
179             $this->_addPostParam('AVV', $this->getCard()->getAvv());
180             $this->_addPostParam('XID', $this->getCard()->getXid());
181         }
182 
183         $this->_addPostParam('AccountSettlement', $this->getAccountSettlement());
184         $this->_addPostParam('Note', $this->getNote());
185         $this->_addPostParam('OutputFormat', $this->getOutputFormat());
186 
187         $this->_addPostParam('CartItems', $this->getCart()->getItemsCount());
188         $items = $this->getCart()->getCart();
189         $i = 1;
190         foreach ($items as $v) {
191             $this->_addPostParam('Article_' . $i, $v['name']);
192             $this->_addPostParam('Quantity_' . $i, $v['quantity']);
193             $this->_addPostParam('Price_' . $i, $v['price']);
194             $this->_addPostParam('Amount_' . $i, $v['price'] * $v['quantity']);
195             $this->_addPostParam('Currency_' . $i, $this->getCurrency());
196             $i++;
197         }
198         return $this->_processPost();
199     }
200 
201     /**
202      * Validate all set purchase details
203      * @return boolean
204      * @throws IPC_Exception
205      */
206     public function validate()
207     {
208         if ($this->getCurrency() === null || strpos(Defines::AVL_CURRENCIES, $this->getCurrency()) === false) {
209             throw new IPC_Exception('Invalid currency');
210         }
211 
212         try {
213             $this->getCnf()->validate();
214         } catch (Exception $ex) {
215             throw new IPC_Exception('Invalid Config details: ' . $ex->getMessage());
216         }
217 
218         try {
219             $this->getCart()->validate();
220         } catch (Exception $ex) {
221             throw new IPC_Exception('Invalid Cart details: ' . $ex->getMessage());
222         }
223 
224         try {
225             $this->getCard()->validate();
226         } catch (Exception $ex) {
227             throw new IPC_Exception('Invalid Card details: ' . $ex->getMessage());
228         }
229         return true;
230     }
231 
232 }
233 
API documentation generated by ApiGen