first commit
This commit is contained in:
138
class/payments/class.Essox.php
Normal file
138
class/payments/class.Essox.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Config;
|
||||
|
||||
class Essox extends Payment
|
||||
{
|
||||
public static $name = 'Essox';
|
||||
|
||||
protected $templateOrderView = 'payment.Essox.orderView.tpl';
|
||||
// protected $templateCart = 'payment.Essox.cart.tpl';
|
||||
|
||||
public $class = 'Essox';
|
||||
|
||||
protected $pay_method = Payment::METHOD_INSTALLMENTS;
|
||||
|
||||
// Config
|
||||
public $url = 'https://e-smlouvy.essox.cz';
|
||||
public $userName;
|
||||
public $encryptKey;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->readConfig();
|
||||
}
|
||||
|
||||
public function readConfig()
|
||||
{
|
||||
foreach ($this->config as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getEssoxOrderUrl()
|
||||
{
|
||||
return $this->getRequestUrl('NewContract', $this->order->total_price->asInteger(), ['OrderId' => $this->order->order_no]);
|
||||
}
|
||||
|
||||
protected function base64_url_encode($input)
|
||||
{
|
||||
return strtr(base64_encode($input), '+/', '-_');
|
||||
}
|
||||
|
||||
protected function getRequestUrl($method, $price, $customData)
|
||||
{
|
||||
$Timestamp = date('YmdHis', time()); // aktualni cas
|
||||
$UserName = $this->userName; // vase prihlasovaci jmeno
|
||||
$Password = $this->encryptKey; // vase heslo
|
||||
|
||||
$HashKey = $UserName.'#'.$Password.'#'.$price.'#'.$Timestamp;
|
||||
$HashKey = sha1($HashKey);
|
||||
|
||||
$extendedParameters = join('', array_map(function ($key, $value) {
|
||||
return "<{$key}>{$value}</{$key}>";
|
||||
}, array_keys($customData), $customData));
|
||||
|
||||
$xml = "<FinitServiceRequest>
|
||||
<Version>1.0</Version>
|
||||
<ServiceName>{$method}</ServiceName>
|
||||
<BaseParameters>
|
||||
<UserName>{$UserName}</UserName>
|
||||
<Price>{$price}</Price>
|
||||
<Timestamp>{$Timestamp}</Timestamp>
|
||||
<HashKey>{$HashKey}</HashKey>
|
||||
</BaseParameters>
|
||||
<ExtendedParameters>
|
||||
{$extendedParameters}
|
||||
</ExtendedParameters>
|
||||
|
||||
</FinitServiceRequest>";
|
||||
|
||||
return $this->url.'?ESXCode=5&ESXAuth='.$this->base64_url_encode(trim($xml));
|
||||
}
|
||||
|
||||
public function accept($totalPrice, $freeDelivery)
|
||||
{
|
||||
$totalPrice = $totalPrice->getPriceWithVat()->asFloat();
|
||||
if ($totalPrice <= 0 && $this->order) {
|
||||
$totalPrice = $this->order->total_price;
|
||||
}
|
||||
|
||||
return parent::accept($totalPrice, $freeDelivery) && $totalPrice >= 2000;
|
||||
}
|
||||
|
||||
public function getEssoxCalcUrl(Decimal $price)
|
||||
{
|
||||
$price = roundPrice($price, -1, 'DB', 0)->asInteger();
|
||||
|
||||
if ($price < 2000) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return path('kupshop_ordering_payment_legacypayment', [
|
||||
'step' => 5,
|
||||
'class' => $this->class,
|
||||
'price' => $price,
|
||||
]);
|
||||
}
|
||||
|
||||
public function processStep_1()
|
||||
{
|
||||
redirection($this->getEssoxOrderUrl());
|
||||
}
|
||||
|
||||
public function processStep_5()
|
||||
{
|
||||
$price = roundPrice(getVal('price'), -1, 'DB', 0)->asInteger();
|
||||
|
||||
if ($price < 2000) {
|
||||
return null;
|
||||
}
|
||||
|
||||
redirection($this->getRequestUrl('Calculation', $price, []));
|
||||
}
|
||||
|
||||
public function startPayment()
|
||||
{
|
||||
// Zakázat automatický redirect na bránu, už se z ní nikdy nevrátí
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasOnlinePayment()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function isEnabled($className)
|
||||
{
|
||||
$cfg = Config::get();
|
||||
|
||||
if (empty($cfg['Modules']['payments'][$className])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user