1 <?php
  2 
  3 namespace Mypos\IPC;
  4 
  5   6   7   8 
  9 class Refund extends Base {
 10     private $currency = 'EUR', $amount, $trnref, $orderID;
 11 
 12      13  14  15 
 16     public function __construct(Config $cnf) {
 17         $this->setCnf($cnf);
 18     }
 19 
 20      21  22  23 
 24     public function setAmount($amount) {
 25         $this->amount = $amount;
 26     }
 27 
 28      29  30  31 
 32     public function getAmount() {
 33         return $this->amount;
 34     }
 35 
 36      37  38  39  40 
 41     public function setCurrency($currency) {
 42         $this->currency = $currency;
 43         return $this;
 44     }
 45 
 46      47  48  49 
 50     public function getCurrency() {
 51         return $this->currency;
 52     }
 53 
 54      55  56  57  58 
 59     public function setTrnref($trnref) {
 60         $this->trnref = $trnref;
 61         return $this;
 62     }
 63 
 64      65  66  67 
 68     public function getTrnref() {
 69         return $this->trnref;
 70     }
 71 
 72      73  74  75  76 
 77     public function setOrderID($orderID) {
 78         $this->orderID = $orderID;
 79         return $this;
 80     }
 81 
 82      83  84  85 
 86     public function getOrderID() {
 87         return $this->orderID;
 88     }
 89 
 90      91  92  93 
 94     public function process() {
 95         $this->validate();
 96 
 97         $this->_addPostParam('IPCmethod', 'IPCRefund');
 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', Defines::SOURCE_PARAM);
104         
105         $this->_addPostParam('Currency', $this->getCurrency());
106         $this->_addPostParam('Amount', $this->getAmount());
107 
108         $this->_addPostParam('OrderID', $this->getOrderID());
109         $this->_addPostParam('IPC_Trnref', $this->getTrnref());
110         $this->_addPostParam('OutputFormat', $this->getOutputFormat());
111 
112         $response = $this->_processPost()->getData(CASE_LOWER);
113         if (
114             (empty($response['ipc_trnref']) || $response['ipc_trnref'] != $this->getTrnref()) ||
115             (empty($response['amount']) || $response['amount'] != $this->getAmount()) ||
116             (empty($response['currency']) || $response['currency'] != $this->getCurrency()) ||
117             $response['status'] != \Mypos\IPC\Defines::STATUS_SUCCESS
118         ) {
119             return false;
120         }
121         return true;
122     }
123 
124     125 126 127 128 
129     public function validate() {
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 || !Helper::isValidCurrency($this->getCurrency())) {
141             throw new IPC_Exception('Invalid Currency');
142         }
143 
144         if ($this->getTrnref() == null || !Helper::isValidTrnRef($this->getTrnref())) {
145             throw new IPC_Exception('Invalid TrnRef');
146         }
147 
148         if ($this->getOrderID() == null || !Helper::isValidOrderId($this->getOrderID())) {
149             throw new IPC_Exception('Invalid OrderId');
150         }
151 
152         if ($this->getOutputFormat() == null || !Helper::isValidOutputFormat($this->getOutputFormat())) {
153             throw new IPC_Exception('Invalid Output format');
154         }
155 
156         return true;
157     }
158 }