1: <?php
2:
3: namespace Mypos\IPC;
4:
5: /**
6: * Process IPC method: IPCReversal.
7: * Collect, validate and send API params
8: */
9: class Reversal extends Base
10: {
11: private $trnref;
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: * Initiate API request
25: *
26: * @return Response
27: * @throws IPC_Exception
28: */
29: public function process()
30: {
31: $this->validate();
32:
33: $this->_addPostParam('IPCmethod', 'IPCReversal');
34: $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
35: $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
36: $this->_addPostParam('SID', $this->getCnf()->getSid());
37: $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
38: $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
39: $this->_addPostParam('Source', $this->getCnf()->getSource());
40: $this->_addPostParam('IPC_Trnref', $this->getTrnref());
41: $this->_addPostParam('OutputFormat', $this->getOutputFormat());
42: $this->_addPostParam('ApplicationID', $this->getCnf()->getApplicationID());
43: $this->_addPostParam('PartnerID', $this->getCnf()->getPartnerID());
44:
45: return $this->_processPost();
46: }
47:
48: /**
49: * Validate all set refund details
50: *
51: * @return boolean
52: * @throws IPC_Exception
53: */
54: public function validate()
55: {
56: try {
57: $this->getCnf()->validate();
58: } catch (\Exception $ex) {
59: throw new IPC_Exception('Invalid Config details: '.$ex->getMessage());
60: }
61:
62: if ($this->getTrnref() == null || !Helper::isValidTrnRef($this->getTrnref())) {
63: throw new IPC_Exception('Invalid TrnRef');
64: }
65:
66: if ($this->getOutputFormat() == null || !Helper::isValidOutputFormat($this->getOutputFormat())) {
67: throw new IPC_Exception('Invalid Output format');
68: }
69:
70: if ($this->getCnf()->getVersion() === '1.4.1') {
71: if ($this->getCnf()->getPartnerID() == null) {
72: throw new IPC_Exception('Required parameter: Partner ID');
73: }
74:
75: if ($this->getCnf()->getApplicationID() == null) {
76: throw new IPC_Exception('Required parameter: Application ID');
77: }
78: }
79:
80: return true;
81: }
82:
83: /**
84: * Transaction reference - transaction unique identifier
85: *
86: * @return string
87: */
88: public function getTrnref()
89: {
90: return $this->trnref;
91: }
92:
93: /**
94: * Transaction reference - transaction unique identifier
95: *
96: * @param string $trnref
97: *
98: * @return Reversal
99: */
100: public function setTrnref($trnref)
101: {
102: $this->trnref = $trnref;
103:
104: return $this;
105: }
106:
107: }