/** * @return mixed an HTTP response, or */ public function configure() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, 'Payzen', AccessManager::UPDATE))) { return $response; } // Initialize the potential error message, and the potential exception $error_msg = $ex = null; // Create the Form from the request $configurationForm = new ConfigurationForm($this->getRequest()); try { // Check the form against constraints violations $form = $this->validateForm($configurationForm, "POST"); // Get the form field values $data = $form->getData(); foreach ($data as $name => $value) { if (is_array($value)) { $value = implode(';', $value); } PayzenConfigQuery::set($name, $value); } // Log configuration modification $this->adminLogAppend("payzen.configuration.message", AccessManager::UPDATE, sprintf("Payzen configuration updated")); // Redirect to the success URL, if ($this->getRequest()->get('save_mode') == 'stay') { // If we have to stay on the same page, redisplay the configuration page/ $route = '/admin/module/Payzen'; } else { // If we have to close the page, go back to the module back-office page. $route = '/admin/modules'; } $this->redirect(URL::getInstance()->absoluteUrl($route)); // An exit is performed after redirect.+ } catch (FormValidationException $ex) { // Form cannot be validated. Create the error message using // the BaseAdminController helper method. $error_msg = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error $error_msg = $ex->getMessage(); } // At this point, the form has errors, and should be redisplayed. We don not redirect, // just redisplay the same template. // Setup the Form error context, to make error information available in the template. $this->setupFormErrorContext($this->getTranslator()->trans("Payzen configuration", [], Payzen::MODULE_DOMAIN), $error_msg, $configurationForm, $ex); // Do not redirect at this point, or the error context will be lost. // Just redisplay the current template. return $this->render('module-configure', array('module_code' => 'Payzen')); }
/** * Returns the vads transaction id, that should be unique during the current day, * and should be 6 numeric characters between 000000 and 899999 * * @return string the transaction ID * @throws \Exception an exception if something goes wrong. */ protected function getTransactionId() { $con = Propel::getWriteConnection(PayzenConfigTableMap::DATABASE_NAME); $con->beginTransaction(); try { $trans_id = intval(PayzenConfigQuery::read('next_transaction_id', 1)); $next_trans_id = 1 + $trans_id; if ($next_trans_id > 899999) { $next_trans_id = 0; } PayzenConfigQuery::set('next_transaction_id', $next_trans_id); $con->commit(); return sprintf("%06d", $trans_id); } catch (\Exception $ex) { $con->rollback(); throw $ex; } }