1 <?php
2
3 namespace Mypos\IPC;
4
5 6 7 8
9 class Reversal extends Base
10 {
11 private $trnref;
12
13 14 15 16
17 public function __construct(Config $cnf)
18 {
19 $this->setCnf($cnf);
20 }
21
22 23 24 25 26
27 public function setTrnref($trnref)
28 {
29 $this->trnref = $trnref;
30 return $this;
31 }
32
33 34 35 36
37 public function getTrnref()
38 {
39 return $this->trnref;
40 }
41
42 43 44 45
46 public function process()
47 {
48 $this->validate();
49
50 $this->_addPostParam('IPCmethod', 'IPCReversal');
51 $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
52 $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
53 $this->_addPostParam('SID', $this->getCnf()->getSid());
54 $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
55 $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
56 $this->_addPostParam('Source', Defines::SOURCE_PARAM);
57 $this->_addPostParam('IPC_Trnref', $this->getTrnref());
58 $this->_addPostParam('OutputFormat', $this->getOutputFormat());
59
60 return $this->_processPost();
61 }
62
63 64 65 66 67
68 public function validate()
69 {
70 try {
71 $this->getCnf()->validate();
72 } catch (\Exception $ex) {
73 throw new IPC_Exception('Invalid Config details: ' . $ex->getMessage());
74 }
75
76 if ($this->getTrnref() == null || !Helper::isValidTrnRef($this->getTrnref())) {
77 throw new IPC_Exception('Invalid TrnRef');
78 }
79
80 if ($this->getOutputFormat() == null || !Helper::isValidOutputFormat($this->getOutputFormat())) {
81 throw new IPC_Exception('Invalid Output format');
82 }
83
84 return true;
85 }
86 }