1: | <?php
|
2: |
|
3: | namespace Mypos\IPC;
|
4: |
|
5: | |
6: | |
7: | |
8: |
|
9: | class Authorization extends Base
|
10: | {
|
11: | |
12: | |
13: |
|
14: | private $card;
|
15: | private $currency = 'EUR', $note, $orderID, $itemName, $amount;
|
16: |
|
17: | |
18: | |
19: | |
20: | |
21: |
|
22: | public function __construct(Config $cnf)
|
23: | {
|
24: | $this->setCnf($cnf);
|
25: | }
|
26: |
|
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: |
|
34: | public function setOrderID($orderID)
|
35: | {
|
36: | $this->orderID = $orderID;
|
37: |
|
38: | return $this;
|
39: | }
|
40: |
|
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: |
|
48: | public function setItemName($itemName)
|
49: | {
|
50: | $this->itemName = $itemName;
|
51: |
|
52: | return $this;
|
53: | }
|
54: |
|
55: | |
56: | |
57: | |
58: | |
59: | |
60: | |
61: |
|
62: | public function setCurrency($currency)
|
63: | {
|
64: | $this->currency = $currency;
|
65: |
|
66: | return $this;
|
67: | }
|
68: |
|
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: |
|
76: | public function setAmount($amount)
|
77: | {
|
78: | $this->amount = $amount;
|
79: |
|
80: | return $this;
|
81: | }
|
82: |
|
83: | |
84: | |
85: | |
86: | |
87: | |
88: | |
89: |
|
90: | public function setCard($card)
|
91: | {
|
92: | $this->card = $card;
|
93: |
|
94: | return $this;
|
95: | }
|
96: |
|
97: | |
98: | |
99: | |
100: | |
101: | |
102: | |
103: |
|
104: | public function setNote($note)
|
105: | {
|
106: | $this->note = $note;
|
107: |
|
108: | return $this;
|
109: | }
|
110: |
|
111: | |
112: | |
113: | |
114: | |
115: | |
116: |
|
117: | public function process()
|
118: | {
|
119: | $this->validate();
|
120: |
|
121: | $this->_addPostParam('IPCmethod', 'IPCAuthorization');
|
122: | $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
|
123: | $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
|
124: | $this->_addPostParam('SID', $this->getCnf()->getSid());
|
125: | $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
|
126: | $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
|
127: | $this->_addPostParam('Source', $this->getCnf()->getSource());
|
128: |
|
129: | $this->_addPostParam('OrderID', $this->getOrderID());
|
130: |
|
131: | $this->_addPostParam('ItemName', $this->getItemName());
|
132: |
|
133: | $this->_addPostParam('Amount', $this->getAmount());
|
134: | $this->_addPostParam('Currency', $this->getCurrency());
|
135: |
|
136: | $this->_addPostParam('CardToken', $this->getCard()->getCardToken());
|
137: |
|
138: | $this->_addPostParam('Note', $this->getNote());
|
139: | $this->_addPostParam('OutputFormat', $this->getOutputFormat());
|
140: |
|
141: | $this->_addPostParam('ApplicationID', $this->getCnf()->getApplicationID());
|
142: | $this->_addPostParam('PartnerID', $this->getCnf()->getPartnerID());
|
143: |
|
144: | return $this->_processPost();
|
145: | }
|
146: |
|
147: | |
148: | |
149: | |
150: | |
151: | |
152: |
|
153: | public function validate()
|
154: | {
|
155: | try {
|
156: | $this->getCnf()->validate();
|
157: | } catch (\Exception $ex) {
|
158: | throw new IPC_Exception('Invalid Config details: ' . $ex->getMessage());
|
159: | }
|
160: |
|
161: | if (!Helper::versionCheck($this->getCnf()->getVersion(), '1.4')) {
|
162: | throw new IPC_Exception('IPCVersion ' . $this->getCnf()->getVersion() . ' does not support IPCAuthorization method. Please use 1.4 or above.');
|
163: | }
|
164: |
|
165: | if ($this->getItemName() === null || !is_string($this->getItemName())) {
|
166: | throw new IPC_Exception('Empty or invalid item name.');
|
167: | }
|
168: |
|
169: | if ($this->getCurrency() === null) {
|
170: | throw new IPC_Exception('Invalid currency');
|
171: | }
|
172: |
|
173: | if ($this->getAmount() === null || !Helper::isValidAmount($this->getAmount())) {
|
174: | throw new IPC_Exception('Empty or invalid amount');
|
175: | }
|
176: |
|
177: | if ($this->getCard() === null) {
|
178: | throw new IPC_Exception('Missing card details');
|
179: | }
|
180: |
|
181: | if ($this->getCard()->getCardNumber() !== null) {
|
182: | throw new IPC_Exception('IPCAuthorization supports only card token.');
|
183: | }
|
184: |
|
185: | try {
|
186: | $this->getCard()->validate();
|
187: | } catch (\Exception $ex) {
|
188: | throw new IPC_Exception('Invalid Card details: ' . $ex->getMessage());
|
189: | }
|
190: |
|
191: | if ($this->getCnf()->getVersion() === '1.4.1') {
|
192: | if ($this->getCnf()->getPartnerID() == null) {
|
193: | throw new IPC_Exception('Required parameter: Partner ID');
|
194: | }
|
195: |
|
196: | if ($this->getCnf()->getApplicationID() == null) {
|
197: | throw new IPC_Exception('Required parameter: Application ID');
|
198: | }
|
199: | }
|
200: |
|
201: | return true;
|
202: | }
|
203: |
|
204: | |
205: | |
206: | |
207: | |
208: |
|
209: | public function getCurrency()
|
210: | {
|
211: | return $this->currency;
|
212: | }
|
213: |
|
214: | |
215: | |
216: | |
217: | |
218: |
|
219: | public function getCard()
|
220: | {
|
221: | return $this->card;
|
222: | }
|
223: |
|
224: | |
225: | |
226: | |
227: | |
228: |
|
229: | public function getOrderID()
|
230: | {
|
231: | return $this->orderID;
|
232: | }
|
233: |
|
234: | |
235: | |
236: | |
237: | |
238: |
|
239: | public function getItemName()
|
240: | {
|
241: | return $this->itemName;
|
242: | }
|
243: |
|
244: | |
245: | |
246: | |
247: | |
248: |
|
249: | public function getAmount()
|
250: | {
|
251: | return $this->amount;
|
252: | }
|
253: |
|
254: | |
255: | |
256: | |
257: | |
258: |
|
259: | public function getNote()
|
260: | {
|
261: | return $this->note;
|
262: | }
|
263: | }
|
264: | |