| 1: | <?php
|
| 2: |
|
| 3: | namespace Mypos\IPC;
|
| 4: |
|
| 5: | |
| 6: | |
| 7: | |
| 8: |
|
| 9: | class PreAuthorizationCompletion extends Base
|
| 10: | {
|
| 11: | private $currency = 'EUR', $orderID, $amount;
|
| 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: | |
| 29: |
|
| 30: | public function setOrderID($orderID)
|
| 31: | {
|
| 32: | $this->orderID = $orderID;
|
| 33: |
|
| 34: | return $this;
|
| 35: | }
|
| 36: |
|
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: |
|
| 44: | public function setCurrency($currency)
|
| 45: | {
|
| 46: | $this->currency = $currency;
|
| 47: |
|
| 48: | return $this;
|
| 49: | }
|
| 50: |
|
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: |
|
| 58: | public function setAmount($amount)
|
| 59: | {
|
| 60: | $this->amount = $amount;
|
| 61: |
|
| 62: | return $this;
|
| 63: | }
|
| 64: |
|
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: |
|
| 71: | public function process()
|
| 72: | {
|
| 73: | $this->validate();
|
| 74: |
|
| 75: | $this->_addPostParam('IPCmethod', 'IPCPreAuthCompletion');
|
| 76: | $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
|
| 77: | $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
|
| 78: | $this->_addPostParam('SID', $this->getCnf()->getSid());
|
| 79: | $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
|
| 80: | $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
|
| 81: | $this->_addPostParam('Source', $this->getCnf()->getSource());
|
| 82: |
|
| 83: | $this->_addPostParam('OrderID', $this->getOrderID());
|
| 84: |
|
| 85: | $this->_addPostParam('Amount', $this->getAmount());
|
| 86: | $this->_addPostParam('Currency', $this->getCurrency());
|
| 87: |
|
| 88: | $this->_addPostParam('OutputFormat', $this->getOutputFormat());
|
| 89: | $this->_addPostParam('ApplicationID', $this->getCnf()->getApplicationID());
|
| 90: | $this->_addPostParam('PartnerID', $this->getCnf()->getPartnerID());
|
| 91: |
|
| 92: | return $this->_processPost();
|
| 93: | }
|
| 94: |
|
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: | |
| 100: |
|
| 101: | public function validate()
|
| 102: | {
|
| 103: | try {
|
| 104: | $this->getCnf()->validate();
|
| 105: | } catch (\Exception $ex) {
|
| 106: | throw new IPC_Exception('Invalid Config details: ' . $ex->getMessage());
|
| 107: | }
|
| 108: |
|
| 109: | if (!Helper::versionCheck($this->getCnf()->getVersion(), '1.4')) {
|
| 110: | throw new IPC_Exception('IPCVersion ' . $this->getCnf()->getVersion() . ' does not support IPCPreAuthorizationCompletion method. Please use 1.4 or above.');
|
| 111: | }
|
| 112: |
|
| 113: | if ($this->getCurrency() === null) {
|
| 114: | throw new IPC_Exception('Invalid currency');
|
| 115: | }
|
| 116: |
|
| 117: | if ($this->getAmount() === null || !Helper::isValidAmount($this->getAmount())) {
|
| 118: | throw new IPC_Exception('Empty or invalid amount');
|
| 119: | }
|
| 120: |
|
| 121: | if ($this->getCnf()->getVersion() === '1.4.1') {
|
| 122: | if ($this->getCnf()->getPartnerID() == null) {
|
| 123: | throw new IPC_Exception('Required parameter: Partner ID');
|
| 124: | }
|
| 125: |
|
| 126: | if ($this->getCnf()->getApplicationID() == null) {
|
| 127: | throw new IPC_Exception('Required parameter: Application ID');
|
| 128: | }
|
| 129: | }
|
| 130: |
|
| 131: | return true;
|
| 132: | }
|
| 133: |
|
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: |
|
| 139: | public function getCurrency()
|
| 140: | {
|
| 141: | return $this->currency;
|
| 142: | }
|
| 143: |
|
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: |
|
| 149: | public function getOrderID()
|
| 150: | {
|
| 151: | return $this->orderID;
|
| 152: | }
|
| 153: |
|
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: |
|
| 159: | public function getAmount()
|
| 160: | {
|
| 161: | return $this->amount;
|
| 162: | }
|
| 163: |
|
| 164: | }
|
| 165: | |