This commit is contained in:
2025-03-21 20:24:43 +01:00
parent 224398df90
commit f34c9162d4
12427 changed files with 5329941 additions and 373384 deletions

View File

@@ -17,6 +17,9 @@ if (!defined('_PS_VERSION_')) {
include_once(dirname(__FILE__) . '/vendor/autoload.php');
include_once(dirname(__FILE__) . '/classes/PaynowFrontController.php');
include_once(dirname(__FILE__) . '/classes/PaynowLogger.php');
include_once(dirname(__FILE__) . '/classes/PaynowHelper.php');
include_once(dirname(__FILE__) . '/classes/PaynowNotificationRetryProcessing.php');
include_once(dirname(__FILE__) . '/classes/PaynowNotificationStopProcessing.php');
include_once(dirname(__FILE__) . '/classes/PaynowConfigurationHelper.php');
include_once(dirname(__FILE__) . '/classes/PaynowPaymentMethodsHelper.php');
include_once(dirname(__FILE__) . '/classes/PaynowPaymentAuthorizeException.php');
@@ -32,6 +35,7 @@ include_once(dirname(__FILE__) . '/classes/PaynowFrontController.php');
include_once(dirname(__FILE__) . '/classes/PaynowPaymentProcessor.php');
include_once(dirname(__FILE__) . '/classes/PaynowPaymentDataBuilder.php');
include_once(dirname(__FILE__) . '/classes/PaynowGithubClient.php');
include_once(dirname(__FILE__) . '/classes/PaynowLockingHelper.php');
class Paynow extends PaymentModule
{
@@ -43,7 +47,7 @@ class Paynow extends PaymentModule
{
$this->name = 'paynow';
$this->tab = 'payments_gateways';
$this->version = '1.6.18';
$this->version = '1.6.35';
$this->ps_versions_compliancy = ['min' => '1.6.0', 'max' => _PS_VERSION_];
$this->author = 'mElements S.A.';
$this->is_eu_compatible = 1;
@@ -102,6 +106,9 @@ class Paynow extends PaymentModule
`status` varchar(64) NOT NULL,
`total` DECIMAL(20,6) NOT NULL DEFAULT \'0.000000\',
`locked` TINYINT(1) NOT NULL DEFAULT 0,
`active` tinyint(1) NOT NULL DEFAULT 0,
`counter` tinyint(1) NOT NULL DEFAULT 0,
`sent_at` datetime DEFAULT NULL,
`created_at` datetime,
`modified_at` datetime,
UNIQUE (`id_payment`, `status`),
@@ -111,14 +118,19 @@ class Paynow extends PaymentModule
private function registerHooks()
{
$registerStatus = $this->registerHook('header') &&
$this->registerHook('displayOrderDetail') &&
$registerStatus = $this->registerHook('displayOrderDetail') &&
$this->registerHook('actionOrderStatusPostUpdate') &&
$this->registerHook('actionOrderSlipAdd') &&
$this->registerHook('displayAdminOrder') &&
$this->registerHook('displayAdminAfterHeader') &&
$this->registerHook('actionAdminControllerSetMedia');
if (version_compare(_PS_VERSION_, '8.1', 'ge')) {
$registerStatus &= $this->registerHook('displayHeader');
} else {
$registerStatus &= $this->registerHook('header');
}
if (version_compare(_PS_VERSION_, '1.7', 'lt')) {
$registerStatus &= $this->registerHook('payment') &&
$this->registerHook('displayPaymentEU');
@@ -134,13 +146,19 @@ class Paynow extends PaymentModule
private function unregisterHooks()
{
$registerStatus = $this->unregisterHook('header') &&
$this->unregisterHook('displayOrderDetail') &&
$registerStatus = $this->unregisterHook('displayOrderDetail') &&
$this->unregisterHook('actionOrderStatusPostUpdate') &&
$this->unregisterHook('actionOrderSlipAdd') &&
$this->unregisterHook('displayAdminOrderTop') &&
$this->unregisterHook('displayAdminOrder') &&
$this->unregisterHook('displayAdminAfterHeader') &&
$this->unregisterHook('actionAdminControllerSetMedia');
if (version_compare(_PS_VERSION_, '8.1', 'ge')) {
$registerStatus &= $this->unregisterHook('displayHeader');
} else {
$registerStatus &= $this->unregisterHook('header');
}
if (version_compare(_PS_VERSION_, '1.7', 'lt')) {
$registerStatus &= $this->unregisterHook('displayPaymentEU') &&
$this->unregisterHook('payment');
@@ -160,6 +178,7 @@ class Paynow extends PaymentModule
Configuration::updateValue('PAYNOW_REFUNDS_ON_STATUS', Configuration::get('PS_OS_REFUND')) &&
Configuration::updateValue('PAYNOW_REFUNDS_WITH_SHIPPING_COSTS', 0) &&
Configuration::updateValue('PAYNOW_SEPARATE_PAYMENT_METHODS', 1) &&
Configuration::updateValue('PAYNOW_HIDE_PAYMENT_TYPES', '') &&
Configuration::updateValue('PAYNOW_PROD_API_KEY', '') &&
Configuration::updateValue('PAYNOW_PROD_API_SIGNATURE_KEY', '') &&
Configuration::updateValue('PAYNOW_SANDBOX_ENABLED', 0) &&
@@ -174,7 +193,10 @@ class Paynow extends PaymentModule
Configuration::updateValue('PAYNOW_PAYMENT_VALIDITY_TIME', 86400) &&
Configuration::updateValue('PAYNOW_ORDER_ABANDONED_STATE', Configuration::get('PAYNOW_ORDER_INITIAL_STATE')) &&
Configuration::updateValue('PAYNOW_ORDER_EXPIRED_STATE', Configuration::get('PAYNOW_ORDER_INITIAL_STATE')) &&
Configuration::updateValue('PAYNOW_CREATE_ORDER_STATE', 1);
Configuration::updateValue('PAYNOW_CREATE_ORDER_STATE', 1) &&
Configuration::updateValue('PAYNOW_RETRY_PAYMENT_BUTTON_ENABLED', 1) &&
Configuration::updateValue('PAYNOW_RETRY_BUTTON_ORDER_STATE', join(',', [8,20,12])) &&
Configuration::updateValue('PAYNOW_BLIK_AUTOFOCUS_ENABLED', 1);
}
private function deleteModuleSettings()
@@ -186,6 +208,7 @@ class Paynow extends PaymentModule
Configuration::deleteByName('PAYNOW_REFUNDS_ON_STATUS') &&
Configuration::deleteByName('PAYNOW_REFUNDS_WITH_SHIPPING_COSTS') &&
Configuration::deleteByName('PAYNOW_SEPARATE_PAYMENT_METHODS') &&
Configuration::deleteByName('PAYNOW_HIDE_PAYMENT_TYPES') &&
Configuration::deleteByName('PAYNOW_PROD_API_KEY') &&
Configuration::deleteByName('PAYNOW_PROD_API_SIGNATURE_KEY') &&
Configuration::deleteByName('PAYNOW_SANDBOX_ENABLED') &&
@@ -199,7 +222,10 @@ class Paynow extends PaymentModule
Configuration::deleteByName('PAYNOW_PAYMENT_VALIDITY_TIME') &&
Configuration::deleteByName('PAYNOW_ORDER_ABANDONED_STATE') &&
Configuration::deleteByName('PAYNOW_ORDER_EXPIRED_STATE') &&
Configuration::deleteByName('PAYNOW_CREATE_ORDER_STATE');
Configuration::deleteByName('PAYNOW_CREATE_ORDER_STATE') &&
Configuration::deleteByName('PAYNOW_RETRY_PAYMENT_BUTTON_ENABLED') &&
Configuration::deleteByName('PAYNOW_RETRY_BUTTON_ORDER_STATE') &&
Configuration::deleteByName('PAYNOW_BLIK_AUTOFOCUS_ENABLED');
}
public function createOrderInitialState()
@@ -285,6 +311,27 @@ class Paynow extends PaymentModule
return !empty($this->getApiKey()) && !empty($this->getSignatureKey());
}
private function showRetryButton(array $params): bool
{
if ((int)Configuration::get('PAYNOW_RETRY_PAYMENT_BUTTON_ENABLED') === 0) {
return false;
}
/** @var \PrestaShop\PrestaShop\Adapter\Entity\Order $order */
$order = $params['order'] ?? null;
if ($order === null) {
return false;
}
$paynowPaymentData = PaynowPaymentData::findLastByOrderId($order->id);
if ($paynowPaymentData === false) {
return false;
}
$retryBtnOrderStates = explode(',', Configuration::get('PAYNOW_RETRY_BUTTON_ORDER_STATE'));
return in_array($order->getCurrentState(), $retryBtnOrderStates);
}
public function checkCurrency($cart): bool
{
$currency_order = new Currency($cart->id_currency);
@@ -306,19 +353,31 @@ class Paynow extends PaymentModule
ContextCore::getContext()->controller->addJs(($this->_path) . 'views/js/front.js', 'all');
}
/**
* Prestashop 8.1 compatibility
*
* @return void
*/
public function hookDisplayHeader()
{
$this->hookHeader();
}
public function getPaymentMethodTitle($payment_method_type): string
{
switch ($payment_method_type) {
default:
return '';
case \Paynow\Model\PaymentMethods\Type::BLIK:
return $this->l('Pay by Blik');
return $this->l('Pay by BLIK');
case \Paynow\Model\PaymentMethods\Type::CARD:
return $this->l('Pay by card');
case \Paynow\Model\PaymentMethods\Type::PBL:
return $this->l('Pay by online transfer');
case \Paynow\Model\PaymentMethods\Type::GOOGLE_PAY:
return $this->l('Pay by Google Pay');
case \Paynow\Model\PaymentMethods\Type::APPLE_PAY:
return $this->l('Pay by Apple Pay');
}
}
@@ -362,6 +421,7 @@ class Paynow extends PaymentModule
$this->getPaymentMethods(),
$this->getGDPRNotices()
);
return $payment_options->generate();
}
@@ -405,8 +465,10 @@ class Paynow extends PaymentModule
]
),
'action_token' => Tools::encrypt($this->context->customer->secure_key),
'action_token_refresh' => Context::getContext()->link->getModuleLink('paynow', 'customerToken'),
'error_message' => $this->getTranslationsArray()['An error occurred during the payment process'],
'terms_message' => $this->getTranslationsArray()['You have to accept terms and conditions']
'terms_message' => $this->getTranslationsArray()['You have to accept terms and conditions'],
'blik_autofocus' => Configuration::get('PAYNOW_BLIK_AUTOFOCUS_ENABLED') === '0' ? '0' : '1',
]);
}
array_push($payment_options, [
@@ -445,7 +507,7 @@ class Paynow extends PaymentModule
public function hookDisplayOrderDetail($params)
{
if (!$this->isActive()) {
if (!$this->isActive() || !$this->showRetryButton($params)) {
return;
}
@@ -495,8 +557,14 @@ class Paynow extends PaymentModule
$this->context->controller instanceof AdminController) {
$order = new Order($params['id_order']);
$newOrderStatus = $params['newOrderStatus'];
$logContext = [
'params_id_order' => $params['id_order'],
'params_new_order_status' => $params['newOrderStatus'],
'order_id' => $order->id,
];
PaynowLogger::info('Refunds: after change status triggered.', $logContext);
if ((int)Configuration::get('PAYNOW_REFUNDS_ON_STATUS') === $newOrderStatus->id) {
PaynowLogger::info('Refunds: PaynowRefundProcessor->processFromOrderStatusChange()', $logContext);
(new PaynowRefundProcessor($this->getPaynowClient(), $this->displayName))
->processFromOrderStatusChange($order);
}
@@ -601,6 +669,22 @@ class Paynow extends PaymentModule
!Validate::isInt(Tools::getValue('PAYNOW_PAYMENT_VALIDITY_TIME'))) {
$this->postErrors[] = $this->l('Payment validity time must be integer');
}
$uuv4Fields = [
'PAYNOW_SANDBOX_API_KEY' => $this->l('Incorrect API key format (sandbox)'),
'PAYNOW_SANDBOX_API_SIGNATURE_KEY' => $this->l('Incorrect API signature key format (sandbox)'),
'PAYNOW_PROD_API_KEY' => $this->l('Incorrect API key format (production)'),
'PAYNOW_PROD_API_SIGNATURE_KEY' => $this->l('Incorrect API signature key format (production)')
];
foreach ($uuv4Fields as $field => $message) {
if (empty(Tools::getValue($field))) {
continue;
}
$regex = '/^[[:xdigit:]]{8}(?:\-[[:xdigit:]]{4}){3}\-[[:xdigit:]]{12}$/i';
if (!preg_match($regex, Tools::getValue($field))) {
$this->postErrors[] = $message;
}
}
}
}
@@ -706,6 +790,7 @@ class Paynow extends PaymentModule
'Awaiting payment confirmation' => $this->l('Awaiting payment confirmation'),
'Payment has been authorized by the buyer' => $this->l('Payment has been authorized by the buyer'),
'Payment has not been authorized by the buyer' => $this->l('Payment has not been authorized by the buyer'),
'An error occurred during the cart validation' => $this->l('An error occurred during the cart validation'),
'An error occurred during the payment process and the payment could not be completed' => $this->l('An error occurred during the payment process and the payment could not be completed'),
'An error occurred during the payment process' => $this->l('An error occurred during the payment process.'),
'Payment has been abandoned by the buyer' => $this->l('Payment has been abandoned by the buyer'),
@@ -717,6 +802,7 @@ class Paynow extends PaymentModule
'Include shipping costs' => $this->l('Include shipping costs'),
'Additional options' => $this->l('Additional options'),
'Show separated payment methods' => $this->l('Show separated payment methods'),
'Hide payment types' => $this->l('Hide payment types'),
'Use order-confirmation page as shop\'s return URL' => $this->l('Use order-confirmation page as shop\'s return URL'),
'Buyer will be redirected to order-confirmation page after payment.' => $this->l('Buyer will be redirected to order-confirmation page after payment.'),
'Send order items' => $this->l('Send order items'),
@@ -736,7 +822,12 @@ class Paynow extends PaymentModule
'You have to accept terms and conditions' => $this->l('You have to accept terms and conditions'),
'Moment of creating order' => $this->l('Moment of creating order'),
'On clicking the Place order' => $this->l('On clicking the Place order'),
'After the successful Paynow payment' => $this->l('After the successful Paynow payment')
'After the successful Paynow payment' => $this->l('After the successful Paynow payment'),
'Show retry payment button' => $this->l('Show retry payment button'),
'The button appears on the order details screen.' => $this->l('The button appears on the order details screen.'),
'Show retry payment button on selected statuses' => $this->l('Show retry payment button on selected statuses'),
'BLIK field autofocus' => $this->l('BLIK field autofocus'),
'Autofocus on checkout form field: BLIK code. Enabled by default. Disabling may be helpful when checkout page is visualy long (e.g. single-page checkout).' => $this->l('Autofocus on checkout form field: BLIK code. Enabled by default. Disabling may be helpful when checkout page is visualy long (e.g. single-page checkout).'),
];
}
}