1: <?php
2:
3: namespace Mypos\IPC;
4:
5: /**
6: * Process IPC method: IPCSendMoney.
7: * Collect, validate and send API params
8: */
9: class SendMoney extends Base
10: {
11: private $currency = 'EUR', $amount, $orderID, $customerWalletNumber, $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 SendMoney
39: */
40: public function setOrderID($orderID)
41: {
42: $this->orderID = $orderID;
43:
44: return $this;
45: }
46:
47: /**
48: * Identifier of the client’s (debtor’s) myPOS account
49: *
50: * @param string $customerWalletNumber
51: */
52: public function setCustomerWalletNumber($customerWalletNumber)
53: {
54: $this->customerWalletNumber = $customerWalletNumber;
55: }
56:
57: /**
58: * The reason for the transfer.
59: *
60: * @param string $reason
61: */
62: public function setReason($reason)
63: {
64: $this->reason = $reason;
65: }
66:
67: /**
68: * Initiate API request
69: *
70: * @return Response
71: * @throws IPC_Exception
72: */
73: public function process()
74: {
75: $this->validate();
76:
77: $this->_addPostParam('IPCmethod', 'IPCSendMoney');
78: $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
79: $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
80: $this->_addPostParam('SID', $this->getCnf()->getSid());
81: $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
82: $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
83: $this->_addPostParam('Source', $this->getCnf()->getSource());
84:
85: $this->_addPostParam('Currency', $this->getCurrency());
86: $this->_addPostParam('Amount', $this->getAmount());
87:
88: $this->_addPostParam('OrderID', $this->getOrderID());
89:
90: $this->_addPostParam('CustomerWalletNumber', $this->getCustomerWalletNumber());
91: $this->_addPostParam('Reason', $this->getReason());
92: $this->_addPostParam('OutputFormat', $this->getOutputFormat());
93:
94: $this->_addPostParam('ApplicationID', $this->getCnf()->getApplicationID());
95: $this->_addPostParam('PartnerID', $this->getCnf()->getPartnerID());
96:
97: return $this->_processPost();
98: }
99:
100: /**
101: * Validate all set refund details
102: *
103: * @return boolean
104: * @throws IPC_Exception
105: */
106: public function validate()
107: {
108: try {
109: $this->getCnf()->validate();
110: } catch (\Exception $ex) {
111: throw new IPC_Exception('Invalid Config details: '.$ex->getMessage());
112: }
113:
114: if ($this->getAmount() == null || !Helper::isValidAmount($this->getAmount())) {
115: throw new IPC_Exception('Invalid Amount');
116: }
117:
118: if ($this->getCurrency() == null) {
119: throw new IPC_Exception('Invalid Currency');
120: }
121:
122: if ($this->getOrderID() == null || !Helper::isValidOrderId($this->getOrderID())) {
123: throw new IPC_Exception('Invalid OrderId');
124: }
125:
126: if ($this->getOutputFormat() == null || !Helper::isValidOutputFormat($this->getOutputFormat())) {
127: throw new IPC_Exception('Invalid Output format');
128: }
129:
130: if ($this->getCnf()->getVersion() === '1.4.1') {
131: if ($this->getCnf()->getPartnerID() == null) {
132: throw new IPC_Exception('Required parameter: Partner ID');
133: }
134:
135: if ($this->getCnf()->getApplicationID() == null) {
136: throw new IPC_Exception('Required parameter: Application ID');
137: }
138: }
139:
140: return true;
141: }
142:
143: /**
144: * Refund amount
145: *
146: * @return float
147: */
148: public function getAmount()
149: {
150: return $this->amount;
151: }
152:
153: /**
154: * ISO-4217 Three letter currency code
155: *
156: * @return string
157: */
158: public function getCurrency()
159: {
160: return $this->currency;
161: }
162:
163: /**
164: * ISO-4217 Three letter currency code
165: *
166: * @param string $currency
167: *
168: * @return SendMoney
169: */
170: public function setCurrency($currency)
171: {
172: $this->currency = $currency;
173:
174: return $this;
175: }
176:
177: /**
178: * Request identifier - must be unique
179: *
180: * @return string
181: */
182: public function getOrderID()
183: {
184: return $this->orderID;
185: }
186:
187: /**
188: * Identifier of the client’s (debtor’s) myPOS account
189: *
190: * @return string
191: */
192: public function getCustomerWalletNumber()
193: {
194: return $this->customerWalletNumber;
195: }
196:
197: /**
198: * The reason for the transfer.
199: *
200: * @return string
201: */
202: public function getReason()
203: {
204: return $this->reason;
205: }
206:
207: }