diff --git a/controllers/admin/AdminSaferPayOfficialSettingsController.php b/controllers/admin/AdminSaferPayOfficialSettingsController.php index 794cb4b4..76a449d7 100755 --- a/controllers/admin/AdminSaferPayOfficialSettingsController.php +++ b/controllers/admin/AdminSaferPayOfficialSettingsController.php @@ -56,12 +56,24 @@ public function postProcess() { parent::postProcess(); - $isCreditCardSaveEnabled = Configuration::get(SaferPayConfig::CREDIT_CARD_SAVE); + /** @var \Invertus\SaferPay\Adapter\Configuration $configuration */ + $configuration = $this->module->getService(\Invertus\SaferPay\Adapter\Configuration::class); + + $isCreditCardSaveEnabled = $configuration->get(SaferPayConfig::CREDIT_CARD_SAVE); + if (!$isCreditCardSaveEnabled) { /** @var SaferPaySavedCreditCardRepository $cardRepo */ $cardRepo = $this->module->getService(SaferPaySavedCreditCardRepository::class); $cardRepo->deleteAllSavedCreditCards(); } + + $haveFieldToken = $configuration->get(SaferPayConfig::FIELDS_ACCESS_TOKEN . SaferPayConfig::getConfigSuffix()); + $haveBusinessLicense = $configuration->get(SaferPayConfig::BUSINESS_LICENSE . SaferPayConfig::getConfigSuffix()); + + if (!$haveFieldToken && $haveBusinessLicense) { + $configuration->set(SaferPayConfig::BUSINESS_LICENSE . SaferPayConfig::getConfigSuffix(), 0); + $this->errors[] = $this->module->l('Field Access Token is required to use business license'); + } } public function initOptions() diff --git a/controllers/front/return.php b/controllers/front/return.php index cebbb441..27fd10b9 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -87,6 +87,10 @@ public function postProcess() $orderPayment = $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(); + if (!empty($assertResponseBody->getPaymentMeans()->getWallet())) { + $orderPayment = $assertResponseBody->getPaymentMeans()->getWallet(); + } + /** @var SaferPayFieldRepository $saferPayFieldRepository */ $saferPayFieldRepository = $this->module->getService(SaferPayFieldRepository::class); diff --git a/src/Config/SaferPayConfig.php b/src/Config/SaferPayConfig.php index a9f93af5..8b640b0c 100755 --- a/src/Config/SaferPayConfig.php +++ b/src/Config/SaferPayConfig.php @@ -313,7 +313,9 @@ public static function isRedirectPayment($paymentMethod) self::PAYMENT_APPLEPAY, self::PAYMENT_GOOGLEPAY, self::PAYMENT_TWINT, - self::PAYMENT_POSTFINANCE_PAY + self::PAYMENT_POSTFINANCE_PAY, + self::PAYMENT_DIRECTDEBIT, + self::PAYMENT_SOFORT ]; return in_array($paymentMethod, $paymentsAlwaysRedirect); diff --git a/src/DTO/Response/PaymentMeans.php b/src/DTO/Response/PaymentMeans.php index c80990e7..21bdc750 100755 --- a/src/DTO/Response/PaymentMeans.php +++ b/src/DTO/Response/PaymentMeans.php @@ -43,6 +43,10 @@ class PaymentMeans * @var Card */ private $card; + /** + * @var string + */ + private $wallet; /** * PaymentMeans constructor. @@ -50,11 +54,12 @@ class PaymentMeans * @param string $displayText * @param Card|null $card */ - public function __construct(Brand $brand = null, $displayText = null, Card $card = null) + public function __construct(Brand $brand = null, $displayText = null, Card $card = null, $wallet = null) { $this->brand = $brand; $this->displayText = $displayText; $this->card = $card; + $this->wallet = $wallet; } /** @@ -97,6 +102,14 @@ public function getCard() return $this->card; } + /** + * @return string + */ + public function getWallet() + { + return $this->wallet; + } + /** * @param Card $card */ @@ -104,4 +117,9 @@ public function setCard($card) { $this->card = $card; } + + public function setWallet($wallet) + { + $this->wallet = $wallet; + } } diff --git a/src/Install/Installer.php b/src/Install/Installer.php index a6cdacca..f198ca4b 100755 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -300,17 +300,17 @@ private function installSaferPayLog() { return Db::getInstance()->execute( 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . pSQL(\SaferPayLog::$definition['table']) . '( - `id_saferpay_log` INTEGER(10) NOT NULL AUTO_INCREMENT, + `id_saferpay_log` INTEGER(10) unsigned NOT NULL AUTO_INCREMENT, `id_log` INT(10) NOT NULL, `id_shop` INT(10) NOT NULL DEFAULT ' . (int) Configuration::get('PS_SHOP_DEFAULT') . ', `message` TEXT DEFAULT NULL, `request` MEDIUMTEXT DEFAULT NULL, `response` MEDIUMTEXT DEFAULT NULL, `context` TEXT DEFAULT NULL, - `date_add` DATETIME NOT NULL, + `date_add` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(`id_saferpay_log`, `id_log`, `id_shop`), INDEX(`id_log`) - ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' + ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;' ); } diff --git a/src/Presentation/Loader/PaymentFormAssetLoader.php b/src/Presentation/Loader/PaymentFormAssetLoader.php index be73df09..c6f826b4 100755 --- a/src/Presentation/Loader/PaymentFormAssetLoader.php +++ b/src/Presentation/Loader/PaymentFormAssetLoader.php @@ -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; @@ -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) @@ -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) diff --git a/src/Service/Response/ResponseObjectCreator.php b/src/Service/Response/ResponseObjectCreator.php index 6db2cd0e..38c4b882 100755 --- a/src/Service/Response/ResponseObjectCreator.php +++ b/src/Service/Response/ResponseObjectCreator.php @@ -89,6 +89,9 @@ protected function createPaymentMeans($paymentMeans) } $paymentMeansObj->setBrand($brandObj); $paymentMeansObj->setDisplayText($paymentMeans->DisplayText); + if (isset($paymentMeans->Wallet)) { + $paymentMeansObj->setWallet($paymentMeans->Wallet); + } return $paymentMeansObj; } diff --git a/views/css/front/saferpay_checkout.css b/views/css/front/saferpay_checkout.css index f98495b3..a100ae4c 100755 --- a/views/css/front/saferpay_checkout.css +++ b/views/css/front/saferpay_checkout.css @@ -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; +} diff --git a/views/js/front/opc/onepagecheckoutps/hosted_fields.js b/views/js/front/opc/onepagecheckoutps/hosted_fields.js new file mode 100644 index 00000000..2b8162f7 --- /dev/null +++ b/views/js/front/opc/onepagecheckoutps/hosted_fields.js @@ -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 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 INVERTUS UAB www.invertus.eu + *@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; + }, + }); +}); \ No newline at end of file diff --git a/views/js/front/opc/supercheckout/hosted_fields.js b/views/js/front/opc/supercheckout/hosted_fields.js new file mode 100644 index 00000000..2b8162f7 --- /dev/null +++ b/views/js/front/opc/supercheckout/hosted_fields.js @@ -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 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 INVERTUS UAB www.invertus.eu + *@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; + }, + }); +}); \ No newline at end of file