*/ /** * Klasa stPrzelewy24BackendActions * * @package stPrzelewy24Plugin * @subpackage actions */ class stPrzelewy24BackendActions extends autoStPrzelewy24BackendActions { public function executeConfig() { $result = parent::executeConfig(); if (!$this->config->get('enabled')) { $i18n = $this->getContext()->getI18n(); $this->setFlash('info', ''.$i18n->__('Zarejestruj się w Przelewy24, aby utworzyć konto.').''); } return $result; } protected function loadConfigOrCreate() { $config = parent::loadConfigOrCreate(); if ($this->getRequest()->getMethod() != sfRequest::POST) { $this->hideFields($config); } return $config; } protected function updateConfigFromRequest() { if ($this->getRequest()->getMethod() == sfRequest::POST) { parent::updateConfigFromRequest(); $data = $this->getRequestParameter('config'); if (!isset($data['highlighted_for_product'])) { $this->config->set('highlighted_for_product', []); } if (!isset($data['highlighted_for_basket'])) { $this->config->set('highlighted_for_basket', []); } } $this->hideFields($this->config); } protected function saveConfig() { $this->config->set('has_valid_configuration', true); parent::saveConfig(); $api = new stPrzelewy24(); $paymentTypes = $api->getBasketPaymentTypes(true); $paymentMethods = $api->getPaymentMethods(); if ($paymentMethods) { if ($this->hasRequestParameter('fake_paypo')) { $paymentMethods[227] = new stdClass(); $paymentMethods[227]->status = true; } foreach (stPrzelewy24::HIGHLIGHTED as $type => $current) { $id = $current['id']; if (!isset($paymentTypes[$type])) { $paymentType = new PaymentType(); $paymentType->setCulture(stLanguage::getOptLanguage()); $paymentType->setName($current['name']); $paymentType->setHideForDeliveryConfiguration(true); $paymentType->setModuleName('stPrzelewy24'); if (isset($id)) { $paymentType->setConfigurationParameter('payment_channel', $id); } $paymentType->setConfigurationParameter('type', $type); $paymentTypes[$type] = $paymentType; } $paymentTypes[$type]->setActive($this->config->get('enabled') && isset($paymentMethods[$id]) && $paymentMethods[$id]->status && in_array($type, $this->config->get('highlighted_for_basket', []))); } } if (!isset($paymentTypes['default'])) { $paymentType = new PaymentType(); $paymentType->setCulture(stLanguage::getOptLanguage()); $paymentType->setName('Przelewy24'); $paymentType->setModuleName('stPrzelewy24'); $paymentTypes['default'] = $paymentType; } $paymentTypes['default']->setActive($this->config->get('enabled')); foreach ($paymentTypes as $paymentType) { $paymentType->save(); } stNotification::getInstance()->markAllAsRead('stPrzelewy24Plugin'); } protected function getConfigLabels() { $i18n = $this->getContext()->getI18n(); $labels = parent::getConfigLabels(); $labels['api'] = 'Przelewy24'; return $labels; } public function validateConfig() { stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName()); $i18n = $this->getContext()->getI18N(); $request = $this->getRequest(); if ($request->getMethod() == sfRequest::POST) { $data = $this->getRequestParameter('config'); if (!isset($data['enabled'])) { return true; } if (!$data['przelewy24_id']) { $request->setError('config{przelewy24_id}', $i18n->__('Uzupełnij pole')); } if (!$data['salt']) { $request->setError('config{salt}', $i18n->__('Uzupełnij pole')); } if (!$data['report_key'] && $data['payment_channels_enabled']) { $request->setError('config{report_key}', $i18n->__('Uzupełnij pole')); } if (!$request->hasErrors()) { $api = new stPrzelewy24($data['przelewy24_id'], $data['salt'], $data['report_key'], isset($data['test']) && $data['test']); try { $api->testConnection(); } catch(stPrzelewyException $e) { $error = $i18n->__($e->getMessage()); $request->setError('api', $i18n->__('Wystąpił problem z połączeniem sprawdź czy wprowadzone dane są prawidłowe (Zwrócony błąd: "%error%")', array( '%error%' => $error ))); } } } elseif (stConfig::getInstance('stPrzelewy24Backend')->get('enabled')) { $api = new stPrzelewy24(); try { $api->testConnection(); } catch(stPrzelewyException $e) { $error = $i18n->__($e->getMessage()); $request->setError('api', $i18n->__('Wystąpił problem z połączeniem sprawdź czy wprowadzone dane są prawidłowe (Zwrócony błąd: "%error%")', array( '%error%' => $error ))); } } return !$request->hasErrors(); } protected function hideFields(stConfig $config) { if (!$config->get('payment_channels_enabled')) { $this->hideField('report_key'); $this->hideField('channels'); $this->hideField('highlighted_for_product'); $this->hideField('highlighted_for_basket'); } } }