diff --git a/controllers/admin/AdminSaferPayOfficialPaymentController.php b/controllers/admin/AdminSaferPayOfficialPaymentController.php index 5a85cc65..3dea2ccc 100755 --- a/controllers/admin/AdminSaferPayOfficialPaymentController.php +++ b/controllers/admin/AdminSaferPayOfficialPaymentController.php @@ -64,6 +64,7 @@ public function postProcess() // Refresh payments. /** @var SaferPayRefreshPaymentsService $refreshPaymentsService */ $refreshPaymentsService = $this->module->getService(SaferPayRefreshPaymentsService::class); + try { $refreshPaymentsService->refreshPayments(); } catch (SaferPayApiException $exception) { diff --git a/controllers/admin/AdminSaferPayOfficialSettingsController.php b/controllers/admin/AdminSaferPayOfficialSettingsController.php index fdd33062..3b310c5c 100755 --- a/controllers/admin/AdminSaferPayOfficialSettingsController.php +++ b/controllers/admin/AdminSaferPayOfficialSettingsController.php @@ -400,7 +400,7 @@ private function displayConfigurationSettings() 'title' => $this->module->l('Description', self::FILE_NAME), 'type' => 'text', 'desc' => 'This description is visible in payment page also in payment confirmation email', - 'class' => 'fixed-width-xxl' + 'class' => 'fixed-width-xxl', ], ], 'buttons' => [ diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 270c768c..0cd60cc7 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -43,6 +43,9 @@ public function postProcess() case 'submitHostedFields': $this->submitHostedFields(); break; + case 'initializeSavedCardPayment': + $this->initializeSavedCardPayment(); + break; } } @@ -108,4 +111,48 @@ private function getRedirectionToControllerUrl($controllerName) true ); } + + + public function initializeSavedCardPayment() + { + try { + if (Order::getOrderByCartId($this->context->cart->id)) { + $this->ajaxDie(json_encode([ + 'error' => true, + 'message' => $this->module->l('Order already exists', self::FILE_NAME), + 'url' => $this->getRedirectionToControllerUrl('fail'), + ])); + } + + $checkoutData = CheckoutData::create( + (int) $this->context->cart->id, + Tools::getValue('paymentMethod'), + (int) Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE), + Tools::getValue('selectedCard'), + Tools::getValue('fieldToken'), + ControllerName::SUCCESS_HOSTED, + true + ); + + /** @var CheckoutController $checkoutController */ + $checkoutController = $this->module->getService(CheckoutController::class); + $redirectUrl = $checkoutController->execute($checkoutData); + + if (empty($redirectUrl)) { + $redirectUrl = $this->getRedirectionToControllerUrl('successHosted'); + } + + $this->ajaxDie(json_encode([ + 'error' => false, + 'url' => $redirectUrl, + 'successUrl' => $this->getRedirectionToControllerUrl('success'), + ])); + } catch (Exception $e) { + $this->ajaxDie(json_encode([ + 'error' => true, + 'message' => $e->getMessage(), + 'url' => $this->getRedirectionToControllerUrl('fail'), + ])); + } + } } diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index 7fb34709..c02c806c 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -89,7 +89,6 @@ public function initContent() /** @var CheckoutController $checkoutController */ $checkoutController = $this->module->getService(CheckoutController::class); - // refactor it to create checkout data from validator request $checkoutData = CheckoutData::create( (int) $this->context->cart->id, $paymentMethod, @@ -98,7 +97,6 @@ public function initContent() ); $redirectUrl = $checkoutController->execute($checkoutData); - } catch (\Exception $exception) { $redirectUrl = $this->context->link->getModuleLink( $this->module->name, diff --git a/controllers/front/notify.php b/controllers/front/notify.php index 584dc479..b4860443 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -180,7 +180,8 @@ public function postProcess() die($this->module->l('Success', self::FILENAME)); } - private function assertTransaction($cartId) { + private function assertTransaction($cartId) + { /** @var SaferPayTransactionAssertion $transactionAssert */ $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 9998633d..63794782 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -21,12 +21,9 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; if (!defined('_PS_VERSION_')) { exit; diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index a7ce3b5d..699cb404 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -21,13 +21,8 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; -use Invertus\SaferPay\Enum\ControllerName; -use Invertus\SaferPay\Exception\Api\SaferPayApiException; -use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; if (!defined('_PS_VERSION_')) { exit; @@ -48,7 +43,7 @@ public function init() parent::init(); } - public function postProcess() // todo refactor this by the logic provided + public function postProcess() { $cartId = Tools::getValue('cartId'); $orderId = Tools::getValue('orderId'); @@ -62,37 +57,6 @@ public function postProcess() // todo refactor this by the logic provided $this->redirectWithNotifications($this->getOrderLink()); } - - try { - Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey)); - } catch (Exception $e) { - PrestaShopLogger::addLog( - sprintf( - '%s has caught an error: %s', - __CLASS__, - $e->getMessage() - ), - 1, - null, - null, - null, - true - ); - - Tools::redirect( - $this->context->link->getModuleLink( - $this->module->name, - ControllerName::FAIL_IFRAME, - [ - 'cartId' => $cartId, - 'secureKey' => $secureKey, - 'orderId' => $orderId, - \Invertus\SaferPay\Config\SaferPayConfig::IS_BUSINESS_LICENCE => true, - ], - true - ) - ); - } } public function initContent() diff --git a/saferpayofficial.php b/saferpayofficial.php index c94e6f0b..ba6efce5 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -625,7 +625,7 @@ public function hookActionOrderHistoryAddAfter($params = []) } if ((int) \Configuration::get(SaferPayConfig::SAFERPAY_PAYMENT_AUTHORIZED) === (int) $orderStatus->id) { - $mailService->sendOrderConfMail($order, (int) $orderStatus->id); + $mailService->sendOrderConfMail($order, (int) $orderStatus->id); } } } @@ -759,4 +759,13 @@ public function addFlash($msg, $type) return true; } + + public function hookDisplayHeader() + { + if (true) { + return $this->context->smarty->fetch( + $this->getLocalPath() . 'views/templates/front/saferpay_iframe_modal.tpl' + ); + } + } } diff --git a/src/Api/Request/AssertService.php b/src/Api/Request/AssertService.php index c430dbce..fc0d2871 100755 --- a/src/Api/Request/AssertService.php +++ b/src/Api/Request/AssertService.php @@ -83,7 +83,7 @@ public function assert(AssertRequest $assertRequest, $saferPayOrderId) // also we call authorize method in some of the success controllers, so if we leave the logic here, // we get an error with TRANSACTION_IN_WRONG_STATE if ($saferPayOrder->is_transaction) { - $assertApi = self::ASSERT_API_TRANSACTION; + $assertApi = self::ASSERT_API_TRANSACTION; } try { diff --git a/src/Controller/Front/index.php b/src/Controller/Front/index.php index 7487f261..6b778722 100644 --- a/src/Controller/Front/index.php +++ b/src/Controller/Front/index.php @@ -21,7 +21,7 @@ *@license SIX Payment Services */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." 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); diff --git a/src/Core/Order/Action/UpdateOrderStatusAction.php b/src/Core/Order/Action/UpdateOrderStatusAction.php index 316bbd66..58f93ba3 100644 --- a/src/Core/Order/Action/UpdateOrderStatusAction.php +++ b/src/Core/Order/Action/UpdateOrderStatusAction.php @@ -60,6 +60,5 @@ public function run($orderId, $orderStatusId) } catch (\Exception $exception) { throw CouldNotChangeOrderStatus::unknownError($exception); } - } } diff --git a/src/Core/Payment/DTO/CheckoutData.php b/src/Core/Payment/DTO/CheckoutData.php index 7281cfe9..b81208c4 100644 --- a/src/Core/Payment/DTO/CheckoutData.php +++ b/src/Core/Payment/DTO/CheckoutData.php @@ -44,15 +44,14 @@ class CheckoutData private $status; public function __construct( - $cartId, - $paymentMethod, - $isBusinessLicense, - $selectedCard = -1, - $fieldToken = null, - $successController = null, - $isTransaction = false - ) - { + $cartId, + $paymentMethod, + $isBusinessLicense, + $selectedCard = -1, + $fieldToken = null, + $successController = null, + $isTransaction = false + ) { $this->cartId = $cartId; $this->paymentMethod = $paymentMethod; $this->isBusinessLicense = $isBusinessLicense; @@ -65,15 +64,14 @@ public function __construct( } public static function create( - $cartId, - $paymentMethod, - $isBusinessLicense, - $selectedCard = -1, - $fieldToken = null, - $successController = null, - $isTransaction = false - ) - { + $cartId, + $paymentMethod, + $isBusinessLicense, + $selectedCard = -1, + $fieldToken = null, + $successController = null, + $isTransaction = false + ) { return new self( $cartId, $paymentMethod, @@ -184,4 +182,4 @@ public function setOrderStatus($status) { $this->status = $status; } -} \ No newline at end of file +} diff --git a/src/Exception/CouldNotProcessCheckout.php b/src/Exception/CouldNotProcessCheckout.php index b8b19281..e495daa4 100644 --- a/src/Exception/CouldNotProcessCheckout.php +++ b/src/Exception/CouldNotProcessCheckout.php @@ -75,4 +75,4 @@ public static function failedToCreateSaferPayOrder($cartId) ] ); } -} \ No newline at end of file +} diff --git a/src/Exception/SaferPayException.php b/src/Exception/SaferPayException.php index 41906751..851bd257 100644 --- a/src/Exception/SaferPayException.php +++ b/src/Exception/SaferPayException.php @@ -35,8 +35,7 @@ final public function __construct( $internalMessage, $code, array $context = [] - ) - { + ) { parent::__construct($internalMessage, $code); $this->context = $context; } @@ -53,4 +52,4 @@ public static function unknownError() ExceptionCode::UNKNOWN_ERROR ); } -} \ No newline at end of file +} diff --git a/src/Install/Installer.php b/src/Install/Installer.php index 8e5c9534..22c96778 100755 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -89,13 +89,13 @@ private function registerHooks() $this->module->registerHook('displayAdminOrder'); $this->module->registerHook('actionFrontControllerSetMedia'); $this->module->registerHook('displayCustomerAccount'); - $this->module->registerHook('displayPayment'); $this->module->registerHook('paymentReturn'); $this->module->registerHook('actionEmailSendBefore'); $this->module->registerHook('displayAdminOrderTabContent'); $this->module->registerHook('actionAdminControllerSetMedia'); $this->module->registerHook('actionOrderHistoryAddAfter'); $this->module->registerHook('actionObjectOrderPaymentAddAfter'); + $this->module->registerHook('displayHeader'); } private function installConfiguration() diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index eac6cc4a..771b6691 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -66,8 +66,8 @@ public function __construct( $this->saferPayOrderRepository = $saferPayOrderRepository; } - public function run(CheckoutData $data) { - + public function run(CheckoutData $data) + { $cart = new Cart($data->getCartId()); if (!$cart) { diff --git a/src/Processor/index.php b/src/Processor/index.php index 7487f261..6b778722 100644 --- a/src/Processor/index.php +++ b/src/Processor/index.php @@ -21,7 +21,7 @@ *@license SIX Payment Services */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." 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); diff --git a/src/Service/Request/InitializeRequestObjectCreator.php b/src/Service/Request/InitializeRequestObjectCreator.php index 0ca1e5e4..906cd5aa 100755 --- a/src/Service/Request/InitializeRequestObjectCreator.php +++ b/src/Service/Request/InitializeRequestObjectCreator.php @@ -27,10 +27,8 @@ use Configuration; use Customer; use Invertus\SaferPay\Config\SaferPayConfig; -use Invertus\SaferPay\DTO\Request\RequestHeader; use Invertus\SaferPay\DTO\Request\Initialize\InitializeRequest; use Invertus\SaferPay\DTO\Request\Payer; -use PrestaShop\PrestaShop\Adapter\Shop\Context; if (!defined('_PS_VERSION_')) { exit; diff --git a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php index 92c1b2fa..b79bc354 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php @@ -30,7 +30,6 @@ use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\Request\AuthorizationRequestObjectCreator; use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Order; use SaferPayOrder; if (!defined('_PS_VERSION_')) { diff --git a/upgrade/install-1.1.8.php b/upgrade/install-1.1.8.php index d52c8914..636a4cb3 100644 --- a/upgrade/install-1.1.8.php +++ b/upgrade/install-1.1.8.php @@ -41,4 +41,4 @@ function upgrade_module_1_1_8(SaferPayOfficial $module) $module->registerHook('actionObjectOrderPaymentAddAfter'); return true; -} \ No newline at end of file +} diff --git a/upgrade/install-1.2.2.php b/upgrade/install-1.2.2.php index b0b04cc5..7424b1ae 100644 --- a/upgrade/install-1.2.2.php +++ b/upgrade/install-1.2.2.php @@ -31,8 +31,8 @@ */ function upgrade_module_1_2_2($module) { - return $module->registerHook('actionOrderHistoryAddAfter') + return $module->registerHook('displayHeader') + && $module->registerHook('actionOrderStatusPostUpdate') && $module->unregisterHook('actionOrderStatusUpdate') && Configuration::deleteByName('SAFERPAY_SEND_ORDER_CONFIRMATION'); } - diff --git a/views/js/front/hosted-templates/hosted_fields.js b/views/js/front/hosted-templates/hosted_fields.js index 66324a49..4ea1a54e 100755 --- a/views/js/front/hosted-templates/hosted_fields.js +++ b/views/js/front/hosted-templates/hosted_fields.js @@ -32,16 +32,48 @@ $(document).ready(function () { var paymentType = $(this).find("[name=saferpayPaymentType]").val(); + var selectedCardMethod = $(this).find("[name=saved_card_method]").val(); + var selectedCard = $(this).find("[name=selectedCreditCard_" + selectedCardMethod + "]").val(); + //NOTE: if it's not a hosted iframe then we don't need to submitHostedFields. if (paymentType !== saferpay_payment_types.hosted_iframe) { - event.target.submit(); + //NOTE: not saved card chosen, continuing with normal procedures. + if (selectedCard <= 0) { + event.target.submit(); - return; - } + return; + } - var selectedCardMethod = $(this).find("[name=saved_card_method]").val(); + $.ajax(saferpay_official_ajax_url, { + method: 'POST', + data: { + action: 'initializeSavedCardPayment', + paymentMethod: selectedCardMethod, + selectedCard: selectedCard, + isBusinessLicence: 1, + ajax: 1 + }, + success: function (response) { + var data = jQuery.parseJSON(response); - var selectedCard = $(this).find("[name=selectedCreditCard_" + selectedCardMethod + "]").val(); + if(data.error) { + window.location.href = data.url; + + return + } + + $('#savedCardModal').modal('show'); + document.getElementById("savedCardIframe").src = data.url; + + // Attach event handler for modal close event + $('#savedCardModal').on('hidden.bs.modal', function () { + window.location.href = data.successUrl; + }); + }, + }); + + return; + } //NOTE: not saved card chosen, continuing with normal procedures. if (selectedCard <= 0) { @@ -61,7 +93,6 @@ $(document).ready(function () { }, success: function (response) { var data = jQuery.parseJSON(response); - window.location = data.url; }, }); diff --git a/views/templates/front/credit_cards.tpl b/views/templates/front/credit_cards.tpl index d042b193..16083a4b 100755 --- a/views/templates/front/credit_cards.tpl +++ b/views/templates/front/credit_cards.tpl @@ -51,7 +51,7 @@ {foreach $rows as $row} - {$row nofilter|escape:'htmlall':'UTF-8'} + {$row|cleanHtml nofilter} {/foreach} diff --git a/views/templates/front/credit_cards_16.tpl b/views/templates/front/credit_cards_16.tpl index ee8f2a0a..af1140bf 100755 --- a/views/templates/front/credit_cards_16.tpl +++ b/views/templates/front/credit_cards_16.tpl @@ -53,7 +53,7 @@ {foreach $rows as $row} - {$row nofilter|escape:'htmlall':'UTF-8'} + {$row|cleanHtml nofilter} {/foreach} diff --git a/views/templates/front/saferpay_iframe_modal.tpl b/views/templates/front/saferpay_iframe_modal.tpl new file mode 100644 index 00000000..724358b9 --- /dev/null +++ b/views/templates/front/saferpay_iframe_modal.tpl @@ -0,0 +1,37 @@ +{** + *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 + *} + +