Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TheCheckout compatibility #208

Merged
merged 91 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
f2fc6c8
added action
MarijusCoding Oct 9, 2024
fe89f11
added css to image sizes
MarijusCoding Oct 9, 2024
76fb165
wip
MarijusCoding Oct 9, 2024
fd50112
wip
MarijusCoding Oct 9, 2024
4b7b538
structurization
MarijusCoding Oct 9, 2024
dc6a275
added structure
MarijusCoding Oct 10, 2024
75b9fe4
thecheckout compatibility
MarijusCoding Oct 10, 2024
8c580c4
cleanup
MarijusCoding Oct 10, 2024
e538a2b
fix
MarijusCoding Oct 10, 2024
2be327c
fix
MarijusCoding Oct 10, 2024
f84a99c
fix
MarijusCoding Oct 10, 2024
0cfc5ef
fix
MarijusCoding Oct 10, 2024
81577a5
revert
MarijusCoding Oct 10, 2024
2aa3a90
revert
MarijusCoding Oct 10, 2024
9d09e52
full compatibility
MarijusCoding Oct 10, 2024
616e150
fix js
MarijusCoding Oct 10, 2024
1d643dc
fix
MarijusCoding Oct 10, 2024
759761d
fix
MarijusCoding Oct 11, 2024
db25893
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 11, 2024
23f292d
removed JS
MarijusCoding Oct 11, 2024
85da886
load only in checkout
MarijusCoding Oct 11, 2024
d507b9b
css n js
MarijusCoding Oct 11, 2024
9875c3a
fixed bug
MarijusCoding Oct 11, 2024
00b6fb0
reusability
MarijusCoding Oct 11, 2024
7cb7d7e
fix
MarijusCoding Oct 11, 2024
9d91a0b
fix
MarijusCoding Oct 11, 2024
baa923b
fix
MarijusCoding Oct 11, 2024
b18be44
comment
MarijusCoding Oct 11, 2024
ac84ca9
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 11, 2024
fadaeec
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 11, 2024
05c55fe
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 12, 2024
adb3b2c
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 12, 2024
582da6f
license
MarijusCoding Oct 13, 2024
ed9256c
fix
MarijusCoding Oct 13, 2024
59cc882
fix
MarijusCoding Oct 13, 2024
d5b2d42
fix
MarijusCoding Oct 14, 2024
ff26d2e
fix
MarijusCoding Oct 14, 2024
0425e66
fix var
MarijusCoding Oct 14, 2024
c4eb3be
fix
MarijusCoding Oct 14, 2024
9bd99a6
fix
MarijusCoding Oct 14, 2024
d8a70d0
fix
MarijusCoding Oct 14, 2024
7bb5557
fix
MarijusCoding Oct 14, 2024
13292ae
fix
MarijusCoding Oct 14, 2024
3683d20
fix
MarijusCoding Oct 14, 2024
1af6c97
fix css
MarijusCoding Oct 14, 2024
264a526
fix
MarijusCoding Oct 14, 2024
8f8724b
Merge branch 'SV-28/thecheckout' of github.com:Invertus/saferpayoffic…
MarijusCoding Oct 14, 2024
fff2742
fi
MarijusCoding Oct 14, 2024
6d07fe2
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 15, 2024
72ef707
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 15, 2024
48bd536
fix
MarijusCoding Oct 15, 2024
096f5dc
fix
MarijusCoding Oct 15, 2024
f0a2260
update
MarijusCoding Oct 15, 2024
9449f0a
comments
MarijusCoding Oct 15, 2024
6a66534
fix
MarijusCoding Oct 15, 2024
9392a98
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 15, 2024
e3732db
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 15, 2024
587280a
unused use statement
MarijusCoding Oct 16, 2024
ab2a4b8
added if to work only in checkout
MarijusCoding Oct 16, 2024
0759cc4
updated js selector
MarijusCoding Oct 16, 2024
3b99709
fix
MarijusCoding Oct 16, 2024
d0e20a5
fix
MarijusCoding Oct 16, 2024
d1c5129
fix
MarijusCoding Oct 16, 2024
c0c2c96
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 17, 2024
16031cd
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 17, 2024
3e6440b
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 17, 2024
7ad57f3
fix conf
MarijusCoding Oct 17, 2024
092ff2d
added compatibility opcps
MarijusCoding Oct 17, 2024
38db797
compatibility
MarijusCoding Oct 17, 2024
e3bbf9c
revert
MarijusCoding Oct 17, 2024
e310a39
revert
MarijusCoding Oct 17, 2024
f5b367a
revert
MarijusCoding Oct 17, 2024
857ba82
revert
MarijusCoding Oct 17, 2024
0b7ffd7
Revert "revert"
MarijusCoding Oct 17, 2024
71bc3c1
Revert "revert"
MarijusCoding Oct 17, 2024
8401319
Revert "revert"
MarijusCoding Oct 17, 2024
65cec16
Revert "revert"
MarijusCoding Oct 17, 2024
dd2a277
fix
MarijusCoding Oct 18, 2024
7991127
fix
MarijusCoding Oct 18, 2024
3ad9df9
removed config
MarijusCoding Oct 18, 2024
b5d5944
fix
MarijusCoding Oct 18, 2024
a6f6d63
Merge branch 'SV-28/thecheckout' of github.com:Invertus/saferpayoffic…
MarijusCoding Oct 18, 2024
ab141d7
fix
MarijusCoding Oct 18, 2024
ed53990
fix
MarijusCoding Oct 18, 2024
ff483c5
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 20, 2024
ede7712
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 20, 2024
54528d8
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 20, 2024
066d638
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 20, 2024
c2b0d5c
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 22, 2024
3962abe
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
MarijusCoding Oct 22, 2024
f34b434
Merge pull request #209 from Invertus/SV-29/checkoutps
MarijusCoding Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions saferpayofficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,31 +344,19 @@ public function hookDisplayAdminOrder(array $params)

public function hookActionFrontControllerSetMedia()
{
/** @var \Invertus\SaferPay\Validation\ValidateIsAssetsRequired $validateIsAssetsRequired */
$validateIsAssetsRequired = $this->getService(\Invertus\SaferPay\Validation\ValidateIsAssetsRequired::class);

if (!$validateIsAssetsRequired->run($this->context->controller)) {
return;
}

/** @var \Invertus\SaferPay\Presentation\Loader\PaymentFormAssetLoader $paymentFormAssetsLoader */
$paymentFormAssetsLoader = $this->getService(\Invertus\SaferPay\Presentation\Loader\PaymentFormAssetLoader::class);

$paymentFormAssetsLoader->register($this->context->controller);

if ($this->context->controller instanceof OrderController) {
if (\Invertus\SaferPay\Config\SaferPayConfig::isVersion17()) {
$this->context->controller->registerJavascript(
'saved-card',
'modules/' . $this->name . '/views/js/front/saferpay_saved_card.js'
);

$this->context->controller->addCSS("{$this->getPathUri()}views/css/front/saferpay_checkout.css");
} else {
$this->context->controller->addCSS("{$this->getPathUri()}views/css/front/saferpay_checkout_16.css");
$this->context->controller->addJS("{$this->getPathUri()}views/js/front/saferpay_saved_card_16.js");
$fieldsLibrary = \Invertus\SaferPay\Config\SaferPayConfig::FIELDS_LIBRARY;
$configSuffix = \Invertus\SaferPay\Config\SaferPayConfig::getConfigSuffix();
$this->context->controller->addJs(Configuration::get($fieldsLibrary . $configSuffix));
}

/** @var \Invertus\SaferPay\Service\SaferPayErrorDisplayService $errorDisplayService */
$errorDisplayService = $this->getService(\Invertus\SaferPay\Service\SaferPayErrorDisplayService::class);
$errorDisplayService->showCookieError('saferpay_payment_canceled_error');
}
$paymentFormAssetsLoader->registerErrorBags();
}

public function hookDisplayCustomerAccount()
Expand Down
9 changes: 9 additions & 0 deletions src/Config/SaferPayConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ class SaferPayConfig
const LOG_SEVERITY_LEVEL_MAJOR = 4;
const TRANSACTION_ALREADY_CAPTURED = 'TRANSACTION_ALREADY_CAPTURED';

const ONE_PAGE_CHECKOUT_MODULE = 'onepagecheckoutps';
const THE_CHECKOUT_MODULE = 'thecheckout';
const SUPER_CHECKOUT_MODULE = 'supercheckout';
const OPC_MODULE_LIST = [
self::ONE_PAGE_CHECKOUT_MODULE,
self::THE_CHECKOUT_MODULE,
self::SUPER_CHECKOUT_MODULE,
];

public static function supportsOrderCapture($paymentMethod)
{
//payments that DOES NOT SUPPORT capture
Expand Down
88 changes: 83 additions & 5 deletions src/Presentation/Loader/PaymentFormAssetLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@

namespace Invertus\SaferPay\Presentation\Loader;

use Configuration;
use Invertus\SaferPay\Adapter\LegacyContext;
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Enum\ControllerName;
use Invertus\SaferPay\Enum\PaymentType;
use Invertus\SaferPay\Factory\ModuleFactory;
use Invertus\SaferPay\Provider\OpcModulesProvider;
use Media;
use OrderControllerCore;
use SaferPayOfficial;
Expand All @@ -41,19 +44,18 @@ class PaymentFormAssetLoader
private $module;
/** @var LegacyContext */
private $context;
/** @var OpcModulesProvider $opcModuleProvider */
private $opcModulesProvider;

public function __construct(ModuleFactory $module, LegacyContext $context)
public function __construct(ModuleFactory $module, LegacyContext $context, OpcModulesProvider $opcModulesProvider)
{
$this->module = $module->getModule();
$this->context = $context;
$this->opcModulesProvider = $opcModulesProvider;
}

public function register($controller)
{
if (!$controller instanceof OrderControllerCore) {
return;
}

Media::addJsDef([
'saferpay_official_ajax_url' => $this->context->getLink()->getModuleLink('saferpayofficial', ControllerName::AJAX),
'saferpay_payment_types' => [
Expand All @@ -63,17 +65,85 @@ public function register($controller)
],
]);

$opcModule = $this->opcModulesProvider->get();

switch ($opcModule) {
case SaferPayConfig::ONE_PAGE_CHECKOUT_MODULE:
$this->registerOnePageCheckoutAssets($controller);
break;
case SaferPayConfig::THE_CHECKOUT_MODULE:
$this->registerTheCheckoutAssets($controller);
break;
case SaferPayConfig::SUPER_CHECKOUT_MODULE:
$this->registerSuperCheckoutAssets($controller);
break;
default:
$this->registerDefaultCheckoutAssets($controller);
}
}

private function registerOnePageCheckoutAssets($controller)
{
// TODO: will be implemented in other branches
}

private function registerTheCheckoutAssets($controller)
{
if (!$controller instanceof \TheCheckoutModuleFrontController) {
return;
}

$controller->addCSS("{$this->module->getPathUri()}views/css/front/saferpay_checkout.css");

if (method_exists($controller, 'registerJavascript')) {
$controller->registerJavascript(
'saved_card_hosted_fields_opc',
"modules/saferpayofficial/views/js/front/opc/thecheckout/hosted_fields.js"
);
} else {
$controller->addJs(
$this->module->getPathUri() . 'views/js/front/opc/thecheckout/hosted_fields.js',
false
);
}
}

private function registerSuperCheckoutAssets($controller)
{
// TODO: will be implemented in other branches
}

private function registerDefaultCheckoutAssets($controller)
{
if (!$controller instanceof OrderControllerCore) {
return;
}

if (method_exists($controller, 'registerJavascript')) {
if (\Invertus\SaferPay\Config\SaferPayConfig::isVersion17()) {
$controller->registerJavascript(
'saved_card_hosted_fields',
"modules/saferpayofficial/views/js/front/hosted-templates/hosted_fields.js"
);

$controller->registerJavascript(
'saved-card',
'modules/' . $this->module->name . '/views/js/front/saferpay_saved_card.js'
);

$controller->registerStylesheet("",
"{$this->module->getPathUri()}views/css/front/saferpay_checkout.css");
} else {
$controller->registerJavascript(
'saved_card_hosted_fields',
"modules/saferpayofficial/views/js/front/hosted-templates/hosted_fields_16.js"
);

$controller->addCSS("{$this->module->getPathUri()}views/css/front/saferpay_checkout_16.css");
$controller->addJS("{$this->module->getPathUri()}views/js/front/saferpay_saved_card_16.js");
$fieldsLibrary = \Invertus\SaferPay\Config\SaferPayConfig::FIELDS_LIBRARY;
$configSuffix = \Invertus\SaferPay\Config\SaferPayConfig::getConfigSuffix();
$controller->addJs(Configuration::get($fieldsLibrary . $configSuffix));
}
} else {
if (\Invertus\SaferPay\Config\SaferPayConfig::isVersion17()) {
Expand All @@ -89,4 +159,12 @@ public function register($controller)
}
}
}

public function registerErrorBags()
{
/** @var \Invertus\SaferPay\Service\SaferPayErrorDisplayService $errorDisplayService */
$errorDisplayService = $this->module->getService(\Invertus\SaferPay\Service\SaferPayErrorDisplayService::class);

$errorDisplayService->showCookieError('saferpay_payment_canceled_error');
}
}
47 changes: 47 additions & 0 deletions src/Provider/OpcModulesProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
*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 [email protected] 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 INVERTUS UAB www.invertus.eu <[email protected]>
*@copyright SIX Payment Services
*@license SIX Payment Services
*/

namespace Invertus\SaferPay\Provider;

use Invertus\SaferPay\Config\SaferPayConfig;

if (!defined('_PS_VERSION_')) {
exit;
}

class OpcModulesProvider
{
/**
* @return string
*/
public function get()
{
foreach (SaferPayConfig::OPC_MODULE_LIST as $opcModule){
if (\Module::isInstalled($opcModule) && \Module::isEnabled($opcModule)) {
return $opcModule;
}
}

return '';
}
}
56 changes: 56 additions & 0 deletions src/Validation/ValidateIsAssetsRequired.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
*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 [email protected] 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 INVERTUS UAB www.invertus.eu <[email protected]>
*@copyright SIX Payment Services
*@license SIX Payment Services
*/

namespace Invertus\SaferPay\Validation;

use Invertus\SaferPay\Provider\OpcModulesProvider;
use FrontController;

if (!defined('_PS_VERSION_')) {
exit;
}

class ValidateIsAssetsRequired
{
private $opcModulesProvider;

public function __construct(OpcModulesProvider $opcModulesProvider)
{
$this->opcModulesProvider = $opcModulesProvider;
}

/**
* It returns true if it's an OPC controller or an OrderController with products in the cart. Otherwise, it returns false.
*/
public function run(FrontController $controller)
{
$isOrderController = $controller instanceof \OrderControllerCore
|| $controller instanceof \ModuleFrontController && isset($controller->php_self) && $controller->php_self === 'order';

if (!empty($this->opcModulesProvider->get($controller))) {
return $isOrderController && !empty(\Context::getContext()->cart->getProducts());
}

return true;
}
}
8 changes: 8 additions & 0 deletions views/css/front/saferpay_checkout.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@
.payment-option img {
height: 24px;
}

.payment-logo {
max-width: 40px;
}

.payment-logo {
max-width: 40px;
}
Loading