first commit

This commit is contained in:
2025-01-06 20:47:25 +01:00
commit 3bdbd78c2f
25591 changed files with 3586440 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?php
/**
* Class Przelewy24Controller
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24JsonLegacyController
*
* The legacy class for code that expext JSON with wrong headers.
*/
class Przelewy24JsonLegacyController extends Przelewy24JsonController
{
/**
* Output.
*
* @var array
*/
protected $output = array();
/**
* Init content.
*/
public function initContent()
{
parent::initContent();
$this->output = array();
}
/**
* Legacy response function.
*
* The content type is not set to JSON.
* Some code may require this error.
*
* @param int $httpCode
* @param string $infoMessage
* @param bool $log
* @deprecated
*/
protected function response($httpCode, $infoMessage = '', $log = true)
{
http_response_code($httpCode);
if ($log) {
Przelewy24Logger::addTruncatedLog($infoMessage);
}
echo filter_var(json_encode($this->output), FILTER_SANITIZE_STRING);
exit;
}
/**
* Logs message.
*
* @param int $infoMessage
*/
protected function log($infoMessage)
{
PrestaShopLogger::addLog('Przelewy24Controller - ' . $infoMessage, 1);
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* Class przelewy24accountMyCardsModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24accountMyCardsModuleFrontController
*/
class Przelewy24accountMyCardsModuleFrontController extends ModuleFrontController
{
/**
* Init.
*/
public function init()
{
parent::init();
}
/**
* Init content.
*/
public function initContent()
{
parent::initContent();
$przelewy24 = new Przelewy24();
$message = '';
if (empty($this->context->customer->id)) {
Tools::redirect('index.php');
}
$customerId = (int)$this->context->customer->id;
if (Tools::isSubmit('submit')) {
if ((int)Tools::getValue('remember_cc_post')) {
$remember = (int)Tools::getValue('remember_credit_cards');
Przelewy24CustomerSetting::initialize($customerId)->setIsCardRemembered($remember)->save();
$message = $przelewy24->getLangString('Saved successfully');
}
if ($idOgRecurringToRemove = (int)Tools::getValue('remove_card')) {
$entryToRemove = new Przelewy24Recurring($idOgRecurringToRemove);
if ($entryToRemove->canBeRemovedByUser($customerId)) {
$entryToRemove->delete();
}
$message = $przelewy24->getLangString('Removed successfully');
}
}
$customerCards = Przelewy24Recurring::findArrayByCustomerId($customerId);
$this->context->smarty->assign(
array(
'logo_url' => $this->module->getPathUri() . 'views/img/logo.png',
'home_url' => _PS_BASE_URL_,
'urls' => $this->getTemplateVarUrls(),
'customer_cards' => $customerCards,
'message' => $message,
'remember_customer_cards' => Przelewy24CustomerSetting::initialize($customerId)->card_remember,
)
);
$this->setTemplate('module:przelewy24/views/templates/front/account_card_page.tpl');
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Class przelewy24ajaxBlikErrorModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24ajaxBlikErrorModuleFrontController
*/
class Przelewy24ajaxBlikErrorModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*/
public function initContent()
{
parent::initContent();
$output = array();
if ((Tools::getValue('errorCode') >= 0) || (Tools::getValue('reasonCode') >= 0)) {
$przelewy24BlikErrorEnum = new Przelewy24BlikErrorEnum($this);
$errorCode = Tools::getValue('errorCode');
if (!$errorCode) {
$errorCode = Tools::getValue('reasonCode');
}
/** @var Przelewy24ErrorResult $error */
$error = $przelewy24BlikErrorEnum->getErrorMessage($errorCode);
$output['error'] = $error->toArray();
}
echo json_encode($output);
exit;
}
}

View File

@@ -0,0 +1,199 @@
<?php
/**
* Class przelewy24ajaxChargeCardFormModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/gpl.html
*
*/
/**
* Class Przelewy24ajaxChargeCardFormModuleFrontController
*/
class Przelewy24ajaxChargeCardFormModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*/
public function initContent()
{
parent::initContent();
try {
$response = $this->doChargeCard();
} catch (Exception $e) {
PrestaShopLogger::addLog(
'przelewy24ajaxChargeCardFormModuleFrontController - ' .
json_encode(array( 'exception' => $e->getMessage() )),
1
);
$response = array();
}
exit(json_encode($response));
}
/**
* Charges card.
*
* @return array
*
* @throws Exception
*/
private function doChargeCard()
{
$cartId = (int)Tools::getValue('cartId', 0);
$przelewy24 = new Przelewy24();
if ('cardCharge' !== Tools::getValue('action') || $cartId < 0) {
throw new Exception($przelewy24->getLangString('Invalid request'));
}
/** @var $cart \PrestaShop\PrestaShop\Adapter\Entity\Order */
$cart = new Cart($cartId);
if (!$cart) {
throw new Exception($przelewy24->getLangString('Invalid cart ID'));
}
$orderId = Order::getIdByCartId($cartId);
$order = new Order($orderId);
$extracharge = 0;
if ($orderId && 'przelewy24' === $order->module) {
$currency = new Currency($order->id_currency);
$shipping = $cart->getPackageShippingCost((int)$order->id_carrier) * 100;
$amount = Przelewy24Helper::p24AmountFormat($order->total_paid);
$products = $order->getProducts();
$customerId = $order->id_customer;
$description = $przelewy24->getLangString("Order") . ': ' . $order->id;
} else {
$currency = new Currency($cart->id_currency);
$suffix = Przelewy24Helper::getSuffix($currency->iso_code);
$shipping = $cart->getPackageShippingCost((int)$cart->id_carrier) * 100;
$amount = Przelewy24Helper::p24AmountFormat($cart->getOrderTotal(true, Cart::BOTH));
$servicePaymentOptions = new Przelewy24ServicePaymentOptions(new Przelewy24());
$extracharge = $servicePaymentOptions->getExtracharge(
$cart->getOrderTotal(true, Cart::BOTH),
$suffix
) * 100;
$products = $cart->getProducts();
$customerId = $cart->id_customer;
$description = $przelewy24->getLangString("Cart") . ': ' . $cart->id;
}
$customer = new Customer($customerId);
if (empty($this->context->customer->id) || empty($cart->id_customer) ||
(int)$this->context->customer->id !== (int)$cart->id_customer) {
if (empty($cart->id_customer) || !$customer) {
throw new Exception($przelewy24->getLangString('Order not exist for this customer'));
}
}
$my_currency_iso_code = $currency->iso_code;
$suffix = Przelewy24Helper::getSuffix($my_currency_iso_code);
$p24_session_id = $cart->id . '|' . md5(time());
// products cart
$productsInfo = array();
foreach ($products as $product) {
if (!is_array($product)) {
$product = array();
}
$product = array_merge(array(
'name' => null,
'description_short' => null,
'cart_quantity' => null,
'price' => null,
'id_product' => null,
), $product);
$productsInfo[] = array(
'name' => $product['name'],
'description' => $product['description_short'],
'quantity' => (int)$product['cart_quantity'],
'price' => null !== $product['price'] ? (int)($product['price'] * 100) : null,
'number' => (int)$product['id_product'],
);
}
$translations = array(
'virtual_product_name' => $przelewy24->getLangString('Extra charge [VAT and discounts]'),
'cart_as_product' => $przelewy24->getLangString('Your order'),
);
$p24Product = new Przelewy24Product($translations);
$p24ProductItems = $p24Product->prepareCartItems($amount, $productsInfo, $shipping);
$addresses = $customer->getAddresses((int)Configuration::get('PS_LANG_DEFAULT'));
$addressObj = array_pop($addresses);
$address = new Address((int)$addressObj['id_address']);
$s_lang = new Country((int)($address->id_country));
$iso_code = $this->context->language->iso_code;
$url_status = $this->context->link->getModuleLink(
'przelewy24',
'paymentStatus',
$orderId ? ['id_order' => $orderId] : ['id_cart'=> $cartId ],
'1' === (string)Configuration::get('PS_SSL_ENABLED')
);
$P24C = Przelewy24ClassInterfaceFactory::getForSuffix($suffix);
if ($extracharge > 0) {
$amount = $amount + $extracharge;
}
$post_data = array(
'p24_merchant_id' => Configuration::get('P24_MERCHANT_ID' . $suffix),
'p24_pos_id' => Configuration::get('P24_SHOP_ID' . $suffix),
'p24_session_id' => $p24_session_id,
'p24_amount' => $amount,
'p24_currency' => $my_currency_iso_code,
'p24_description' => $description,
'p24_email' => $customer->email,
'p24_client' => $customer->firstname . ' ' . $customer->lastname,
'p24_address' => $address->address1 . " " . $address->address2,
'p24_zip' => $address->postcode,
'p24_city' => $address->city,
'p24_country' => $s_lang->iso_code,
'p24_language' => Tools::strtolower($iso_code),
'p24_url_return' => $this->context->link->getModuleLink(
'przelewy24',
'paymentFinished',
$orderId ? ['id_order' => $orderId] : ['id_cart'=> $cartId ],
'1' === (string)Configuration::get('PS_SSL_ENABLED')
),
'p24_url_status' => $url_status,
'p24_api_version' => P24_VERSION,
'p24_ecommerce' => 'prestashop_' . _PS_VERSION_,
'p24_ecommerce2' => Configuration::get('P24_PLUGIN_VERSION'),
'p24_shipping' => $shipping,
);
$post_data += $p24ProductItems;
foreach ($post_data as $k => $v) {
$P24C->addValue($k, $v);
}
$token = $P24C->trnRegister();
$p24_sign = $P24C->trnDirectSign($post_data);
if (is_array($token) && !empty($token['token'])) {
$token = $token['token'];
return array(
'p24jsURL' => $P24C->getHost() . 'inchtml/card/register_card_and_pay/ajax.js?token=' . $token,
'p24cssURL' => $P24C->getHost() . 'inchtml/card/register_card_and_pay/ajax.css',
'p24_sign' => $p24_sign,
'sessionId' => $p24_session_id,
'client_id' => $customer->id
);
}
throw new Exception($przelewy24->getLangString('Failed transaction registration in Przelewy24'));
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Class przelewy24ajaxNoticesModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24ajaxNoticesModuleFrontController
*/
class Przelewy24ajaxNoticesModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*/
public function initContent()
{
parent::initContent();
$response = array('status' => 0);
if (!empty($_POST)) {
if (!empty(Tools::getValue('card_remember'))) {
$remember = (int)Tools::getValue('remember');
$customerId = Context::getContext()->customer->id;
if (!empty($customerId)) { // remember my card
$result = Przelewy24CustomerSetting::initialize($customerId)
->setIsCardRemembered($remember)
->save();
$response = array('status' => (int)$result);
}
}
}
Przelewy24Helper::renderJson($response);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Class przelewy24ajaxPaymentCheckModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24ajaxPaymentCheckModuleFrontController
*/
class Przelewy24ajaxPaymentCheckModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*
* @return string $return
*/
public function initContent()
{
parent::initContent();
$cartId = (int)Tools::getValue('cartId');
$order_id = Order::getOrderByCartId($cartId);
$order = new Order($order_id);
$return = 0;
if ($order->hasInvoice()) {
$return = 1;
}
return Przelewy24Helper::renderJson($return);
}
}

View File

@@ -0,0 +1,117 @@
<?php
/**
* Class przelewy24ajaxRegisterCardFormModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24ajaxRegisterCardFormModuleFrontController
*/
class Przelewy24ajaxRegisterCardFormModuleFrontController extends Przelewy24JsonLegacyController
{
/**
* Init content.
*
* @throws Exception
*/
public function initContent()
{
parent::initContent();
if ('cardRegister' !== Tools::getValue('action')) {
Tools::redirect('index.php');
}
$cookie = Context::getContext()->cookie;
$currency = new CurrencyCore($cookie->id_currency);
$my_currency_iso_code = $currency->iso_code;
$suffix = Przelewy24Helper::getSuffix($currency->iso_code);
$p24_session_id = md5(time());
$description = "Rejestracja karty";
$amount = 1;
$amount = Przelewy24Helper::p24AmountFormat($amount);
$customer = new Customer((int)($cookie->id_customer));
$addresses = $customer->getAddresses((int)Configuration::get('PS_LANG_DEFAULT'));
$addressObj = array_pop($addresses);
$address = new Address((int)$addressObj['id_address']);
$s_lang = new Country((int)($address->id_country));
$iso_code = $this->context->language->iso_code;
$url_status = $this->context->link->getModuleLink(
'przelewy24',
'paymentStatus',
array(),
'1' === (string)Configuration::get('PS_SSL_ENABLED')
);
$P24C = Przelewy24ClassInterfaceFactory::getForSuffix($suffix);
$post_data = array(
'p24_merchant_id' => Configuration::get('P24_MERCHANT_ID' . $suffix),
'p24_pos_id' => Configuration::get('P24_SHOP_ID' . $suffix),
'p24_session_id' => $p24_session_id,
'p24_amount' => $amount,
'p24_currency' => $my_currency_iso_code,
'p24_description' => $description,
'p24_email' => $customer->email,
'p24_client' => $customer->firstname . ' ' . $customer->lastname,
'p24_address' => $address->address1 . " " . $address->address2,
'p24_zip' => $address->postcode,
'p24_city' => $address->city,
'p24_country' => $s_lang->iso_code,
'p24_language' => Tools::strtolower($iso_code),
'p24_url_return' => $this->context->link->getModuleLink(
'przelewy24',
'paymentFinished',
[],
'1' === (string)Configuration::get('PS_SSL_ENABLED')
),
'p24_url_status' => $url_status,
'p24_api_version' => P24_VERSION,
'p24_ecommerce' => 'prestashop_' . _PS_VERSION_,
'p24_ecommerce2' => Configuration::get('P24_PLUGIN_VERSION'),
'p24_shipping' => 0,
'p24_name_1' => $description,
'p24_description_1' => '',
'p24_quantity_1' => 1,
'p24_price_1' => $amount,
'p24_number_1' => 0,
);
foreach ($post_data as $k => $v) {
$P24C->addValue($k, $v);
}
$token = $P24C->trnRegister();
$p24_sign = $P24C->trnDirectSign($post_data);
if (is_array($token) && !empty($token['token'])) {
$token = $token['token'];
$this->output = array(
'p24jsURL' => $P24C->getHost() . 'inchtml/card/register_card/ajax.js?token=' . $token,
'p24cssURL' => $P24C->getHost() . 'inchtml/card/register_card/ajax.css',
'p24_sign' => $p24_sign,
'sessionId' => $p24_session_id,
'client_id' => $customer->id,
);
$this->response(200, '', false);
} else {
$logMessage = print_r($token, true);
Przelewy24Logger::addTruncatedLog($logMessage);
}
exit();
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* Class przelewy24ajaxRememberOneclickOrderIdModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/gpl.html
*
*/
/**
* Class Przelewy24ajaxRememberOneclickOrderIdModuleFrontController
*/
class Przelewy24ajaxRememberOneclickOrderIdModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*/
public function initContent()
{
$data = array();
try {
$orderId = $this->sanitizeOrderId(Tools::getValue('orderId'));
$sessionId = $this->sanitizeSessionId(Tools::getValue('sessionId'));
$sign = $this->sanitizeSign(Tools::getValue('sign'));
$signValidation = $this->checkSign($sign, $sessionId);
if ($orderId && $sessionId && $sign && $signValidation) {
$data['success'] = 1;
$data['error'] = '';
} else {
$data['success'] = 0;
$data['error'] = 'wrong data';
}
} catch (Exception $e) {
$data['success'] = 0;
$data['error'] = 'Data not added';
}
Przelewy24Helper::renderJson($data);
}
/**
* Sanitize order id.
*
* @param int|string $orderId
*
* @return int|bool
*/
private function sanitizeOrderId($orderId)
{
if (9 === Tools::strlen($orderId) || 0 === (int)$orderId) {
return (int)$orderId;
} else {
return false;
}
}
/**
* Sanitize session id.
*
* @param string $sessionId
* @return string|bool
*/
private function sanitizeSessionId($sessionId)
{
if (Tools::strlen($sessionId) > 0 && filter_var($sessionId, FILTER_SANITIZE_STRING)) {
return filter_var($sessionId, FILTER_SANITIZE_STRING);
} else {
return false;
}
}
/**
* Sanitizes sign parameter.
*
* @param string $sign
*
* @return string|bool
*/
private function sanitizeSign($sign)
{
if (Tools::strlen($sign) > 0 && Tools::strlen($sign) <= 100 && filter_var($sign, FILTER_SANITIZE_STRING)) {
return filter_var($sign, FILTER_SANITIZE_STRING);
} else {
return false;
}
}
/**
* Checks sign correctness.
*
* @param string $sign
* @param string $sessionId
*
* @return bool
*/
private function checkSign($sign, $sessionId)
{
list($cartId) = explode('|', $sessionId, 1);
$cartId = (int)$cartId;
$cart = new Cart($cartId);
$currency = new Currency($cart->id_currency);
$suffix = Przelewy24Helper::getSuffix($currency->iso_code);
$amount = Przelewy24Helper::p24AmountFormat($cart->getOrderTotal(true, Cart::BOTH));
$przelewy24ServicePaymentOptions = new Przelewy24ServicePaymentOptions(new Przelewy24());
$extracharge = (int)($przelewy24ServicePaymentOptions->getExtracharge($amount / 100, $suffix) * 100);
$amount = $amount + $extracharge;
$currency = new Currency($cart->id_currency);
$suffix = Przelewy24Helper::getSuffix($currency->iso_code);
$merchantId = Configuration::get('P24_MERCHANT_ID' . $suffix);
$salt = Configuration::get('P24_SALT' . $suffix);
$countedSign = md5($sessionId . '|' . $merchantId . '|' . $amount . '|' . $currency->iso_code . '|' . $salt);
if ($sign === $countedSign) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,123 @@
<?php
/**
* Class przelewy24ajaxVerifyBlikModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24ajaxVerifyBlikModuleFrontController
*/
class Przelewy24ajaxVerifyBlikModuleFrontController extends Przelewy24JsonLegacyController
{
/**
* Customer id.
*
* @var int
*/
private $customerId;
/**
* P24 order id (Przelewy24Order->p24_order_id).
*
* @var int
*/
private $p24OrderId;
/**
* P24 order.
*
* @var Przelewy24Order
*/
private $p24Order;
/**
* Prestashop order id (Przelewy24Order->pshop_order_id)
*
* @var int
*/
private $pshopOrder;
/**
* Action to perform.
*
* @var string
*/
private $action;
/**
* Init content.
* @throws Exception
*/
public function initContent()
{
parent::initContent();
$this->customerId = (int)$this->context->customer->id;
$this->p24OrderId = (int)Tools::getValue('params')['orderId'];
$this->action = filter_var(Tools::getValue('action'), FILTER_SANITIZE_STRING);
if ('Subscribe' !== $this->action || !$this->p24OrderId) {
$this->response(400, 'Wrong action or no p24OrderId');
}
if (!$this->customerId) {
$this->response(403, 'Customer context does not exist');
}
$this->p24Order = new Przelewy24Order($this->p24OrderId);
if (!$this->p24Order->p24_order_id || !$this->p24Order->pshop_order_id) {
$this->response(404, 'P24Order not found');
}
$this->pshopOrder = new Order((int)$this->p24Order->pshop_order_id);
if (!$this->pshopOrder->id) {
$this->response(404, 'Prestashop order not found');
}
if ((int)$this->pshopOrder->id_customer !== (int)$this->customerId) {
$this->response(403, 'The customer is not allowed to check this transaction status');
}
$p24BlikSoap = Przelewy24BlikSoapInterfaceFactory::getDefault();
$this->output = $p24BlikSoap->getTransactionStatus($this->p24OrderId);
$przelewy24BlikErrorEnum = new Przelewy24BlikErrorEnum($this);
$errorCode = (int)$this->output['error'];
if (!$errorCode && 'AUTHORIZED' !== $this->output['status']) {
$errorCode = (int)$this->output['reasonCode'];
}
/** @var Przelewy24ErrorResult $error */
$error = $przelewy24BlikErrorEnum->getErrorMessage($errorCode);
$this->output['error'] = $error->toArray();
$this->response(200, 'Response success');
}
/**
* Log message.
*
* @param string $infoMessage
*/
protected function log($infoMessage)
{
PrestaShopLogger::addLog(
'ajaxVerifyBlik - ' . $infoMessage . ' - ' .
json_encode(
array(
'customerId' => (int)$this->customerId,
'p24OrderId' => (int)$this->p24OrderId,
'p24Order' => (bool)$this->p24Order,
'pshopOrder' => (bool)$this->pshopOrder,
'action' => $this->action,
'output' => $this->output,
)
),
1
);
}
}

View File

@@ -0,0 +1,274 @@
<?php
/**
* Class przelewy24chargeBlikModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24chargeBlikModuleFrontController
*/
class Przelewy24chargeBlikModuleFrontController extends ModuleFrontController
{
/**
* Order.
*
* @var Order
*/
private $order;
/**
* Session id.
*
* @var string
*/
private $p24_session_id;
/**
* Description.
*
* @var string
*/
private $description;
/**
* Amount.
*
* @var string
*/
private $amount;
/**
* Shop customer.
*
* @var Customer
*/
private $customer;
/**
* Currency code.
*
* @var string
*/
private $currencyCode;
/**
* Url for site with payment status.
*
* @var string
*/
private $url_status;
/**
* Init content.
*
* @throws Exception
*/
public function initContent()
{
parent::initContent();
if (Tools::getValue('id_order')) {
$this->order = new Order((int)Tools::getValue('id_order'));
$this->amount = Przelewy24Helper::p24AmountFormat($this->order->getOrdersTotalPaid());
$customerId = $this->order->id_customer;
$cookie = $this->context->cookie;
// Removes remembered token of transaction when there is new transaction active.
if (isset($cookie->token) && ((int)$cookie->tokenOrderId !== (int)Tools::getValue('id_order'))) {
$cookie->__unset('token');
$cookie->__unset('tokenOrderId');
}
$this->url_status = Context::getContext()->link->getModuleLink(
'przelewy24',
'paymentStatus',
array('id_order' => $this->order->id),
'1' === (string)Configuration::get('PS_SSL_ENABLED')
);
$currency = new CurrencyCore($cookie->id_currency);
$this->currencyCode = $currency->iso_code;
$this->customer = new Customer((int)($customerId));
$this->p24_session_id = $this->order->id . '|' . md5(time());
$this->description = 'Blik UID payment';
// Gets alias from database, when it exists and user is logged in.
$p24BlikSoap = Przelewy24BlikSoapInterfaceFactory::getDefault();
$savedAlias = false;
if ($this->context->customer->isLogged()) {
$savedAlias = Przelewy24BlikHelper::getSavedAlias($this->customer);
}
$aliasAlternatives = false;
$alternativeKeys = Tools::getValue('alternativeKey');
if ($savedAlias && ('false' === Tools::getValue('blikCode')) && $alternativeKeys) {
// Another transaction of already remembered user.
$paymentResult = $p24BlikSoap->executePaymentByUIdWithAlternativeKey(
$savedAlias,
$this->amount,
$this->currencyCode,
$this->customer->email,
$this->p24_session_id,
$this->customer->firstname . ' ' . $this->customer->lastname,
$this->description,
$alternativeKeys,
json_encode(array('url_status' => $this->url_status))
);
} elseif ($savedAlias && ('false' === Tools::getValue('blikCode'))) {
// Another transaction of already remembered user.
$paymentResult = $p24BlikSoap->executePaymentByUid(
$savedAlias,
$this->amount,
$this->currencyCode,
$this->customer->email,
$this->p24_session_id,
$this->customer->firstname . ' ' . $this->customer->lastname,
$this->description,
json_encode(array('url_status' => $this->url_status))
);
if (isset($paymentResult['error']) &&
((int)$paymentResult['error'] === Przelewy24BlikErrorEnum::ERR_ALIAS_IDENTIFICATION)) {
$aliasAlternatives = $paymentResult['aliasAlternatives'];
}
} elseif ($savedAlias && ('true' === Tools::getValue('declinedAlias'))) {
// Transaction with alias AND blickCode (when alias was rejeced by websocket).
$paymentResult = $p24BlikSoap->executePaymentByUidWithBlikCode(
$savedAlias,
$this->amount,
$this->currencyCode,
$this->customer->email,
$this->p24_session_id,
$this->customer->firstname . ' ' . $this->customer->lastname,
$this->description,
pSQL(Tools::getValue('blikCode')),
json_encode(array('url_status' => $this->url_status))
);
} else {
// Registering transaction / getting saved token.
if (Tools::getValue('blikCodeCheck') && !Tools::getValue('declinedAlias')) {
if (!isset($cookie->token)) {
$token = $this->registerBlikTransaction();
$cookie->__set('token', $token['token']);
$cookie->__set('tokenOrderId', Tools::getValue('id_order'));
} else {
$token['token'] = $cookie->token;
}
} else {
$token = $this->registerBlikTransaction();
}
// Transaction of not remembered user or guest.
$paymentResult = $p24BlikSoap->executePaymentAndCreateUid(
pSQL(Tools::getValue('blikCode')),
$token['token']
);
if ($paymentResult['success'] && $this->context->customer->isLogged()) {
$model = Przelewy24BlikAlias::prepareEmptyModel($customerId);
$model->last_order_id = $paymentResult['orderId'];
$model->save();
}
}
Przelewy24Order::saveOrder($paymentResult['orderId'], $this->order->id, $this->p24_session_id);
if ($paymentResult['success']) {
$response = array(
'urlSuccess' => $this->context->link->getModuleLink(
'przelewy24',
'paymentSuccessful',
array(),
'1' === (string)Configuration::get('PS_SSL_ENABLED')
),
'status' => 'success',
'orderId' => $paymentResult['orderId'],
'error' => false,
);
} else {
$status = $paymentResult['error'];
$error = new Przelewy24BlikErrorEnum($this);
$response = array(
'urlFail' => $this->context->link->getModuleLink(
'przelewy24',
'paymentFailed',
array('errorCode' => $paymentResult['error'], 'order_id' => $this->order->id),
'1' === (string)Configuration::get('PS_SSL_ENABLED')
),
'status' => $status,
'aliasAlternatives' => $aliasAlternatives,
'error' => $error->getErrorMessage($status)->toArray(),
);
}
echo json_encode($response);
}
exit;
}
/**
* Register blik transaction.
*
* @return array
*
* @throws Exception
*/
private function registerBlikTransaction()
{
$p24Class = Przelewy24ClassBlikInterfaceFactory::getDefault();
$addresses = $this->customer->getAddresses((int)Configuration::get('PS_LANG_DEFAULT'));
$addressObj = array_pop($addresses);
$address = new Address((int)$addressObj['id_address']);
$s_lang = new Country((int)($address->id_country));
$iso_code = Context::getContext()->language->iso_code;
$customerName = $this->customer->firstname . ' ' . $this->customer->lastname;
$successUrl = Context::getContext()->link->getModuleLink(
'przelewy24',
'paymentSuccess',
array(),
'1' === (string)Configuration::get('PS_SSL_ENABLED')
);
$post_data = array(
'p24_merchant_id' => Configuration::get('P24_MERCHANT_ID'),
'p24_pos_id' => Configuration::get('P24_SHOP_ID'),
'p24_session_id' => $this->p24_session_id,
'p24_amount' => $this->amount,
'p24_currency' => $this->currencyCode,
'p24_description' => $this->description,
'p24_email' => $this->customer->email,
'p24_client' => $customerName,
'p24_address' => $address->address1 . ' ' . $address->address2,
'p24_zip' => $address->postcode,
'p24_city' => $address->city,
'p24_country' => $s_lang->iso_code,
'p24_language' => Tools::strtolower($iso_code),
'p24_url_return' => $successUrl,
'p24_url_status' => $this->url_status,
'p24_api_version' => P24_VERSION,
'p24_ecommerce' => 'prestashop_' . _PS_VERSION_,
'p24_ecommerce2' => Configuration::get('P24_PLUGIN_VERSION'),
'p24_shipping' => 0,
'p24_name_1' => $this->description,
'p24_description_1' => '',
'p24_quantity_1' => 1,
'p24_price_1' => $this->amount,
'p24_number_1' => 0,
);
foreach ($post_data as $k => $v) {
$p24Class->addValue($k, $v);
}
$token = $p24Class->trnRegister();
return $token;
}
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* Class przelewy24chargeCardModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24chargeCardModuleFrontController
*/
class Przelewy24chargeCardModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*
* @throws Exception
*/
public function initContent()
{
parent::initContent();
$valid = false;
$createdPrestaShopOrder = false;
$toolsIdCart = (int)Tools::getValue('id_cart');
$toolsP24CardCustomerId = (int)Tools::getValue('p24_card_customer_id');
if (!empty($toolsIdCart) && !empty($toolsP24CardCustomerId)) {
$cartId = (int)Tools::getValue('id_cart');
/** @var $order \PrestaShop\PrestaShop\Adapter\Entity\Order */
$cart = new Cart($cartId);
$currency = new Currency($cart->id_currency);
$suffix = Przelewy24Helper::getSuffix($currency->iso_code);
$customer = new Customer((int)($cart->id_customer));
$cardId = (int)Tools::getValue('p24_card_customer_id');
$creditCards = Przelewy24Recurring::findByCustomerId($customer->id);
if (is_array($creditCards) && !empty($creditCards)) {
foreach ($creditCards as $creditCard) {
if (isset($creditCard->id) && $cardId === (int)$creditCard->id) {
$refId = $creditCard->reference_id;
$p24Soap = Przelewy24SoapInterfaceFactory::getForSuffix($suffix);
$p24OrderId = $p24Soap->chargeCard(
filter_var(Configuration::get('P24_API_KEY' . $suffix), FILTER_SANITIZE_STRING),
filter_var($refId, FILTER_SANITIZE_STRING),
(int)Tools::getValue('p24_amount'),
filter_var(Tools::getValue('p24_currency'), FILTER_SANITIZE_STRING),
filter_var(Tools::getValue('p24_email'), FILTER_SANITIZE_STRING),
filter_var(Tools::getValue('p24_session_id'), FILTER_SANITIZE_STRING),
filter_var(Tools::getValue('p24_client'), FILTER_SANITIZE_STRING),
filter_var(Tools::getValue('p24_description'), FILTER_SANITIZE_STRING)
);
$orderId = Order::getIdByCartId($cartId);
if (!$orderId) {
$orderBeginingState = Configuration::get('P24_ORDER_STATE_1');
$amount = $cart->getOrderTotal(true, Cart::BOTH);
$this->module->validateOrder(
(int)$cart->id,
(int)$orderBeginingState,
(float)$amount,
$this->module->displayName,
null,
array(),
(int)$cart->id_currency,
false,
$customer->secure_key
);
$orderId = Order::getIdByCartId($cartId);
$servicePaymentOptions = new Przelewy24ServicePaymentOptions(new Przelewy24());
$servicePaymentOptions->setExtrachargeByOrderId($orderId);
}
if ($p24OrderId) {
$order = new Order($orderId);
$order->current_state = Configuration::get('P24_ORDER_STATE_2');
$order->update();
$history = new OrderHistory();
$history->id_order = $orderId;
$history->changeIdOrderState(Configuration::get('P24_ORDER_STATE_2'), $orderId);
$history->addWithemail(true);
$history->update();
$valid = true;
$createdPrestaShopOrder = true;
} else {
PrestaShopLogger::addLog('chargeCard response: ' . var_export($p24OrderId, true), 1);
}
}
}
}
}
if ($createdPrestaShopOrder) {
$p24SessionId = filter_var(Tools::getValue('p24_session_id'), FILTER_SANITIZE_STRING);
if (isset($p24OrderId) && isset($orderId) && $p24SessionId) {
Przelewy24Order::saveOrder($p24OrderId, $orderId, $p24SessionId);
} else {
$msg = [];
$msg[] = isset($p24OrderId) ? '' : 'no $p24OrderId';
$msg[] = isset($orderId) ? '' : 'no $orderId';
$msg[] = $p24SessionId ? '' : 'wrong $p24SessionId';
$msg = join(';', $msg);
PrestaShopLogger::addLog(__METHOD__ . ' Cannot create P24 order. Problems: ' . $msg);
}
}
if ($valid) {
Tools::redirect(
$this->context->link->getModuleLink(
'przelewy24',
'paymentSuccessful',
array(),
'1' === (string)Configuration::get('PS_SSL_ENABLED')
)
);
} else {
Tools::redirect(
$this->context->link->getModuleLink(
'przelewy24',
'paymentFailed',
array(),
'1' === (string)Configuration::get('PS_SSL_ENABLED')
)
);
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2016 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,33 @@
<?php
/**
* Class przelewy24paymentConfirmBlikModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24paymentConfirmBlikModuleFrontController
*/
class Przelewy24paymentConfirmBlikModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*/
public function initContent()
{
parent::initContent();
$this->context->smarty->assign(
array(
'logo_url' => $this->module->getPathUri() . 'views/img/logo.png',
'home_url' => _PS_BASE_URL_,
'urls' => $this->getTemplateVarUrls(),
)
);
$this->setTemplate('module:przelewy24/views/templates/front/payment_confirm_blik.tpl');
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* Class przelewy24paymentConfirmationModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24paymentConfirmationModuleFrontController
*/
class Przelewy24paymentConfirmationModuleFrontController extends ModuleFrontController
{
/**
* Post process.
*/
public function postProcess()
{
$smarty = Context::getContext()->smarty;
$cart = $this->context->cart;
$currency = $this->context->currency;
if ((0 === (int)$cart->id_customer) || (0 === (int)$cart->id_address_delivery) ||
(0 === (int)$cart->id_address_invoice) || !$this->module->active) {
Tools::redirect('index.php?controller=order&step=1');
}
$servicePaymentOptions = new Przelewy24ServicePaymentOptions(new Przelewy24());
$suffix = Przelewy24Helper::getSuffix($currency->iso_code);
$customer = new Customer($cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
Tools::redirect('index.php?controller=order&step=1');
}
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$idOrderState = (int)Configuration::get('P24_ORDER_STATE_1');
$paymentMethod = '';
if (Tools::getValue('payment_method') && (int)Tools::getValue('payment_method') > 0) {
$paymentMethod = '&payment_method=' . (int)Tools::getValue('payment_method');
}
if (0 === (int)Configuration::get('P24_VERIFYORDER' . $suffix)) {
$this->module->validateOrder(
(int)$cart->id,
$idOrderState,
$total,
$this->module->displayName,
null,
array(),
(int)$currency->id,
false,
$customer->secure_key
);
$currentOrderId = (int)$this->module->currentOrder;
if (!$servicePaymentOptions->hasExtrachargeOrder($currentOrderId)) {
$servicePaymentOptions->setExtrachargeByOrderId($currentOrderId);
}
Tools::redirect(
'index.php?controller=order-confirmation&id_cart=' . (int)$cart->id .
'&id_module=' . (int)$this->module->id .
'&id_order=' . (int)$this->module->currentOrder .
'&key=' . $customer->secure_key . $paymentMethod
);
}
$service = new Przelewy24ServicePaymentReturn(new Przelewy24());
$data = $service->execute($this->context);
$przelewy24 = new Przelewy24();
$protocol = $przelewy24->getProtocol();
$smarty->assign(
'base_url',
$protocol . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__
);
$smarty->assign($data);
$this->setTemplate('module:przelewy24/views/templates/front/payment_confirmation.tpl');
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Class przelewy24paymentFailedModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24paymentFailedModuleFrontController
*/
class Przelewy24paymentFailedModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*/
public function initContent()
{
parent::initContent();
if (Tools::getValue('errorCode')) {
$przelewy24BlikErrorEnum = new Przelewy24BlikErrorEnum($this);
/** @var Przelewy24ErrorResult $error */
$error = $przelewy24BlikErrorEnum->getErrorMessage((int)Tools::getValue('errorCode'));
$this->context->smarty->assign(array('errorReason' => $error->getErrorMessage()));
}
$this->context->smarty->assign(
array(
'logo_url' => $this->module->getPathUri() . 'views/img/logo.png',
'home_url' => _PS_BASE_URL_,
'urls' => $this->getTemplateVarUrls(),
)
);
$this->setTemplate('module:przelewy24/views/templates/front/payment_failed.tpl');
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* Class Przelewy24paymentFinishedModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24paymentFinishedModuleFrontController
*/
class Przelewy24paymentFinishedModuleFrontController extends ModuleFrontController
{
const TIME_TO_WAIT_FOR_PAYMENT_STATUS = 2;
const MAXIMUM_TRY = 3;
const FETCH_LAST_ORDER = false;
/**
* Redirect to finished or failed payment.
*/
public function initContent()
{
parent::initContent();
$order = null;
$idOrder = Tools::getValue('id_order');
$idCart = Tools::getValue('id_cart');
$sleep = Tools::getValue('sleep') ? Tools::getValue('sleep') : 0;
sleep(self::TIME_TO_WAIT_FOR_PAYMENT_STATUS); // wait for payment status
if ($idOrder) {
$order = new Order($idOrder);
} elseif ($idCart && ($cardOrderId = Order::getIdByCartId($idCart))) {
$order = new Order($cardOrderId);
}
if (!$order && self::FETCH_LAST_ORDER) {
// last created order
$sql = new DbQuery();
$sql->select('max(id_order) as id');
$sql->from('orders');
$sql->where('id_customer = \'' . pSQL(Context::getContext()->customer->id) . '\'');
$lastInsert = Db::getInstance()->getRow($sql->build());
if (is_array($lastInsert)) {
$order = new Order($lastInsert['id']);
}
}
if ($order && ((int)$order->current_state === (int)Configuration::get('P24_ORDER_STATE_2'))) {
Tools::redirect(
$this->context->link->getModuleLink(
'przelewy24',
'paymentSuccessful',
array(),
'1' === (string)Configuration::get('PS_SSL_ENABLED')
)
);
} else {
if (($sleep < self::MAXIMUM_TRY) &&
!($order && ((int)$order->current_state === (int)Configuration::get('PS_OS_ERROR')))) {
// paymentStatus not yet processed
$sleep++;
$returnParamArray = ['sleep' => $sleep];
if ($idOrder) {
$returnParamArray['id_order'] = $idOrder;
} elseif ($idCart) {
$returnParamArray['id_cart'] = $idCart;
}
Tools::redirect(
$this->context->link->getModuleLink(
'przelewy24',
'paymentFinished',
$returnParamArray,
'1' === (string)Configuration::get('PS_SSL_ENABLED')
)
);
} else {
Tools::redirect(
$this->context->link->getModuleLink(
'przelewy24',
'paymentFailed',
$order ? array('id_order' => $order->id) : array(),
'1' === (string)Configuration::get('PS_SSL_ENABLED')
)
);
}
}
}
}

View File

@@ -0,0 +1,150 @@
<?php
/**
* Class przelewy24paymentStatusModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/gpl.html
*
*/
/**
* Class Przelewy24paymentStatusModuleFrontController
*/
class Przelewy24paymentStatusModuleFrontController extends ModuleFrontController
{
/**
* Process change of payment status.
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function postProcess()
{
try {
$this->postProcessInternal();
} catch (Przelewy24HttpException $ex) {
header('HTTP/1.1 ' . $ex->getCode() . ' ' . $ex->getMessage());
header('Content-Type: text/plain');
echo $ex->getCode(), ' ', $ex->getMessage();
}
exit;
}
/**
* Internal code to process change of payment status.
*
* @throws Przelewy24HttpException
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
private function postProcessInternal()
{
$logMessage = 'postProcess ' . var_export($_POST, true);
if (Tools::strlen($logMessage) >= Przelewy24Logger::LOG_MESSAGE_LIMIT) {
throw new Przelewy24HttpException('Payload Too Large', 413);
}
PrestaShopLogger::addLog($logMessage, 1);
if (Tools::getValue('p24_session_id')) {
PrestaShopLogger::addLog('przelewy24paymentStatusModuleFrontController', 1);
list($cartId) = explode('|', Tools::getValue('p24_session_id'), 1);
$cartId = (int)$cartId;
$cart = new Cart($cartId);
if (empty($cart) || !isset($cart->id) || $cartId < 1) {
throw new Przelewy24HttpException('Not Found', 404);
}
Context::getContext()->currency = Currency::getCurrencyInstance((int)$cart->id_currency);
$orderId = Order::getIdByCartId($cart->id);
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$idOrderState = (int)Configuration::get('P24_ORDER_STATE_1');
$customer = new Customer($cart->id_customer);
$currency = new Currency($cart->id_currency);
$addExtracharge = 0;
if (!$orderId) {
$this->module->validateOrder(
(int)$cart->id,
$idOrderState,
$total,
$this->module->displayName,
null,
array(),
(int)$currency->id,
false,
$customer->secure_key
);
$addExtracharge = 1;
$orderId = Order::getIdByCartId($cart->id);
}
if (1 === $addExtracharge) {
$servicePaymentOptions = new Przelewy24ServicePaymentOptions(new Przelewy24());
$servicePaymentOptions->setExtrachargeByOrderId($orderId);
}
$order = new Order($orderId);
$amount = Przelewy24Helper::p24AmountFormat($order->total_paid);
$currency = new Currency($order->id_currency);
$suffix = Przelewy24Helper::getSuffix($currency->iso_code);
$validation = array('p24_amount' => $amount, 'p24_currency' => $currency->iso_code);
$P24C = Przelewy24ClassInterfaceFactory::getForSuffix($suffix);
$trnVerify = $P24C->trnVerifyEx($validation);
PrestaShopLogger::addLog('postProcess trnVerify' . var_export($trnVerify, true), 1);
if (true === $trnVerify) {
$order->setCurrentState((int)Configuration::get('P24_ORDER_STATE_2'));
Przelewy24Order::saveOrder(
Tools::getValue('p24_order_id'),
$order->id,
Tools::getValue('p24_session_id')
);
if (Przelewy24OneClickHelper::isOneClickEnable($suffix)
&& in_array((int)Tools::getValue('p24_method'), Przelewy24OneClickHelper::getCardPaymentIds())
) {
if (Przelewy24CustomerSetting::initialize($order->id_customer)->card_remember) {
$p24Soap = Przelewy24SoapInterfaceFactory::getForSuffix($suffix);
$p24OrderId = (int)Tools::getValue('p24_order_id');
if (Configuration::get('P24_ONECLICK_ENABLE' . $suffix)) {
$res = $p24Soap->getCardReferenceOneClickWithCheckCard(
Configuration::get('P24_API_KEY' . $suffix),
$p24OrderId
);
if (!empty($res)) {
$expires = Tools::substr($res->cardExp, 2, 2) . Tools::substr($res->cardExp, 0, 2);
if (date('ym') <= $expires) {
Przelewy24Recurring::remember(
$order->id_customer,
$res->refId,
$expires,
$res->mask,
$res->cardType
);
} else {
PrestaShopLogger::addLog(
'Error: expiration date ' . var_export(
$expires,
true
),
1
);
}
}
}
} else {
PrestaShopLogger::addLog('Nie pamiętaj karty dla userID: ' . $order->id_customer, 1);
}
}
} else {
$order->setCurrentState((int)Configuration::get('PS_OS_ERROR'));
}
}
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Class przelewy24paymentSuccessfulModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24paymentSuccessfulModuleFrontController
*/
class Przelewy24paymentSuccessfulModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*/
public function initContent()
{
parent::initContent();
$this->context->smarty->assign(
array(
'logo_url' => $this->module->getPathUri() . 'views/img/logo.png',
'home_url' => _PS_BASE_URL_,
'urls' => $this->getTemplateVarUrls(),
)
);
$this->setTemplate('module:przelewy24/views/templates/front/payment_successful.tpl');
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* Class przelewy24validateOrderRequestModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24validateOrderRequestModuleFrontController
*/
class Przelewy24validateOrderRequestModuleFrontController extends ModuleFrontController
{
/**
* Init content.
*/
public function initContent()
{
parent::initContent();
/** @var CartCore $cart */
$cart = Context::getContext()->cart;
/** @var CustomerCore $customer */
$customer = Context::getContext()->customer;
$requestCartId = (int)Tools::getValue('cartId');
$currency = new Currency($cart->id_currency);
$suffix = Przelewy24Helper::getSuffix($currency->iso_code);
if ($requestCartId === (int)$cart->id) {
if ($cart && (2 === (int)Configuration::get('P24_VERIFYORDER' . $suffix))) {
$orderId = (int)Order::getIdByCartId($cart->id);
if (!$cart->OrderExists()) {
$amount = $cart->getOrderTotal(true, Cart::BOTH);
$orderBeginingState = Configuration::get('P24_ORDER_STATE_1');
$this->module->validateOrder(
(int)$cart->id,
(int)$orderBeginingState,
(float)$amount,
$this->module->displayName,
null,
array(),
(int)$cart->id_currency,
false,
$customer->secure_key
);
$servicePaymentOptions = new Przelewy24ServicePaymentOptions(new Przelewy24());
$servicePaymentOptions->setExtrachargeByOrderId($orderId);
}
Przelewy24Helper::renderJson(
array(
'orderId' => $orderId,
'description' => $this->module->l('Order') . ' ' . $orderId,
)
);
}
}
Przelewy24Helper::renderJson(array());
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Class przelewy24validationBlikModuleFrontController
*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*
*/
/**
* Class Przelewy24validationBlikModuleFrontController
*/
class Przelewy24validationBlikModuleFrontController extends ModuleFrontController
{
/**
* Post process.
*/
public function postProcess()
{
if (preg_match('/[^a-z_\-0-9 ]/i', Tools::getValue('p24_blik_code'))
|| preg_match('/[^a-z_\-0-9 ]/i', Tools::getValue('type'))) {
// zwrócić odpowiedź z httpStatus zamiast die
die("Invalid string");
}
$cart = $this->context->cart;
$currency = $this->context->currency;
if ((0 === (int)$cart->id_customer) || (0 === (int)$cart->id_address_delivery) ||
(0 === (int)$cart->id_address_invoice) || !$this->module->active) {
Tools::redirect('index.php?controller=order&step=1');
}
$customer = new Customer($cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
Tools::redirect('index.php?controller=order&step=1');
}
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$idOrderState = Configuration::get('P24_ORDER_STATE_1');
$this->module->validateOrder(
(int)$cart->id,
$idOrderState,
$total,
$this->module->displayName,
null,
array(),
(int)$currency->id,
false,
$customer->secure_key
);
$paymentMethod = '&blik_type=UID'; // default is UID
$toolsType = Tools::getValue('type');
if (!empty($toolsType)) {
$paymentMethod = '&blik_type=' . Tools::getValue('type');
}
if (Tools::getValue('p24_blik_code')) {
$blikCode = '&blik_code=' . Tools::getValue('p24_blik_code');
}
Tools::redirect(
'index.php?controller=order-confirmation&id_cart=' . (int)$cart->id .
'&id_module=' . (int)$this->module->id .
'&id_order=' . $this->module->currentOrder .
'&key=' . $customer->secure_key .
$paymentMethod . (isset($blikCode) ? $blikCode : '')
);
}
}