first commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
class stEserviceBackendActions extends stActions
|
||||
{
|
||||
|
||||
public function initializeParameters()
|
||||
{
|
||||
$this->config = stConfig::getInstance('stEserviceBackend');
|
||||
|
||||
$this->labels = $this->getLabels();
|
||||
}
|
||||
|
||||
public function executeIndex()
|
||||
{
|
||||
$this->initializeParameters();
|
||||
|
||||
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
||||
{
|
||||
$this->config->setFromRequest('config');
|
||||
$this->config->save();
|
||||
|
||||
$modules = PaymentTypePeer::doSelectByModuleName('stEservice');
|
||||
|
||||
if (!$modules)
|
||||
{
|
||||
$modules = PaymentTypePeer::doSelectByModuleName('stEservice2');
|
||||
}
|
||||
|
||||
/**
|
||||
* @var PaymentType $module
|
||||
*/
|
||||
foreach ($modules as $module)
|
||||
{
|
||||
$module->setModuleName('stEservice');
|
||||
$module->setIsActive($this->config->get('enabled'));
|
||||
$module->save();
|
||||
}
|
||||
|
||||
if ($this->config->get('enabled'))
|
||||
{
|
||||
$config = stConfig::getInstance('stEservice2Backend');
|
||||
$config->set('enabled', false);
|
||||
$config->save();
|
||||
}
|
||||
|
||||
$this->setFlash('notice', $this->getContext()->getI18n()->__('Twoje zmiany zostały zapisane', null, 'stAdminGeneratorPlugin'));
|
||||
}
|
||||
$this->labels = $this->getLabels();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function validateIndex()
|
||||
{
|
||||
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
||||
{
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName());
|
||||
|
||||
$data = $this->getRequestParameter('config');
|
||||
|
||||
if (isset($data['enabled']))
|
||||
{
|
||||
$postParameters = array(
|
||||
'ClientId' => $data['client_id'],
|
||||
'Password' => $data['password'],
|
||||
'OrderId' => uniqid(),
|
||||
'Total' => 500,
|
||||
'Currency' => 'PLN',
|
||||
);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, isset($data['test']) ? stEservice::TOKEN_URL_TEST : stEservice::TOKEN_URL_PROD);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postParameters, '', '&'));
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if ($response)
|
||||
{
|
||||
parse_str($response, $result);
|
||||
|
||||
if (strtolower($result['status']) != 'ok')
|
||||
{
|
||||
if ($result['msg'] == 'merchant-invalid')
|
||||
{
|
||||
$this->getRequest()->setError('{eService}', $i18n->__('Podane dane są nieprawidłowe'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->getRequest()->setError('{eService}', $i18n->__('Wystąpił problem podczas próby weryfikacji danych (zwrócony błąd: "%msg%")', array('%msg%' => $result['msg'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->getRequest()->setError('{eService}', $i18n->__('Wystąpił nieznany problem podczas weryfikacji danych'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->getRequest()->hasErrors();
|
||||
}
|
||||
|
||||
/*public function handleErrorIndex()
|
||||
{
|
||||
$this->initializeParameters();
|
||||
return sfView::SUCCESS;
|
||||
}*/
|
||||
|
||||
public function handleErrorIndex()
|
||||
{
|
||||
|
||||
$this->initializeParameters();
|
||||
$this->config = stConfig::getInstance('stEserviceBackend');
|
||||
return sfView::SUCCESS;
|
||||
}
|
||||
|
||||
protected function getLabels()
|
||||
{
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
return array('config{client_id}' => $i18n->__('Numer sprzedawcy'),'config{password}' => $i18n->__('Hasło sprzedawcy'),'config{store_key}' => $i18n->__('Klucz sklepu'),'{eService}' => 'eService');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class stEserviceBackendComponents extends sfComponents
|
||||
{
|
||||
|
||||
public function executeListMenu()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,19 @@
|
||||
<div class="list-menu">
|
||||
<ul>
|
||||
|
||||
<li class="selected">
|
||||
<?php echo link_to(__('eService'),'stEserviceBackend/index')?>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<?php if (sfContext::getInstance()->getUser()->getCulture() == 'pl_PL'): ?>
|
||||
<a href="https://www.sote.pl/docs/eservice" target="_blank"><?php echo __('Dokumentacja'); ?></a>
|
||||
<?php else: ?>
|
||||
<a href="https://www.soteshop.com/docs/eservice" target="_blank"><?php echo __('Documentation'); ?></a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="clr"></div>
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php use_helper('I18N', 'stAdminGenerator', 'Validation');?>
|
||||
<?php echo st_get_admin_head('stEservicePlugin', __('eService', array()), __('',array()),array('stPayment')); ?>
|
||||
<?php st_view_slot_start('application-menu') ?>
|
||||
<?php st_include_component('stEserviceBackend', 'listMenu') ?>
|
||||
<?php st_view_slot_end() ?>
|
||||
<?php st_include_partial('stAdminGenerator/message', array('labels' => $labels, 'i18n_catalogue' => 'stEserviceBackend')); ?>
|
||||
<?php echo form_tag('eservice/index', array('id' => 'sf_admin_config_form', 'name' => 'sf_admin_config_form', 'class' => 'admin_form'));?>
|
||||
<fieldset>
|
||||
<div class="content">
|
||||
<div class="form-row <?php if($sf_request->hasError('config{client_id}')):?> form-error<?php endif;?>">
|
||||
<label for="config_client_id" class="required"><?php echo __('Numer sprzedawcy') ?></label>
|
||||
<div class="field">
|
||||
<?php if($sf_request->hasErrors()):?>
|
||||
<div class="form-error-msg">
|
||||
<div class="form_error" id="error_for_client_id"> ↓ <?php echo $sf_request->getError('config{client_id}') ?> ↓</div>
|
||||
</div>
|
||||
<?php echo input_tag('config[client_id]', $sf_params->get('config[client_id]'), array('size' => '50'));?>
|
||||
<?php else:?>
|
||||
<?php echo input_tag('config[client_id]', $config->get('client_id'), array('size' => '50'));?>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<div class="form-row <?php if($sf_request->hasError('config{password}')):?> form-error<?php endif;?>">
|
||||
<label for="config_password" class="required"><?php echo __('Hasło sprzedawcy') ?></label>
|
||||
<div class="field">
|
||||
<?php if($sf_request->hasErrors()):?>
|
||||
<div class="form-error-msg">
|
||||
<div class="form_error" id="error_for_password"> ↓ <?php echo $sf_request->getError('config{password}') ?> ↓</div>
|
||||
</div>
|
||||
<?php echo input_password_tag('config[password]', $sf_params->get('config[password]'), array('size' => '50'));?>
|
||||
<?php else:?>
|
||||
<?php echo input_password_tag('config[password]', $config->get('password'), array('size' => '50'));?>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<div class="form-row <?php if($sf_request->hasError('config{store_key}')):?> form-error<?php endif;?>">
|
||||
<label for="config_store_key" class="required" ><?php echo __('Klucz sklepu') ?></label>
|
||||
<div class="field">
|
||||
<?php if($sf_request->hasErrors()):?>
|
||||
<div class="form-error-msg">
|
||||
<div class="form_error" id="error_for_store_key"> ↓ <?php echo $sf_request->getError('config{store_key}') ?> ↓</div>
|
||||
</div>
|
||||
<?php echo input_password_tag('config[store_key]', $sf_params->get('config[store_key]'), array('size' => '50'));?>
|
||||
<?php else:?>
|
||||
<?php echo input_password_tag('config[store_key]', $config->get('store_key'), array('size' => '50'));?>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<?php if (SF_ENVIRONMENT == 'dev' || $sf_request->hasParameter('debug')): ?>
|
||||
<div class="form-row">
|
||||
<label for="config_test"><?php echo __('Aktywuj tryb testowy') ?></label>
|
||||
<div class="field">
|
||||
<?php if($sf_request->hasErrors()):?>
|
||||
<?php echo st_admin_checkbox_tag('config[test]', true, $sf_params->get('config[test]'));?>
|
||||
<?php else:?>
|
||||
<?php echo st_admin_checkbox_tag('config[test]', true, $config->get('test'));?>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php echo st_get_admin_actions(array(
|
||||
array('type' => 'save', 'label' => __('Zapisz', null, 'stAdminGeneratorPlugin'))
|
||||
)) ?>
|
||||
</form>
|
||||
<div class="clr"></div>
|
||||
<?php echo st_get_admin_foot();?>
|
||||
@@ -0,0 +1,10 @@
|
||||
fields:
|
||||
config{client_id}:
|
||||
required:
|
||||
msg: Proszę uzupełnić pole.
|
||||
config{password}:
|
||||
required:
|
||||
msg: Proszę uzupełnić pole.
|
||||
config{store_key}:
|
||||
required:
|
||||
msg: Proszę uzupełnić pole.
|
||||
Reference in New Issue
Block a user