| 1: | <?php
|
| 2: |
|
| 3: | namespace Mypos\IPC;
|
| 4: |
|
| 5: | |
| 6: | |
| 7: | |
| 8: |
|
| 9: | class PreAuthorization extends Base
|
| 10: | {
|
| 11: | |
| 12: | |
| 13: |
|
| 14: | private $url_ok, $url_cancel, $url_notify;
|
| 15: | private $currency = 'EUR', $note, $orderID, $itemName, $amount;
|
| 16: |
|
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: |
|
| 22: | public function __construct(Config $cnf)
|
| 23: | {
|
| 24: | $this->setCnf($cnf);
|
| 25: | }
|
| 26: |
|
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: |
|
| 34: | public function setOrderID($orderID)
|
| 35: | {
|
| 36: | $this->orderID = $orderID;
|
| 37: |
|
| 38: | return $this;
|
| 39: | }
|
| 40: |
|
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: |
|
| 46: | public function setItemName($itemName)
|
| 47: | {
|
| 48: | $this->itemName = $itemName;
|
| 49: |
|
| 50: | return $this;
|
| 51: | }
|
| 52: |
|
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: |
|
| 60: | public function setAmount($amount)
|
| 61: | {
|
| 62: | $this->amount = $amount;
|
| 63: |
|
| 64: | return $this;
|
| 65: | }
|
| 66: |
|
| 67: |
|
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: |
|
| 75: | public function setNote($note)
|
| 76: | {
|
| 77: | $this->note = $note;
|
| 78: |
|
| 79: | return $this;
|
| 80: | }
|
| 81: |
|
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: |
|
| 89: | public function setUrlCancel($urlCancel)
|
| 90: | {
|
| 91: | $this->url_cancel = $urlCancel;
|
| 92: |
|
| 93: | return $this;
|
| 94: | }
|
| 95: |
|
| 96: | |
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: |
|
| 103: | public function setUrlNotify($urlNotify)
|
| 104: | {
|
| 105: | $this->url_notify = $urlNotify;
|
| 106: |
|
| 107: | return $this;
|
| 108: | }
|
| 109: |
|
| 110: | |
| 111: | |
| 112: | |
| 113: | |
| 114: | |
| 115: |
|
| 116: | public function process()
|
| 117: | {
|
| 118: | $this->validate();
|
| 119: |
|
| 120: | $this->_addPostParam('IPCmethod', 'IPCPreAuthorization');
|
| 121: | $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
|
| 122: | $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
|
| 123: | $this->_addPostParam('SID', $this->getCnf()->getSid());
|
| 124: | $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
|
| 125: | $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
|
| 126: | $this->_addPostParam('Source', $this->getCnf()->getSource());
|
| 127: |
|
| 128: | $this->_addPostParam('ItemName', $this->getItemName());
|
| 129: |
|
| 130: | $this->_addPostParam('Currency', $this->getCurrency());
|
| 131: | $this->_addPostParam('Amount', $this->getAmount());
|
| 132: |
|
| 133: | $this->_addPostParam('OrderID', $this->getOrderID());
|
| 134: | $this->_addPostParam('URL_OK', $this->getUrlOk());
|
| 135: | $this->_addPostParam('URL_Cancel', $this->getUrlCancel());
|
| 136: | $this->_addPostParam('URL_Notify', $this->getUrlNotify());
|
| 137: |
|
| 138: | $this->_addPostParam('Note', $this->getNote());
|
| 139: |
|
| 140: | $this->_addPostParam('ApplicationID', $this->getCnf()->getApplicationID());
|
| 141: | $this->_addPostParam('PartnerID', $this->getCnf()->getPartnerID());
|
| 142: |
|
| 143: | $this->_processHtmlPost();
|
| 144: |
|
| 145: | return true;
|
| 146: | }
|
| 147: |
|
| 148: | |
| 149: | |
| 150: | |
| 151: | |
| 152: | |
| 153: |
|
| 154: | public function validate()
|
| 155: | {
|
| 156: | if (!Helper::versionCheck($this->getCnf()->getVersion(), '1.4')) {
|
| 157: | throw new IPC_Exception('IPCVersion ' . $this->getCnf()->getVersion() . ' does not support IPCPreAuthorization method. Please use 1.4 or above.');
|
| 158: | }
|
| 159: |
|
| 160: | if ($this->getItemName() === null || !is_string($this->getItemName())) {
|
| 161: | throw new IPC_Exception('Empty or invalid item name.');
|
| 162: | }
|
| 163: |
|
| 164: | if ($this->getUrlCancel() === null || !Helper::isValidURL($this->getUrlCancel())) {
|
| 165: | throw new IPC_Exception('Invalid Cancel URL');
|
| 166: | }
|
| 167: |
|
| 168: | if ($this->getUrlNotify() === null || !Helper::isValidURL($this->getUrlNotify())) {
|
| 169: | throw new IPC_Exception('Invalid Notify URL');
|
| 170: | }
|
| 171: |
|
| 172: | if ($this->getUrlOk() === null || !Helper::isValidURL($this->getUrlOk())) {
|
| 173: | throw new IPC_Exception('Invalid Success URL');
|
| 174: | }
|
| 175: |
|
| 176: | if ($this->getAmount() === null || !Helper::isValidAmount($this->getAmount())) {
|
| 177: | throw new IPC_Exception('Empty or invalid amount');
|
| 178: | }
|
| 179: |
|
| 180: | if ($this->getCurrency() === null) {
|
| 181: | throw new IPC_Exception('Invalid currency');
|
| 182: | }
|
| 183: |
|
| 184: | try {
|
| 185: | $this->getCnf()->validate();
|
| 186: | } catch (\Exception $ex) {
|
| 187: | throw new IPC_Exception('Invalid Config details: ' . $ex->getMessage());
|
| 188: | }
|
| 189: |
|
| 190: | if ($this->getCnf()->getVersion() === '1.4.1') {
|
| 191: | if ($this->getCnf()->getPartnerID() == null) {
|
| 192: | throw new IPC_Exception('Required parameter: Partner ID');
|
| 193: | }
|
| 194: |
|
| 195: | if ($this->getCnf()->getApplicationID() == null) {
|
| 196: | throw new IPC_Exception('Required parameter: Application ID');
|
| 197: | }
|
| 198: | }
|
| 199: |
|
| 200: | return true;
|
| 201: | }
|
| 202: |
|
| 203: | |
| 204: | |
| 205: | |
| 206: | |
| 207: |
|
| 208: | public function getUrlCancel()
|
| 209: | {
|
| 210: | return $this->url_cancel;
|
| 211: | }
|
| 212: |
|
| 213: | |
| 214: | |
| 215: | |
| 216: | |
| 217: |
|
| 218: | public function getUrlNotify()
|
| 219: | {
|
| 220: | return $this->url_notify;
|
| 221: | }
|
| 222: |
|
| 223: | |
| 224: | |
| 225: | |
| 226: | |
| 227: |
|
| 228: | public function getUrlOk()
|
| 229: | {
|
| 230: | return $this->url_ok;
|
| 231: | }
|
| 232: |
|
| 233: | |
| 234: | |
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: |
|
| 240: | public function setUrlOk($urlOk)
|
| 241: | {
|
| 242: | $this->url_ok = $urlOk;
|
| 243: |
|
| 244: | return $this;
|
| 245: | }
|
| 246: |
|
| 247: | |
| 248: | |
| 249: | |
| 250: | |
| 251: |
|
| 252: | public function getCurrency()
|
| 253: | {
|
| 254: | return $this->currency;
|
| 255: | }
|
| 256: |
|
| 257: | |
| 258: | |
| 259: | |
| 260: | |
| 261: | |
| 262: | |
| 263: |
|
| 264: | public function setCurrency($currency)
|
| 265: | {
|
| 266: | $this->currency = $currency;
|
| 267: |
|
| 268: | return $this;
|
| 269: | }
|
| 270: |
|
| 271: |
|
| 272: | |
| 273: | |
| 274: | |
| 275: | |
| 276: |
|
| 277: | public function getOrderID()
|
| 278: | {
|
| 279: | return $this->orderID;
|
| 280: | }
|
| 281: |
|
| 282: | |
| 283: | |
| 284: |
|
| 285: | public function getItemName()
|
| 286: | {
|
| 287: | return $this->itemName;
|
| 288: | }
|
| 289: |
|
| 290: | |
| 291: | |
| 292: | |
| 293: | |
| 294: |
|
| 295: | public function getAmount()
|
| 296: | {
|
| 297: | return $this->amount;
|
| 298: | }
|
| 299: |
|
| 300: | |
| 301: | |
| 302: | |
| 303: | |
| 304: |
|
| 305: | public function getNote()
|
| 306: | {
|
| 307: | return $this->note;
|
| 308: | }
|
| 309: |
|
| 310: | }
|
| 311: | |