Skip to content

Commit

Permalink
Merge pull request #209 from Invertus/SV-29/checkoutps
Browse files Browse the repository at this point in the history
One Page Checkout PS + Super Checkout compatibility
  • Loading branch information
MarijusCoding authored Oct 22, 2024
2 parents 3962abe + c2b0d5c commit f34b434
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/Presentation/Loader/PaymentFormAssetLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Configuration;
use Invertus\SaferPay\Adapter\LegacyContext;
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\DTO\Request\Order;
use Invertus\SaferPay\Enum\ControllerName;
use Invertus\SaferPay\Enum\PaymentType;
use Invertus\SaferPay\Factory\ModuleFactory;
Expand Down Expand Up @@ -84,7 +85,23 @@ public function register($controller)

private function registerOnePageCheckoutAssets($controller)
{
// TODO: will be implemented in other branches
if (!$controller instanceof \OrderControllerCore) {
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/onepagecheckoutps/hosted_fields.js"
);
} else {
$controller->addJs(
$this->module->getPathUri() . 'views/js/front/opc/onepagecheckoutps/hosted_fields.js',
false
);
}
}

private function registerTheCheckoutAssets($controller)
Expand All @@ -110,7 +127,23 @@ private function registerTheCheckoutAssets($controller)

private function registerSuperCheckoutAssets($controller)
{
// TODO: will be implemented in other branches
if (!$controller instanceof \SupercheckoutSupercheckoutModuleFrontController) {
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/supercheckout/hosted_fields.js"
);
} else {
$controller->addJs(
$this->module->getPathUri() . 'views/js/front/opc/supercheckout/hosted_fields.js',
false
);
}
}

private function registerDefaultCheckoutAssets($controller)
Expand Down
13 changes: 13 additions & 0 deletions views/css/front/saferpay_checkout.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@
.payment-logo {
max-width: 40px;
}

input[type="radio"][name^="saved_card_"] {
opacity: 1 !important;
width: 15px !important;
position: relative !important;
vertical-align: middle !important;
margin: 0 !important;
}
.saved_credit_cards span {
padding-left: 3px !important;
vertical-align: middle !important;
margin: 0 !important;
}
59 changes: 59 additions & 0 deletions views/js/front/opc/onepagecheckoutps/hosted_fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
*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
*/

$(document).ready(function () {
$('body').on('change', "input[name^='saved_card_']", function () {
var $selectedCard = $(this);
var method = $selectedCard.closest('div.saved_cards').find('.saved_card_method').val();
$("input[name='selectedCreditCard_" + method + "']").val($selectedCard.val());
});
});

$('body').on('submit', '[id^=pay-with-][id$=-form] form', function (event) {
event.preventDefault();

var selectedCardMethod = $(this).find("[name=saved_card_method]").val();
var selectedCard = $(this).find("[name=selectedCreditCard_" + selectedCardMethod + "]").val();

//NOTE: not saved card chosen, continuing with normal procedures.
if (selectedCard <= 0) {
event.target.submit();

return;
}

$.ajax(saferpay_official_ajax_url, {
method: 'POST',
data: {
action: 'submitHostedFields',
paymentMethod: selectedCardMethod,
selectedCard: selectedCard,
isBusinessLicence: 1,
ajax: 1
},
success: function (response) {
var data = jQuery.parseJSON(response);

window.location = data.url;
},
});
});
59 changes: 59 additions & 0 deletions views/js/front/opc/supercheckout/hosted_fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
*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
*/

$(document).ready(function () {
$('body').on('change', "input[name^='saved_card_']", function () {
var $selectedCard = $(this);
var method = $selectedCard.closest('div.saved_cards').find('.saved_card_method').val();
$("input[name='selectedCreditCard_" + method + "']").val($selectedCard.val());
});
});

$('body').on('submit', '[id^=pay-with-][id$=-form] form', function (event) {
event.preventDefault();

var selectedCardMethod = $(this).find("[name=saved_card_method]").val();
var selectedCard = $(this).find("[name=selectedCreditCard_" + selectedCardMethod + "]").val();

//NOTE: not saved card chosen, continuing with normal procedures.
if (selectedCard <= 0) {
event.target.submit();

return;
}

$.ajax(saferpay_official_ajax_url, {
method: 'POST',
data: {
action: 'submitHostedFields',
paymentMethod: selectedCardMethod,
selectedCard: selectedCard,
isBusinessLicence: 1,
ajax: 1
},
success: function (response) {
var data = jQuery.parseJSON(response);

window.location = data.url;
},
});
});

0 comments on commit f34b434

Please sign in to comment.