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