_getDataObj()->setFilter('vendorId', $this->_doc->getAuthData('vendorId')); $obj = $this->_getDataObj(); if (!($id = $this->_restAlias) || !($taxation = $obj->setPrimaryKey($id)->getData())) { $this->_doc->displayError('Invalid Taxation ID'); return $this; } $this->_initAction(); if ($this->step != self::STEP_FINAL && !empty($taxation['transactionId'])) { $this->_setBackUrl(View::getPage('url')); $paymentMethodTitle = $this->getConfigArray('paymentMethods')[$taxation['paymentMethod']]; $this->_setBackError( 'Taxation Invoice #' . $taxation['id'] . ' is already paid by ' . $paymentMethodTitle . '. ' . 'Transaction ID = ' . $taxation['transactionId'] ); $this->_doBack(); } $result = $this->_callAction(); $placeholders = [ 'stepProgress' => $this->renderProgressBar(), 'stepTitleBar' => $this->renderStepTitle(), ]; if (is_string($result)) { $placeholders['stepContent'] = $result; } elseif (is_array($result)) { $placeholders = array_merge($placeholders, $result); } else { throw new Exception('Unsupported action result'); } $this->_doc->setModulePlaceholders($this->getOption('type'), $placeholders); return $this; } protected function _initAction() { $this->step = $this->_action = $this->_doc->getOption('xStep'); return parent::_initAction(); } protected function _doPayment() { $form = $this->getPaymentForm(); if (Qs_Request::isPost()) { if ($form->validate()) { $this->saveStepData($this->step, $form->getValues()); $url = self::getStepUrl(self::STEP_VERIFICATION) . '/' . $this->_restAlias; $this->redirect($url); } } else { $form->setDefaults($this->getStepData()); } return $form->render(); } protected function getPaymentForm() { $options = [ 'bankApiUrl' => BankApiView::getPage('fullAlias'), 'userId' => $this->_doc->getAuthData('id'), 'attribs' => array('class' => 'stepPayment'), ]; $form = new PaymentForm($options); return $form; } protected function getVerificationForm() { $options = []; $options['payment'] = $this->getStepData(self::STEP_PAYMENT); $options['payment']['summary']['total'] = $this->_getDataObj()->getData('total'); $options['cancelUrl'] = self::getStepUrl(self::STEP_PAYMENT) . '/' . $this->_restAlias; $form = new VerificationForm($options); return $form; } protected function _doPaymentAjax() { $form = $this->getPaymentForm(); $response = $form->validateAjax(); $this->_displayJson($response); } protected function _doVerificationAjax() { $form = $this->getVerificationForm(); $response = $form->validateAjax(); $this->_displayJson($response); } protected function _doVerification() { $form = $this->getVerificationForm(); if (Qs_Request::isPost() && $form->validate()) { Qs_Db::getInstance()->beginTransaction(); try { $taxationId = $this->_restAlias; $payment = $this->getStepData(self::STEP_PAYMENT); $payment['total'] = $this->_getDataObj()->getData('total'); $user = $this->_doc->getAuthData(); $vendor = $this->_getDataObj()->getVendorModel()->get($user['vendorId']); $payment['transactionId'] = $this->processPayment('Tax. #' . $taxationId, $payment, $user, $vendor); $payment['transactionTime'] = date('Y-m-d H:i:s'); $payment['ip'] = Qs_Request::getClientIP(); $payment['status'] = Entity::STATUS_PAID; $this->maskPaymentData($payment); $this->_getDataObj()->updatePayment($payment, $taxationId); Qs_Db::getInstance()->commit(); Mail::sendTaxationInvoicePaidToUser($taxationId); Mail::sendTaxationInvoicePaidToAdmin($taxationId); $this->clearSession(); $url = self::getStepUrl(self::STEP_FINAL) . '/' . $this->_restAlias; $this->redirect($url); } catch (IntegrityPaymentException $e) { $this->_setBackUrl(self::getStepUrl(self::STEP_PAYMENT) . '/' . $this->_restAlias); $this->_setBackError($e->getMessage()); } catch (SpsException $e) { $this->_setBackUrl(self::getStepUrl(self::STEP_PAYMENT) . '/' . $this->_restAlias); $this->_setBackError('SPS Error: ' . $e->getMessage()); } Qs_Db::getInstance()->rollBack(); $this->_doBack(); } Qs_View::getInstance()->addHelperPath('App/License/View/Helper/', 'App\License\View\Helper\\'); $item = $this->_getDataObj()->getData(); $item['vendor'] = $this->_getDataObj()->getVendorModel()->get($this->_doc->getAuthData('vendorId')); $item['tpl'] = $this->getTemplate('verification.tpl'); return $this->_doc->fetchItem($item) . $form->render(); } protected function _getDataObjClass() { return Obj::class; } public static function getStepUrl($step) { return self::getStepPage($step, 'url'); } public static function getStepPage($step, $field = null) { if (false === ($page = Qs_SiteMap::findFirst(['xStep' => $step], ['type' => 'Taxation\\User\\Pay']))) { throw new Exception('Can not find "' . $step . '" step url'); } return Qs_Array::get($page, $field); } protected function getSteps() { if (null === $this->steps) { $this->getTraitSteps(); $disabledSteps = []; if ($this->_action == self::STEP_FINAL) { $disabledSteps = [self::STEP_PAYMENT, self::STEP_VERIFICATION, self::STEP_FINAL]; } foreach ($this->steps as $index => &$step) { $step['enabled'] = !in_array($step['name'], $disabledSteps); $step['title'] = self::getStepPage($step['name'], 'menuTitle'); $step['url'] .= '/' . $this->_restAlias; } } return $this->steps; } protected function renderStepTitle() { $step = $this->getCurrentStep(); $item = [ 'currentStep' => $step, 'currentStepTitle' => $step['title'], 'stepsCount' => count($this->getSteps()), 'tpl' => $this->getTemplate('step-title-bar.tpl'), ]; return $this->_doc->fetchItem($item); } protected function _doFinal() { return [ 'id' => $this->_restAlias ]; } }