Files
2025-03-12 17:06:23 +01:00

225 lines
7.7 KiB
PHP

<?php
/**
* SOTESHOP/stPayment
*
* Ten plik należy do aplikacji stPayment 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 stPayment
* @subpackage actions
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/sote (Professional License SOTE)
* @version $Id: components.class.php 13721 2011-06-20 14:13:12Z michal $
* @author Michal Prochowski <michal.prochowski@sote.pl>,
*/
/**
* Klasa stPaymentComponents
*
* @package stPayment
* @subpackage actions
* @property Order $order
* @property Product $product
*/
class stPaymentComponents extends sfComponents
{
public function executePaymentInfoButton()
{
if (!$this->payment_type instanceof stPaymentTypeInterface)
{
return sfView::NONE;
}
$smarty = new stSmarty('stPayment');
$smarty->assign('amount', $this->amount);
$smarty->assign('payment_type', $this->payment_type);
$smarty->assign('init', $this->getUser()->getParameter('payment_info_button.init', false, 'soteshop/stPayment'));
$smarty->assign('type', $this->payment_type->getConfiguration()->getId());
$smarty->assign('title', isset($this->title) ? $this->title : null);
$smarty->assign('button_label', isset($this->button_label) ? $this->button_label : $this->payment_type->getPaymentInformationTitle());
$this->getUser()->setParameter('payment_info_button.init', true, 'soteshop/stPayment');
return $smarty;
}
/**
* Wyświetlenie listy płatności
*/
public function executeSelectPaymentType()
{
$this->smarty = new stSmarty('stPayment');
$c = new Criteria();
$c->add(PaymentTypePeer::ACTIVE, 1);
$this->paymentTypes = PaymentTypePeer::doSelect($c);
$paymentTypes = $this->paymentTypes;
foreach ($paymentTypes as $key => $paymentType)
{
if(class_exists($paymentType->getModuleName()))
{
$moduleName = $paymentType->getModuleName();
$obj = new $moduleName;
if(method_exists($obj, 'checkPaymentConfiguration'))
{
if (!$obj->checkPaymentConfiguration())
{
unset($this->paymentTypes[$key]);
}
}
}
}
$this->hasPaymentType = false;
if (count($this->paymentTypes) > 0)
{
$this->hasPaymentType = true;
}
$this->checked = 0;
$paymentType = stPayment::getInstance($this->getContext());
if(is_object($paymentType->get())) $this->checked = $paymentType->get()->getId();
}
/**
* Pokazanie płatności w podsumowaniu zamówienia
* @deprecated 8.0.9.0
*/
public function executeShowPayment()
{
$this->smarty = new stSmarty('stPayment');
$this->paymentType = null;
$this->paymentTypeName = null;
if (!isset($this->order))
{
$this->order = OrderPeer::retrieveByIdAndHashCode($this->getRequestParameter('id'), $this->getRequestParameter('hash_code'));
}
if (null === $this->order)
{
return sfView::NONE;
}
$payment = $this->order->getOrderPayment();
if (!$payment)
{
return sfView::NONE;
}
$this->paymentType = $payment->getPaymentType()->getModuleName();
$this->paymentTypeName = $payment->getPaymentType()->getName();
if(!$this->getController()->componentExists($this->paymentType.'Frontend', 'showPayment'))
{
return sfView::NONE;
}
}
public function executeProcessPayment()
{
if (!$this->order->showPayment())
{
return sfView::NONE;
}
$paymentType = $this->order->getOrderPayment()->getPaymentType();
$api = $paymentType->getApiInstance();
if ($api && $api instanceof stPaymentTypeInterface && $api->isAutoRedirectEnabled())
{
$action = $this->getController()->genUrl('@stPayment?action=processPayment&order_id='.$this->order->getId().'&order_hash='.$this->order->getHashCode().'&type='.$api->getConfiguration()->getId());
}
elseif(!$this->getController()->actionExists($paymentType->getModuleName().'Frontend', 'processPayment'))
{
return sfView::NONE;
}
else
{
$action = $this->getController()->genUrl($paymentType->getModuleName().'Frontend/processPayment?id='.$this->order->getId().'&hash='.$this->order->getHashCode());
}
$this->smarty = new stSmarty('stPayment');
$this->smarty->assign('api', $paymentType->getApiInstance());
$this->smarty->assign('action', $action);
}
/**
* Pokazywanie informacji na karcie produktu
*/
public function executeShowInfoInProduct()
{
if ($this->product && !$this->product->isPriceVisible())
{
return sfView::NONE;
}
$i18n = $this->getContext()->getI18N();
$config = stConfig::getInstance('stProduct');
if ($config->get('show_available_payments'))
{
$c = new Criteria();
$c->addJoin(PaymentTypePeer::ID, DeliveryHasPaymentTypePeer::PAYMENT_TYPE_ID);
$c->addJoin(DeliveryHasPaymentTypePeer::DELIVERY_ID, DeliveryPeer::ID);
$c->add(DeliveryPeer::ACTIVE, true);
$c->add(PaymentTypePeer::ACTIVE, true);
$c->addGroupByColumn(PaymentTypePeer::ID);
$payments = PaymentTypePeer::doSelectWithI18n($c);
}
else
{
$payments = [];
}
$this->smarty = new stSmarty('stPayment');
$this->smarty->assign('payments', $payments);
$this->smarty->assign('highlighted', $this->getHighlighted($payments, $this->product));
$this->smarty->assign('payments_label', $i18n->__('Płatności'));
$this->smarty->assign('lukas', stLukas::isActive());
$this->smarty->assign('amount', stPrice::round($this->product->getPriceBrutto(true)));
}
/**
* Zwraca listę wyróżnionych płatności
*
* @param PaymentType[] $paymentTypes
* @param Product $product
* @return array
* @todo Dostosowanie stPrzelewy24 do stPaymentTypeInterface
*/
protected function getHighlighted(array $paymentTypes, Product $product): array
{
$results = [];
$amount = $product->getPriceBrutto(true);
$api = new stPrzelewy24();
if ($api->checkPaymentConfiguration() && $api->getChannels())
{
$types = $api->getBasketPaymentTypes();
foreach ($api->getHighlightedPaymentsForProduct() as $type => $params)
{
if (isset($types[$type]))
{
$results[$type] = $params;
}
}
}
foreach ($paymentTypes as $paymentType)
{
if ($paymentType->getApiInstance() && method_exists($paymentType->getApiInstance(), 'getHighlightedPaymentsForProduct') && $paymentType->checkPaymentConfiguration($amount))
{
$results = array_merge($results, call_user_func([$paymentType->getApiInstance(), 'getHighlightedPaymentsForProduct'], $this->getContext()->getI18N(), $amount));
}
}
return $results;
}
}