Overview
  • Namespace
  • Class

Namespaces

  • Mypos
    • IPC

Classes

  • Mypos\IPC\Base
  • Mypos\IPC\Card
  • Mypos\IPC\CardStore
  • Mypos\IPC\Cart
  • Mypos\IPC\Config
  • Mypos\IPC\Customer
  • Mypos\IPC\Defines
  • Mypos\IPC\GetTxnStatus
  • Mypos\IPC\Helper
  • Mypos\IPC\IAPurchase
  • Mypos\IPC\IAStoreCard
  • Mypos\IPC\IAStoredCardUpdate
  • Mypos\IPC\IPCGetTxnLog
  • Mypos\IPC\Loader
  • Mypos\IPC\MandateManagement
  • Mypos\IPC\Purchase
  • Mypos\IPC\Refund
  • Mypos\IPC\RequestMoney
  • Mypos\IPC\Response
  • Mypos\IPC\Reversal

Exceptions

  • Mypos\IPC\IPC_Exception
  1 <?php
  2 
  3 namespace Mypos\IPC;
  4 
  5 /**
  6  * Process IPC method: IPCRefund.
  7  * Collect, validate and send API params
  8  */
  9 class Refund extends Base {
 10     private $currency = 'EUR', $amount, $trnref, $orderID;
 11 
 12     /**
 13      * Return Refund object
 14      * @param Config $cnf
 15      */
 16     public function __construct(Config $cnf) {
 17         $this->setCnf($cnf);
 18     }
 19 
 20     /**
 21      * Refund amount
 22      * @param float $amount
 23      */
 24     public function setAmount($amount) {
 25         $this->amount = $amount;
 26     }
 27 
 28     /**
 29      * Refund amount
 30      * @return float
 31      */
 32     public function getAmount() {
 33         return $this->amount;
 34     }
 35 
 36     /**
 37      * ISO-4217 Three letter currency code
 38      * @param string $currency
 39      * @return Refund
 40      */
 41     public function setCurrency($currency) {
 42         $this->currency = $currency;
 43         return $this;
 44     }
 45 
 46     /**
 47      * ISO-4217 Three letter currency code
 48      * @return string
 49      */
 50     public function getCurrency() {
 51         return $this->currency;
 52     }
 53 
 54     /**
 55      * Transaction reference - transaction unique identifier
 56      * @param string $trnref
 57      * @return Refund
 58      */
 59     public function setTrnref($trnref) {
 60         $this->trnref = $trnref;
 61         return $this;
 62     }
 63 
 64     /**
 65      * Transaction reference - transaction unique identifier
 66      * @return string
 67      */
 68     public function getTrnref() {
 69         return $this->trnref;
 70     }
 71 
 72     /**
 73      * Request identifier - must be unique
 74      * @param string $orderID
 75      * @return Refund
 76      */
 77     public function setOrderID($orderID) {
 78         $this->orderID = $orderID;
 79         return $this;
 80     }
 81 
 82     /**
 83      * Request identifier - must be unique
 84      * @return string
 85      */
 86     public function getOrderID() {
 87         return $this->orderID;
 88     }
 89 
 90     /**
 91      * Initiate API request
 92      * @return boolean
 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      * Validate all set refund details
126      * @return boolean
127      * @throws IPC_Exception
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 }
API documentation generated by ApiGen