first commit
This commit is contained in:
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stPrzelewy24Plugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stPrzelewy24Plugin opartej na licencji (Professional License SOTE).
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stPrzelewy24Plugin
|
||||
* @subpackage actions
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/sote (Professional License SOTE)
|
||||
* @version $Id: actions.class.php 10909 2011-02-09 09:43:43Z pawel $
|
||||
* @author Michal Prochowski <michal.prochowski@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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', '<a target="_parent" href="https://panel.przelewy24.pl//rejestracja.php?a=assign_partner&idp=153178" >'.$i18n->__('Zarejestruj się w Przelewy24, aby utworzyć konto.').'</a>');
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class stPrzelewy24BackendComponents extends autoStPrzelewy24BackendComponents
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
generator:
|
||||
param:
|
||||
model_class: false
|
||||
|
||||
title: "Przelewy24"
|
||||
route: "@stPrzelewy24Plugin"
|
||||
icon: "stPrzelewy24Plugin"
|
||||
|
||||
documentation:
|
||||
pl: "https://www.sote.pl/docs/przelewy24"
|
||||
en: "https://www.soteshop.com/docs/przelewy24"
|
||||
|
||||
config:
|
||||
use_helper: [stPrzelewy24]
|
||||
display:
|
||||
"NONE": [enabled, payment_channels_enabled, test, autoredirect, przelewy24_id, salt, report_key, _channels, highlighted_for_product, highlighted_for_basket]
|
||||
fields:
|
||||
enabled: {name: "Włącz", type: checkbox_tag}
|
||||
payment_channels_enabled: {name: "Włącz wybór kanałów płatności", type: "checkbox_tag"}
|
||||
test: {name: "Tryb testowy", type: checkbox_tag}
|
||||
autoredirect: {name: "Automatyczne przekierowanie", type: checkbox_tag, help: "Przekierowuje automatycznie na stronę płatności po złożeniu zamówienia"}
|
||||
przelewy24_id: {name: "ID sprzedawcy", required: true}
|
||||
salt: {name: "Klucz CRC", required: true, type: input_password_tag}
|
||||
report_key: {name: "Klucz raportów", required: true, type: input_password_tag}
|
||||
channels: {name: "Kanały płatności", type: "select_tag", params: multiple=true}
|
||||
highlighted_for_product: {name: "Wyróżnij płatności na karcie produktu", type: "st_przelewy24_highlighted_payments_select_tag"}
|
||||
highlighted_for_basket: {name: "Wyróżnij płatności w koszyku", type: "st_przelewy24_highlighted_payments_select_tag"}
|
||||
actions:
|
||||
_save: -
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
if ($sf_request->hasParameter('fake_paypo'))
|
||||
{
|
||||
echo input_hidden_tag('fake_paypo', true);
|
||||
}
|
||||
|
||||
echo st_przelewy24_payment_methods_select_tag('config[channels]', $config->get('channels'));
|
||||
?>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php include st_admin_get_template_path(__FILE__) ?>
|
||||
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
$('#config_payment_channels_enabled').change(function() {
|
||||
const fields = $('.row_report_key, .row_channels, .row_highlighted_for_product, .row_highlighted_for_basket');
|
||||
if ($(this).prop('checked')) {
|
||||
fields.removeClass('hidden');
|
||||
} else {
|
||||
fields.addClass('hidden');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php use_helper('I18N', 'stAdminGenerator');?>
|
||||
<?php echo st_get_admin_head('stPrzelewy24Plugin', __('Przelewy24'), '', array('stPayment')); ?>
|
||||
<?php st_view_slot_start('application-menu') ?>
|
||||
<?php st_include_component('stPrzelewy24Backend', 'listMenu') ?>
|
||||
<?php st_view_slot_end() ?>
|
||||
|
||||
<?php st_include_partial('stAdminGenerator/message', array('labels' => $labels));?>
|
||||
|
||||
<?php echo form_tag('przelewy24/index', array('id' => 'sf_admin_config_form', 'class' => 'admin_form'));?>
|
||||
<fieldset>
|
||||
<div class="content">
|
||||
<?php echo st_admin_get_form_field('config[autoredirect]', $labels['config{autoredirect}'], true, 'checkbox_tag', array('checked' => $config->get('autoredirect'), 'help' => __('Przekierowuje automatycznie na stronę płatności po złożeniu zamówienia'))) ?>
|
||||
<?php echo st_admin_get_form_field('config[test]', $labels['config{test}'], true, 'checkbox_tag', array('checked' => $config->get('test'))) ?>
|
||||
<?php echo st_admin_get_form_field('config[przelewy24_id]', $labels['config{przelewy24_id}'], $config->get('przelewy24_id'), 'input_tag', array('required' => true)) ?>
|
||||
<?php echo st_admin_get_form_field('config[salt]', $labels['config{salt}'], $config->get('salt'), 'input_tag', array('required' => true)) ?>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php echo st_get_admin_actions_head('style="margin-top: 10px; float: right"');?>
|
||||
<?php echo st_get_admin_action('save', __('Zapisz', null, 'stAdminGeneratorPlugin'), null, array('name' => 'save'));?>
|
||||
<?php echo st_get_admin_actions_foot();?>
|
||||
</form>
|
||||
<?php echo st_get_admin_foot();?>
|
||||
Reference in New Issue
Block a user