. */ /* */ /*************************************************************************************/ namespace PayPal\Controller; use PayPal\Form\ConfigurationForm; use PayPal\PayPal; use Symfony\Component\HttpFoundation\RequestStack; use Thelia\Controller\Admin\BaseAdminController; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; use Thelia\Form\Exception\FormValidationException; use Thelia\Tools\URL; use Thelia\Tools\Version\Version; use Symfony\Component\Routing\Annotation\Route; /** * @Route("/admin/module/paypal/configure", name="paypal_configure") * Class ConfigurePaypal * @package Paypal\Controller */ class ConfigurationController extends BaseAdminController { /* * Checks paypal.configure || paypal.configure.sandbox form and save config into json file */ /** * @return mixed|\Symfony\Component\HttpFoundation\Response|\Thelia\Core\HttpFoundation\Response * @Route("", name="_save", methods="POSt") */ public function configureAction(RequestStack $requestStack, Translator $translator) { if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'Paypal', AccessManager::UPDATE)) { return $response; } $configurationForm = $this->createForm(ConfigurationForm::getName()); try { $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); } Paypal::setConfigValue($name, $value); } $this->adminLogAppend( "paypal.configuration.message", AccessManager::UPDATE, sprintf("Paypal configuration updated") ); if ($requestStack->getCurrentRequest()->get('save_mode') === 'stay') { // If we have to stay on the same page, redisplay the configuration page/ $url = '/admin/module/Paypal'; } else { // If we have to close the page, go back to the module back-office page. $url = '/admin/modules'; } return $this->generateRedirect(URL::getInstance()->absoluteUrl($url)); } catch (FormValidationException $ex) { $error_msg = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { $error_msg = $ex->getMessage(); } $this->setupFormErrorContext( $translator->trans("Paypal configuration", [], PayPal::DOMAIN_NAME), $error_msg, $configurationForm, $ex ); // Before 2.2, the errored form is not stored in session if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) { return $this->render('module-configure', [ 'module_code' => PayPal::getModuleCode()]); } else { return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/PayPal')); } } /** * @return \Thelia\Core\HttpFoundation\Response * @Route("/log", name="_log", methods="GET") */ public function logAction() { return $this->render('paypal/paypal-log'); } }