first commit

This commit is contained in:
2025-03-12 17:06:23 +01:00
commit 2241f7131f
13185 changed files with 1692479 additions and 0 deletions

View File

@@ -0,0 +1,230 @@
<?php
class stPaypalBackendActions extends stActions
{
protected $paymentConfigurartionVerified = false;
public function executeSave()
{
return $this->forward('stPaypalBackend', 'config');
}
public function executeConfig()
{
$this->config = stConfig::getInstance('stPaypal');
$this->labels = $this->getConfigLabels();
$this->deliveries = DeliveryPeer::doSelect(new Criteria());
if ($this->getRequest()->getMethod() == sfRequest::POST)
{
$this->config->set('configuration_verified', $this->paymentConfigurartionVerified);
$this->updateConfigRequest();
$this->config->save();
$this->setFlash('notice', 'Twoje zmiany zostały zapisane');
$this->redirect('stPaypalBackend/config');
}
}
public function executeAjaxPaypalPendingPayments()
{
$this->setLayout(false);
$this->config = stConfig::getInstance('stPaypal');
$paypal = $this->getPaypalCallerService();
$request = new stPaypalCallerRequest();
$timestamp_end = time();
$timestamp_start = $timestamp_end - 86400 * 7;
$request->setStartDate(date('Y-m-d\TH:i:s\Z', $timestamp_start));
$request->setEndDate(date('Y-m-d\TH:i:s\Z', $timestamp_end));
$request->setTransactionClass('Received');
$request->setStatus('Pending');
$this->paypal_response = $paypal->transactionSearch($request);
}
public function executeAjaxPaypalAccountBalance()
{
$this->setLayout(false);
$this->config = stConfig::getInstance('stPaypal');
$paypal = $this->getPaypalCallerService();
$request = new stPaypalCallerRequest();
$request->setReturnAllCurrencies(true);
$this->paypal_response = $paypal->getBalance($request);
}
protected function getPaypalCallerService()
{
$paypal = stPaypalCallerService::getInstance();
if ($this->config->get('test_mode'))
{
$username = $this->config->get('sandbox_api_username');
$password = $this->config->get('sandbox_api_password');
$signature = $this->config->get('sandbox_api_signature');
$environment = 'sandbox';
}
else
{
$username = $this->config->get('live_api_username');
$password = $this->config->get('live_api_password');
$signature = $this->config->get('live_api_signature');
$environment = 'live';
}
$paypal->initialize($username, $password, $signature, array('environment' => $environment));
return $paypal;
}
protected function updateConfigRequest()
{
$request = $this->getRequestParameter('config');
foreach ($request as $name => $value)
{
$this->config->set($name, trim($value));
}
$this->config->set('enabled', isset($request['enabled']));
$this->config->set('test_mode', isset($request['test_mode']));
$this->config->set('show_shipping_info', isset($request['show_shipping_info']));
$this->config->set('express', isset($request['express']));
}
public function handleErrorConfig()
{
$this->config = stConfig::getInstance('stPaypal');
$this->labels = $this->getConfigLabels();
$this->deliveries = DeliveryPeer::doSelect(new Criteria());
if ($this->getRequest()->getMethod() == sfRequest::POST)
{
$this->updateConfigRequest();
}
return sfView::SUCCESS;
}
public function validateConfig()
{
if ($this->getRequest()->getMethod() == sfRequest::POST)
{
stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName());
$i18n = $this->getContext()->getI18n();
$request = $this->getRequestParameter('config');
if (isset($request['enabled']))
{
if (isset($request['test_mode']))
{
if (empty($request['sandbox_api_username']))
{
$this->getRequest()->setError('config{sandbox_api_username}', 'Musisz podać nazwę użytkownika API');
}
if (empty($request['sandbox_api_password']))
{
$this->getRequest()->setError('config{sandbox_api_password}', 'Musisz podać hasło API');
}
if (empty($request['sandbox_api_signature']))
{
$this->getRequest()->setError('config{sandbox_api_signature}', 'Musisz podać podpis API');
}
}
else
{
if (empty($request['live_api_username']))
{
$this->getRequest()->setError('config{live_api_username}', 'Musisz podać nazwę użytkownika API');
}
if (empty($request['live_api_password']))
{
$this->getRequest()->setError('config{live_api_password}', 'Musisz podać hasło API');
}
if (empty($request['live_api_signature']))
{
$this->getRequest()->setError('config{live_api_signature}', 'Musisz podać podpis API');
}
}
if (!$this->getRequest()->hasErrors())
{
$paypal = stPaypalCallerService::getInstance();
if (isset($request['test_mode']))
{
$paypal->initialize(trim($request['sandbox_api_username']), trim($request['sandbox_api_password']), trim($request['sandbox_api_signature']), array('environment' => 'sandbox'));
}
else
{
$paypal->initialize(trim($request['live_api_username']), trim($request['live_api_password']), trim($request['live_api_signature']));
}
$paypal_response = $paypal->getBalance(new stPaypalCallerRequest());
if ($paypal_response->hasFailed())
{
$errors = array();
foreach ($paypal_response->getItems() as $error)
{
$errors[] = $error->getErrorCode().': '.$error->getLongMessage();
}
$this->getRequest()->setError('send_error', $i18n->__('Weryfikacja dostępu do API zakończyła się niepowodzeniem (%errors%)', array('%errors%' => implode(", ", $errors))));
}
else
{
$this->setFlash('notice', $i18n->__('Weryfikacja dostępu do API zakończona powodzeniem. Twoje zmiany zostały zapisane'));
$this->paymentConfigurartionVerified = true;
}
}
}
}
return !$this->getRequest()->hasErrors();
}
protected function getConfigLabels()
{
$i18n = $this->getContext()->getI18N();
return array(
'config{sandbox_api_username}' => $i18n->__('Nazwa użytkownika API'),
'config{sandbox_api_password}' => $i18n->__('Hasło API'),
'config{sandbox_api_signature}' => $i18n->__('Podpis API'),
'config{live_api_username}' => $i18n->__('Nazwa użytkownika API'),
'config{live_api_password}' => $i18n->__('Hasło API'),
'config{live_api_signature}' => $i18n->__('Podpis API'),
'send_error' => 'Paypal',
);
}
}

View File

@@ -0,0 +1,13 @@
<?php
class stPaypalBackendComponents extends sfComponents
{
public function executeListMenu()
{
}
}
?>

View File

@@ -0,0 +1,24 @@
<?php
use_helper('stAdminGenerator');
function st_paypal_order_link($paypal_txn_id)
{
$c = new Criteria();
$c->addJoin(OrderHasPaymentPeer::PAYMENT_ID, PaymentPeer::ID);
$c->addJoin(OrderHasPaymentPeer::ORDER_ID, OrderPeer::ID);
$c->add(PaymentPeer::HASH, 'PAYPAL-' . $paypal_txn_id);
$order = OrderPeer::doSelectOne($c);
if ($order)
{
return st_external_link_to($order->getNumber(), 'stOrder/edit?id=' . $order->getId());
}
else
{
return '-';
}
}

View File

@@ -0,0 +1,19 @@
<div class="list-menu">
<ul>
<li class="selected">
<?php echo link_to(__('PayPal'),'stPaypalBackend/config')?>
</li>
<li>
<?php if (sfContext::getInstance()->getUser()->getCulture() == 'pl_PL'): ?>
<a href="https://www.sote.pl/docs/paypal" target="_blank"><?php echo __('Dokumentacja'); ?></a>
<?php else: ?>
<a href="https://www.soteshop.com/docs/paypal" target="_blank"><?php echo __('Documentation'); ?></a>
<?php endif; ?>
</li>
</ul>
</div>
<div class="clr"></div>

View File

@@ -0,0 +1,27 @@
<?php use_helper('stPaypal') ?>
<?php if ($paypal_response->isSuccessful()): ?>
<?php $items = $paypal_response->getItems() ?>
<?php if (count($items) > 1): ?>
<table class="st_record_list" cellspacing="0">
<thead>
<tr>
<?php foreach ($items as $balance): ?>
<th><?php echo $balance->getCurrencyCode() ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach ($items as $balance): ?>
<td><?php echo $balance->getAmt() ?></td>
<?php endforeach; ?>
</tr>
</tbody>
</table>
<?php else: ?>
<?php echo $items[0]->getAmt() . ' ' . $items[0]->getCurrencyCode() ?>
<?php endif; ?>
<?php else: ?>
<?php echo __('Wystąpiły problemy podczas próby połączenia z Paypal') ?>
<?php endif; ?>

View File

@@ -0,0 +1,33 @@
<?php use_helper('stPaypal', 'stDate') ?>
<?php if ($paypal_response->isSuccessful() && count($paypal_response->getItems()) > 0): ?>
<table class="st_record_list" cellspacing="0">
<thead>
<tr>
<th><?php echo __('Numer zamówienia') ?></th>
<th><?php echo __('Data płatności') ?></th>
<th><?php echo __('Płacący') ?></th>
<th><?php echo __('Kwota płatności') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($paypal_response->getItems() as $transaction): ?>
<tr>
<td><?php echo st_paypal_order_link($transaction->getTransactionId()) ?></td>
<td><?php echo st_format_date($transaction->getTimestamp(), 'f') ?></td>
<td>
<?php echo $transaction->getName() ?><br />
<?php echo $transaction->getEmail() ?>
</td>
<td><?php echo $transaction->getAmt() ?> <?php echo $transaction->getCurrencyCode() ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php elseif ($paypal_response->isSuccessful()): ?>
<p><?php echo __('Brak oczekujących płatności') ?></p>
<?php else: ?>
<?php echo __('Wystąpiły problemy podczas próby połączenia z Paypal') ?>
<?php endif;

View File

@@ -0,0 +1,189 @@
<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date', 'VisualEffect', 'stAdminGenerator') ?>
<?php echo st_get_admin_head('stPaypalPlugin', __('PayPal'), null,array('stPayment')) ?>
<?php st_view_slot_start('application-menu') ?>
<?php st_include_component('stPaypalBackend', 'listMenu') ?>
<?php st_view_slot_end() ?>
<?php st_include_partial('stAdminGenerator/message', array('labels' => $labels, 'i18n_catalogue' => 'stPaypalBackend')) ?>
<?php echo form_tag('stPaypalBackend/save', array('id' => 'sf_admin_config_form', 'name' => 'sf_admin_config_form', 'class' => 'admin_form')) ?>
<fieldset id="sf_fieldset-paypal-live">
<div class="content">
<div class="row">
<?php echo st_admin_get_form_field('config[enabled]', __('Aktywuj'), 1, 'checkbox_tag', array('checked' => $config->get('enabled'), 'class' => 'st_paypal-live-field', 'size' => '60')) ?>
<div class="clr"></div>
</div>
<div class="form-row">
<?php echo label_for('config_live_api_username', __('Nazwa użytkownika API'), array('class' => 'required')) ?>
<div class="content<?php if ($sf_request->hasError('config{live_api_username}')): ?> form-error<?php endif; ?>">
<?php if ($sf_request->hasError('config{live_api_username}')): ?>
<?php echo form_error('config{live_api_username}', array('class' => 'form-error-msg')) ?>
<?php endif; ?>
<?php echo input_tag('config[live_api_username]', $config->get('live_api_username'), array('disabled' => $config->get('test_mode'), 'class' => 'st_paypal-live-field', 'size' => 60)) ?>
<br class="st_clear_all"/>
</div>
</div>
<div class="form-row">
<?php echo label_for('config_live_api_password', __('Hasło API'), array('class' => 'required')) ?>
<div class="content<?php if ($sf_request->hasError('config{live_api_password}')): ?> form-error<?php endif; ?>">
<?php if ($sf_request->hasError('config{live_api_password}')): ?>
<?php echo form_error('config{live_api_password}', array('class' => 'form-error-msg')) ?>
<?php endif; ?>
<?php echo input_password_tag('config[live_api_password]', $config->get('live_api_password'), array('disabled' => $config->get('test_mode'), 'class' => 'st_paypal-live-field', 'size' => 60)) ?>
<br class="st_clear_all"/>
</div>
</div>
<div class="form-row">
<?php echo label_for('config_live_api_signature', __('Podpis API'), array('class' => 'required')) ?>
<div class="content<?php if ($sf_request->hasError('config{live_api_signature}')): ?> form-error<?php endif; ?>">
<?php if ($sf_request->hasError('config{live_api_signature}')): ?>
<?php echo form_error('config{live_api_signature}', array('class' => 'form-error-msg')) ?>
<?php endif; ?>
<?php echo input_password_tag('config[live_api_signature]', $config->get('live_api_signature'), array('disabled' => $config->get('test_mode'), 'class' => 'st_paypal-live-field', 'size' => 60)) ?>
<br class="st_clear_all"/>
</div>
</div>
<?php if (SF_ENVIRONMENT == 'dev' || $sf_request->hasParameter('debug')): ?>
<div class="form-row">
<?php echo label_for('config_enabled', __('Włącz')) ?>
<div class="content">
<?php echo st_admin_checkbox_tag('config[enabled]', true, $config->get('enabled')) ?>
<br class="st_clear_all"/>
</div>
</div>
<div class="form-row">
<?php echo label_for('config_test_mode', __('Tryb testowy')) ?>
<div class="content">
<?php echo st_admin_checkbox_tag('config[test_mode]', true, $config->get('test_mode')) ?>
<br class="st_clear_all"/>
</div>
</div>
<?php endif ?>
<div class="form-row">
<?php echo label_for('config_show_shipping_info', __('Pokaż dane dostawy').' <a href="#" class="help" title="'.__('Wyświetla dane dostawy na stronie potwierdzenia płatności PayPal').'"></a>') ?>
<div class="content">
<?php echo st_admin_checkbox_tag('config[show_shipping_info]', true, $config->get('show_shipping_info')) ?>
<br class="st_clear_all"/>
</div>
</div>
</fieldset>
<fieldset id="sf_fieldset-paypal-live">
<h2><?php echo __('PayPal Express') ?></h2>
<div class="content">
<div class="form-row">
<?php echo label_for('config_express', __('Aktywuj płatność na karcie produktu')) ?>
<div class="content">
<?php echo st_admin_checkbox_tag('config[express]', true, $config->get('express')) ?>
<br class="st_clear_all"/>
</div>
</div>
<div class="form-row">
<?php echo label_for('config_show_shipping_info', __('Domyślna dostawa'));?>
<div class="content">
<?php echo select_tag('config[express_delivery]', objects_for_select($deliveries, 'getId', 'getName', $config->get('express_delivery')));?>
<br class="st_clear_all"/>
</div>
</div>
</div>
</fieldset>
<?php if (SF_ENVIRONMENT == 'dev' || $sf_request->hasParameter('debug')): ?>
<fieldset id="sf_fieldset-paypal-sandbox">
<h2><?php echo __('Konfiguracja API (tryb testowy)') ?></h2>
<div class="content">
<div class="form-row">
<?php echo label_for('config_sandbox_api_username', __('Nazwa użytkownika API'), array('class' => 'required')); ?>
<div class="content<?php if ($sf_request->hasError('config{sandbox_api_username}')): ?> form-error<?php endif; ?>">
<?php if ($sf_request->hasError('config{sandbox_api_username}')): ?>
<?php echo form_error('config{sandbox_api_username}', array('class' => 'form-error-msg')) ?>
<?php endif; ?>
<?php echo input_tag('config[sandbox_api_username]', $config->get('sandbox_api_username'), array('disabled' => !$config->get('test_mode'), 'class' => 'st_paypal-sandbox-field', 'size' => 60)) ?>
<br class="st_clear_all"/>
</div>
</div>
<div class="form-row">
<?php echo label_for('config_sandbox_api_password', __('Hasło API'), array('class' => 'required')) ?>
<div class="content<?php if ($sf_request->hasError('config{sandbox_api_password}')): ?> form-error<?php endif; ?>">
<?php if ($sf_request->hasError('config{sandbox_api_password}')): ?>
<?php echo form_error('config{sandbox_api_password}', array('class' => 'form-error-msg')) ?>
<?php endif; ?>
<?php echo input_password_tag('config[sandbox_api_password]', $config->get('sandbox_api_password'), array('disabled' => !$config->get('test_mode'), 'class' => 'st_paypal-sandbox-field', 'size' => 60)) ?>
<br class="st_clear_all"/>
</div>
</div>
<div class="form-row">
<?php echo label_for('config_sandbox_api_signature', __('Podpis API'), array('class' => 'required')) ?>
<div class="content<?php if ($sf_request->hasError('config{sandbox_api_signature}')): ?> form-error<?php endif; ?>">
<?php if ($sf_request->hasError('config{sandbox_api_signature}')): ?>
<?php echo form_error('config{sandbox_api_signature}', array('class' => 'form-error-msg')) ?>
<?php endif; ?>
<?php echo input_password_tag('config[sandbox_api_signature]', $config->get('sandbox_api_signature'), array('disabled' => !$config->get('test_mode'), 'class' => 'st_paypal-sandbox-field', 'size' => 60)) ?>
<br class="st_clear_all"/>
</div>
</div>
</div>
</fieldset>
<?php endif ?>
<?php if ($config->get('configuration_verified')): ?>
<fieldset id="sf_fieldset-paypal-account">
<h2><?php echo __('Informacje o koncie') ?></h2>
<div class="content">
<div class="form-row">
<div><?php echo __('Bilans konta') ?></div>
<div class="content" id="st_paypal-account-balance" style="margin-left: 15px;">
<?php echo image_tag('backend/stPaypalPlugin/ajax-loader.gif') ?>
</div>
</div>
<div class="form-row">
<div><?php echo __('Oczekujące płatności') ?>:</div>
<div class="content" id="st_paypal-pending-payments" style="margin-left: 15px;">
<?php echo image_tag('backend/stPaypalPlugin/ajax-loader.gif') ?>
</div>
</div>
</div>
</fieldset>
<?php endif ?>
<?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();?>
<script type="text/javascript">
jQuery(function($) {
$('#config_test_mode').on('change', function() {
var input = $(this);
if (input.prop('checked'))
{
$('.st_paypal-sandbox-field').prop('disabled', false);
$('.st_paypal-live-field').prop('disabled', true);
}
else
{
$('.st_paypal-sandbox-field').prop('disabled', true);
$('.st_paypal-live-field').prop('disabled', false);
}
});
$.get('<?php echo url_for('stPaypalBackend/ajaxPaypalAccountBalance') ?>', function(response) {
$('#st_paypal-account-balance').html(response);
});
$.get('<?php echo url_for('stPaypalBackend/ajaxPaypalPendingPayments') ?>', function(response) {
$('#st_paypal-pending-payments').html(response);
});
});
</script>