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