1: <?php
2:
3: namespace Mypos\IPC;
4:
5: /**
6: * Process IPC method: IPCMandateManagement.
7: * Collect, validate and send API params
8: */
9: class MandateManagement extends Base
10: {
11: const MANDATE_MANAGEMENT_ACTION_REGISTER = 1;
12: const MANDATE_MANAGEMENT_ACTION_CANCEL = 2;
13: private $mandateReference, $customerWalletNumber, $action, $mandateText;
14:
15: /**
16: * Return Refund object
17: *
18: * @param Config $cnf
19: */
20: public function __construct(Config $cnf)
21: {
22: $this->setCnf($cnf);
23: }
24:
25: /**
26: * Identifier of the client’s (debtor’s) myPOS account
27: *
28: * @param string $customerWalletNumber
29: */
30: public function setCustomerWalletNumber($customerWalletNumber)
31: {
32: $this->customerWalletNumber = $customerWalletNumber;
33: }
34:
35: /**
36: * Registration / Cancellation of a MandateReference
37: *
38: * @param int $action
39: */
40: public function setAction($action)
41: {
42: $this->action = $action;
43: }
44:
45: /**
46: * Text supplied from the merchant, so the client can easily identify the Mandate.
47: *
48: * @param string $mandateText
49: */
50: public function setMandateText($mandateText)
51: {
52: $this->mandateText = $mandateText;
53: }
54:
55: /**
56: * Initiate API request
57: *
58: * @return Response
59: * @throws IPC_Exception
60: */
61: public function process()
62: {
63: $this->validate();
64: $this->_addPostParam('IPCmethod', 'IPCMandateManagement');
65: $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
66: $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
67: $this->_addPostParam('SID', $this->getCnf()->getSid());
68: $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
69: $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
70: $this->_addPostParam('Source', $this->getCnf()->getSource());
71: $this->_addPostParam('MandateReference', $this->getMandateReference());
72: $this->_addPostParam('CustomerWalletNumber', $this->getCustomerWalletNumber());
73: $this->_addPostParam('Action', $this->getAction());
74: $this->_addPostParam('MandateText', $this->getMandateText());
75: $this->_addPostParam('OutputFormat', $this->getOutputFormat());
76:
77: $this->_addPostParam('ApplicationID', $this->getCnf()->getApplicationID());
78: $this->_addPostParam('PartnerID', $this->getCnf()->getPartnerID());
79:
80: return $this->_processPost();
81: }
82:
83: /**
84: * Validate all set refund details
85: *
86: * @return boolean
87: * @throws IPC_Exception
88: */
89: public function validate()
90: {
91: try {
92: $this->getCnf()->validate();
93: } catch (\Exception $ex) {
94: throw new IPC_Exception('Invalid Config details: '.$ex->getMessage());
95: }
96:
97: if ($this->getOutputFormat() == null || !Helper::isValidOutputFormat($this->getOutputFormat())) {
98: throw new IPC_Exception('Invalid Output format');
99: }
100:
101: if ($this->getCnf()->getVersion() === '1.4.1') {
102: if ($this->getCnf()->getPartnerID() == null) {
103: throw new IPC_Exception('Required parameter: Partner ID');
104: }
105:
106: if ($this->getCnf()->getApplicationID() == null) {
107: throw new IPC_Exception('Required parameter: Application ID');
108: }
109: }
110:
111: return true;
112: }
113:
114: /**
115: * Unique identifier of the agreement (mandate) between the merchant and the client (debtor). Up to 127 characters.
116: *
117: * @return string
118: */
119: public function getMandateReference()
120: {
121: return $this->mandateReference;
122: }
123:
124: /**
125: * Unique identifier of the agreement (mandate) between the merchant and the client (debtor). Up to 127 characters.
126: *
127: * @param string $mandateReference
128: */
129: public function setMandateReference($mandateReference)
130: {
131: $this->mandateReference = $mandateReference;
132: }
133:
134: /**
135: * Identifier of the client’s (debtor’s) myPOS account
136: *
137: * @return string
138: */
139: public function getCustomerWalletNumber()
140: {
141: return $this->customerWalletNumber;
142: }
143:
144: /**
145: * Registration / Cancellation of a MandateReference
146: *
147: * @return int
148: */
149: public function getAction()
150: {
151: return $this->action;
152: }
153:
154: /**
155: * Text supplied from the merchant, so the client can easily identify the Mandate.
156: *
157: * @return string
158: */
159: public function getMandateText()
160: {
161: return $this->mandateText;
162: }
163:
164: }