| 1: | <?php
|
| 2: |
|
| 3: | namespace Mypos\IPC;
|
| 4: |
|
| 5: | |
| 6: | |
| 7: | |
| 8: |
|
| 9: | class Refund extends Base
|
| 10: | {
|
| 11: | private $currency = 'EUR', $amount, $trnref, $orderID;
|
| 12: |
|
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: |
|
| 18: | public function __construct(Config $cnf)
|
| 19: | {
|
| 20: | $this->setCnf($cnf);
|
| 21: | }
|
| 22: |
|
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: |
|
| 28: | public function setAmount($amount)
|
| 29: | {
|
| 30: | $this->amount = $amount;
|
| 31: | }
|
| 32: |
|
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: |
|
| 40: | public function setTrnref($trnref)
|
| 41: | {
|
| 42: | $this->trnref = $trnref;
|
| 43: |
|
| 44: | return $this;
|
| 45: | }
|
| 46: |
|
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: |
|
| 54: | public function setOrderID($orderID)
|
| 55: | {
|
| 56: | $this->orderID = $orderID;
|
| 57: |
|
| 58: | return $this;
|
| 59: | }
|
| 60: |
|
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: |
|
| 67: | public function process()
|
| 68: | {
|
| 69: | $this->validate();
|
| 70: |
|
| 71: | $this->_addPostParam('IPCmethod', 'IPCRefund');
|
| 72: | $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
|
| 73: | $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
|
| 74: | $this->_addPostParam('SID', $this->getCnf()->getSid());
|
| 75: | $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
|
| 76: | $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
|
| 77: | $this->_addPostParam('Source', $this->getCnf()->getSource());
|
| 78: |
|
| 79: | $this->_addPostParam('Currency', $this->getCurrency());
|
| 80: | $this->_addPostParam('Amount', $this->getAmount());
|
| 81: |
|
| 82: | $this->_addPostParam('OrderID', $this->getOrderID());
|
| 83: | $this->_addPostParam('IPC_Trnref', $this->getTrnref());
|
| 84: | $this->_addPostParam('OutputFormat', $this->getOutputFormat());
|
| 85: |
|
| 86: | $this->_addPostParam('ApplicationID', $this->getCnf()->getApplicationID());
|
| 87: | $this->_addPostParam('PartnerID', $this->getCnf()->getPartnerID());
|
| 88: |
|
| 89: | $response = $this->_processPost()->getData(CASE_LOWER);
|
| 90: | if (empty($response['ipc_trnref']) || (empty($response['amount']) || $response['amount'] != $this->getAmount()) || (empty($response['currency']) || $response['currency'] != $this->getCurrency()) || $response['status'] != Defines::STATUS_SUCCESS) {
|
| 91: | return false;
|
| 92: | }
|
| 93: |
|
| 94: | return true;
|
| 95: | }
|
| 96: |
|
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: |
|
| 103: | public function validate()
|
| 104: | {
|
| 105: | try {
|
| 106: | $this->getCnf()->validate();
|
| 107: | } catch (\Exception $ex) {
|
| 108: | throw new IPC_Exception('Invalid Config details: '.$ex->getMessage());
|
| 109: | }
|
| 110: |
|
| 111: | if ($this->getAmount() == null || !Helper::isValidAmount($this->getAmount())) {
|
| 112: | throw new IPC_Exception('Invalid Amount');
|
| 113: | }
|
| 114: |
|
| 115: | if ($this->getCurrency() == null) {
|
| 116: | throw new IPC_Exception('Invalid Currency');
|
| 117: | }
|
| 118: |
|
| 119: | if ($this->getTrnref() == null || !Helper::isValidTrnRef($this->getTrnref())) {
|
| 120: | throw new IPC_Exception('Invalid TrnRef');
|
| 121: | }
|
| 122: |
|
| 123: | if ($this->getOrderID() == null || !Helper::isValidOrderId($this->getOrderID())) {
|
| 124: | throw new IPC_Exception('Invalid OrderId');
|
| 125: | }
|
| 126: |
|
| 127: | if ($this->getOutputFormat() == null || !Helper::isValidOutputFormat($this->getOutputFormat())) {
|
| 128: | throw new IPC_Exception('Invalid Output format');
|
| 129: | }
|
| 130: |
|
| 131: | if ($this->getCnf()->getVersion() === '1.4.1') {
|
| 132: | if ($this->getCnf()->getPartnerID() == null) {
|
| 133: | throw new IPC_Exception('Required parameter: Partner ID');
|
| 134: | }
|
| 135: |
|
| 136: | if ($this->getCnf()->getApplicationID() == null) {
|
| 137: | throw new IPC_Exception('Required parameter: Application ID');
|
| 138: | }
|
| 139: | }
|
| 140: |
|
| 141: | return true;
|
| 142: | }
|
| 143: |
|
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: |
|
| 149: | public function getAmount()
|
| 150: | {
|
| 151: | return $this->amount;
|
| 152: | }
|
| 153: |
|
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: |
|
| 159: | public function getCurrency()
|
| 160: | {
|
| 161: | return $this->currency;
|
| 162: | }
|
| 163: |
|
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: |
|
| 171: | public function setCurrency($currency)
|
| 172: | {
|
| 173: | $this->currency = $currency;
|
| 174: |
|
| 175: | return $this;
|
| 176: | }
|
| 177: |
|
| 178: | |
| 179: | |
| 180: | |
| 181: | |
| 182: |
|
| 183: | public function getTrnref()
|
| 184: | {
|
| 185: | return $this->trnref;
|
| 186: | }
|
| 187: |
|
| 188: | |
| 189: | |
| 190: | |
| 191: | |
| 192: |
|
| 193: | public function getOrderID()
|
| 194: | {
|
| 195: | return $this->orderID;
|
| 196: | }
|
| 197: |
|
| 198: | } |