1 <?php
2
3 namespace Mypos\IPC;
4
5 6 7 8
9 class IAPurchase extends Base
10 {
11
12 13 14
15 private $cart;
16
17 18 19
20 private $card;
21
22
23 private $currency = 'EUR', $note, $orderID, $accountSettlement;
24
25 26 27 28
29 public function __construct(Config $cnf)
30 {
31 $this->setCnf($cnf);
32 }
33
34 35 36 37 38
39 public function setOrderID($orderID)
40 {
41 $this->orderID = $orderID;
42 return $this;
43 }
44
45 46 47 48
49 public function getOrderID()
50 {
51 return $this->orderID;
52 }
53
54 55 56 57 58
59 public function setNote($note)
60 {
61 $this->note = $note;
62 return $this;
63 }
64
65 66 67 68
69 public function getNote()
70 {
71 return $this->note;
72 }
73
74 75 76 77 78
79 public function setCurrency($currency)
80 {
81 $this->currency = $currency;
82 return $this;
83 }
84
85 86 87 88
89 public function getCurrency()
90 {
91 return $this->currency;
92 }
93
94 95 96 97 98
99 public function setCart(Cart $cart)
100 {
101 $this->cart = $cart;
102 return $this;
103 }
104
105 106 107 108
109 public function getCart()
110 {
111 return $this->cart;
112 }
113
114 115 116 117
118 public function getCard()
119 {
120 return $this->card;
121 }
122
123 124 125 126
127 public function setCard($card)
128 {
129 $this->card = $card;
130 }
131
132 133 134 135
136 public function getAccountSettlement()
137 {
138 return $this->accountSettlement;
139 }
140
141 142 143 144
145 public function setAccountSettlement($accountSettlement)
146 {
147 $this->accountSettlement = $accountSettlement;
148 }
149
150 151 152 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 203 204 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