File: /var/www/kpopbg.com_orig/modules/speedypayment/speedypayment.php
<?php
if (!defined('_PS_VERSION_'))
exit;
if((empty(Context::getContext()->controller->controller_name) || !preg_match('/^Admin/', Context::getContext()->controller->controller_name)) && session_id() == '') {
session_start();
}
class SpeedyPayment extends PaymentModule
{
public function __construct()
{
$this->name = 'speedypayment';
$this->tab = 'payments_gateways';
$this->version = '1.1.2';
$this->author = 'Speedy JSC';
$this->currencies = true;
$this->currencies_mode = 'checkbox';
parent::__construct();
$this->displayName = $this->l('Спиди наложен платеж');
$this->description = $this->l('Наложен платеж при доставка със Спиди');
/* For 1.4.3 and less compatibility */
$updateConfig = array('PS_OS_CHEQUE', 'PS_OS_PAYMENT', 'PS_OS_PREPARATION', 'PS_OS_SHIPPING', 'PS_OS_CANCELED', 'PS_OS_REFUND', 'PS_OS_ERROR', 'PS_OS_OUTOFSTOCK', 'PS_OS_BANKWIRE', 'PS_OS_PAYPAL', 'PS_OS_WS_PAYMENT');
if (!Configuration::get('PS_OS_PAYMENT'))
foreach ($updateConfig as $u)
if (!Configuration::get($u) && defined('_'.$u.'_'))
Configuration::updateValue($u, constant('_'.$u.'_'));
}
public function install()
{
if (!parent::install() OR !$this->registerHook('payment') OR !$this->registerHook('paymentReturn') OR !$this->registerHook('paymentOptions'))
return false;
return true;
}
public function hookPayment($params)
{
if (!$this->active || !$this->validateCurrency() || empty($_SESSION['speedy']['cod']) || $this->context->cart->id_carrier != Configuration::get('SPEEDY_CARRIER_ID'))
return ;
global $smarty;
// Check if cart has product download
foreach ($params['cart']->getProducts() AS $product)
{
$pd = ProductDownload::getIdFromIdProduct((int)($product['id_product']));
if ($pd AND Validate::isUnsignedInt($pd))
return false;
}
$this->context->smarty->assign('ps_version', '1.6');
$smarty->assign(array(
'this_path' => $this->_path,
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/',
'cod' => (isset($_SESSION['speedy']['cod']) && $_SESSION['speedy']['cod'] && $this->context->cart->id_carrier == Configuration::get('SPEEDY_CARRIER_ID') ? 1 : 0),
'no_weight' => (isset($_SESSION['speedy']['no_weight']) && $_SESSION['speedy']['no_weight'] && $this->context->cart->id_carrier == Configuration::get('SPEEDY_CARRIER_ID') ? $_SESSION['speedy']['no_weight'] : 0)
));
return $this->display(__FILE__, 'payment.tpl');
}
public function hookPaymentOptions($params)
{
if (!$this->active || !$this->validateCurrency() || empty($_SESSION['speedy']['cod']) || $this->context->cart->id_carrier != Configuration::get('SPEEDY_CARRIER_ID'))
return ;
// Check if cart has product download
foreach ($params['cart']->getProducts() AS $product)
{
$pd = ProductDownload::getIdFromIdProduct((int)($product['id_product']));
if ($pd AND Validate::isUnsignedInt($pd))
return ;
}
$this->context->smarty->assign('ps_version', '1.7');
$this->context->smarty->assign(array(
'this_path' => $this->_path,
'cod' => (isset($_SESSION['speedy']['cod']) && $_SESSION['speedy']['cod'] && $this->context->cart->id_carrier == Configuration::get('SPEEDY_CARRIER_ID') ? 1 : 0),
'no_weight' => (isset($_SESSION['speedy']['no_weight']) && $_SESSION['speedy']['no_weight'] && $this->context->cart->id_carrier == Configuration::get('SPEEDY_CARRIER_ID') ? $_SESSION['speedy']['no_weight'] : 0)
));
$newOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption();
$newOption->setModuleName($this->name)
->setCallToActionText($this->l('Спиди наложен платеж'))
->setAction($this->context->link->getModuleLink($this->name, 'validation', array(), true))
->setAdditionalInformation($this->fetch('module:speedypayment/views/templates/hook/payment.tpl'));
$payment_options = [
$newOption,
];
return $payment_options;
}
public function hookPaymentReturn($params)
{
if (!$this->active || !$this->validateCurrency())
return ;
return $this->display(__FILE__, 'confirmation.tpl');
}
public function validateCurrency() {
if (Currency::getIdByIsoCode('BGN')) {
return true;
} else {
return false;
}
}
}