1: <?php
2:
3: namespace Mypos\IPC;
4:
5: /**
6: * Process IPC method: IPCRequestMoney.
7: * Collect, validate and send API params
8: */
9: class RequestMoney extends Base
10: {
11: private $currency = 'EUR', $amount, $orderID, $mandateReference, $customerWalletNumber, $reversalIndicator, $reason;
12:
13: /**
14: * Return Refund object
15: *
16: * @param Config $cnf
17: */
18: public function __construct(Config $cnf)
19: {
20: $this->setCnf($cnf);
21: }
22:
23: /**
24: * Refund amount
25: *
26: * @param float $amount
27: */
28: public function setAmount($amount)
29: {
30: $this->amount = $amount;
31: }
32:
33: /**
34: * Request identifier - must be unique
35: *
36: * @param string $orderID
37: *
38: * @return RequestMoney
39: */
40: public function setOrderID($orderID)
41: {
42: $this->orderID = $orderID;
43:
44: return $this;
45: }
46:
47: /**
48: * Unique identifier of the agreement (mandate) between the merchant and the client (debtor). Up to 127 characters.
49: *
50: * @param string $mandateReference
51: */
52: public function setMandateReference($mandateReference)
53: {
54: $this->mandateReference = $mandateReference;
55: }
56:
57: /**
58: * Identifier of the client’s (debtor’s) myPOS account
59: *
60: * @param string $customerWalletNumber
61: */
62: public function setCustomerWalletNumber($customerWalletNumber)
63: {
64: $this->customerWalletNumber = $customerWalletNumber;
65: }
66:
67: /**
68: * Reversal of the previously executed Request money transaction.
69: *
70: * @param bool $reversalIndicator
71: */
72: public function setReversalIndicator($reversalIndicator)
73: {
74: $this->reversalIndicator = $reversalIndicator;
75: }
76:
77: /**
78: * The reason for the transfer.
79: *
80: * @param string $reason
81: */
82: public function setReason($reason)
83: {
84: $this->reason = $reason;
85: }
86:
87: /**
88: * Initiate API request
89: *
90: * @return Response
91: * @throws IPC_Exception
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: * Validate all set refund details
124: *
125: * @return boolean
126: * @throws IPC_Exception
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: * Refund amount
167: *
168: * @return float
169: */
170: public function getAmount()
171: {
172: return $this->amount;
173: }
174:
175: /**
176: * ISO-4217 Three letter currency code
177: *
178: * @return string
179: */
180: public function getCurrency()
181: {
182: return $this->currency;
183: }
184:
185: /**
186: * ISO-4217 Three letter currency code
187: *
188: * @param string $currency
189: *
190: * @return RequestMoney
191: */
192: public function setCurrency($currency)
193: {
194: $this->currency = $currency;
195:
196: return $this;
197: }
198:
199: /**
200: * Request identifier - must be unique
201: *
202: * @return string
203: */
204: public function getOrderID()
205: {
206: return $this->orderID;
207: }
208:
209: /**
210: * Unique identifier of the agreement (mandate) between the merchant and the client (debtor). Up to 127 characters.
211: *
212: * @return string
213: */
214: public function getMandateReference()
215: {
216: return $this->mandateReference;
217: }
218:
219: /**
220: * Identifier of the client’s (debtor’s) myPOS account
221: *
222: * @return string
223: */
224: public function getCustomerWalletNumber()
225: {
226: return $this->customerWalletNumber;
227: }
228:
229: /**
230: * Reversal of the previously executed Request money transaction.
231: *
232: * @return bool
233: */
234: public function getReversalIndicator()
235: {
236: return $this->reversalIndicator;
237: }
238:
239: /**
240: * The reason for the transfer.
241: *
242: * @return string
243: */
244: public function getReason()
245: {
246: return $this->reason;
247: }
248:
249: }