From dadc1604449c50462e937b8745de8e8584089027 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 25 Sep 2024 12:23:42 +0300 Subject: [PATCH 1/8] fix --- controllers/front/ajax.php | 2 +- src/DTO/Request/Initialize/InitializeRequest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index f221d68e..b89ecd84 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -147,7 +147,7 @@ private function submitHostedFields() $checkoutController = $this->module->getService(CheckoutController::class); $redirectUrl = $checkoutController->execute($checkoutData); - if (empty($redirectUrl)) { + if (empty($redirectUrl) || Tools::getValue('action') === 'submitHostedFields') { $redirectUrl = $this->getRedirectionToControllerUrl('successHosted'); } diff --git a/src/DTO/Request/Initialize/InitializeRequest.php b/src/DTO/Request/Initialize/InitializeRequest.php index 4bf07ddc..81fad549 100755 --- a/src/DTO/Request/Initialize/InitializeRequest.php +++ b/src/DTO/Request/Initialize/InitializeRequest.php @@ -184,7 +184,6 @@ public function getAsArray() 'PayerNote' => $this->payment->getPayerNote(), 'Description' => $this->payment->getDescription(), ], - 'PaymentMeans' => $this->getPaymentMeansField() ?: null, 'Payer' => [ 'IpAddress' => $this->payer->getIpAddress(), 'LanguageCode' => $this->payer->getLanguageCode(), From a88bf4122ffcc05dba19e4693d5da53d5fead416 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 25 Sep 2024 13:52:30 +0300 Subject: [PATCH 2/8] [SL-252] fix --- controllers/front/ajax.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index b89ecd84..80be6f9b 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -77,7 +77,7 @@ protected function processGetStatus() $this->ajaxDie(json_encode([ 'saferpayOrder' => json_encode($saferPayOrder), - 'isFinished' => $saferPayOrder->authorized || $saferPayOrder->captured || $saferPayOrder->pending, + 'isFinished' => true, 'href' => $this->context->link->getModuleLink( $this->module->name, $this->getSuccessControllerName($isBusinessLicence, $fieldToken), @@ -86,7 +86,7 @@ protected function processGetStatus() 'orderId' => $saferPayOrder->id_order, 'moduleId' => $moduleId, 'secureKey' => $secureKey, - 'selectedCard' => $selectedCard, + 'selectedCard' => $selectedCard ?? '-1', ] ) ])); From 48291889cf9a59c2bcb2ce35bb59831e1928e707 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 25 Sep 2024 15:04:41 +0300 Subject: [PATCH 3/8] [SL-252] fix --- controllers/front/ajax.php | 2 +- views/templates/front/credit_cards.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 80be6f9b..7895c900 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -86,7 +86,7 @@ protected function processGetStatus() 'orderId' => $saferPayOrder->id_order, 'moduleId' => $moduleId, 'secureKey' => $secureKey, - 'selectedCard' => $selectedCard ?? '-1', + 'selectedCard' => $selectedCard, ] ) ])); diff --git a/views/templates/front/credit_cards.tpl b/views/templates/front/credit_cards.tpl index d042b193..9c69534f 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|escape:'htmlall':'UTF-8' nofilter} {/foreach} From 4ec3aacc200c500f90aa84b66a2082adcf3cc260 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 25 Sep 2024 15:13:39 +0300 Subject: [PATCH 4/8] [SL-252] fix order status --- controllers/front/successHosted.php | 4 ++++ src/Service/SaferPayOrderStatusService.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 9998633d..da7c182c 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -54,6 +54,10 @@ public function postProcess() $secureKey = Tools::getValue('secureKey'); $moduleId = Tools::getValue('moduleId'); + $order = new Order($orderId); + $statusService = $this->module->getService(SaferPayOrderStatusService::class); + $statusService->setAuthorized($order); + $cart = new Cart($cartId); if ($cart->secure_key !== $secureKey) { $this->errors[] = $this->module->l('Failed to validate cart.', self::FILE_NAME); diff --git a/src/Service/SaferPayOrderStatusService.php b/src/Service/SaferPayOrderStatusService.php index 711b837c..f340f6aa 100755 --- a/src/Service/SaferPayOrderStatusService.php +++ b/src/Service/SaferPayOrderStatusService.php @@ -136,6 +136,21 @@ public function setComplete(Order $order) $order->setCurrentState(_SAFERPAY_PAYMENT_COMPLETED_); } + public function setAuthorized(Order $order) + { + $saferPayOrder = $this->orderRepository->getByOrderId($order->id); + $saferPayOrder->authorized = 1; + + $saferPayOrder->update(); + + //NOTE: Older PS versions does not handle same state change, so we need to check if state is already set + if ($order->getCurrentState() === _SAFERPAY_PAYMENT_AUTHORIZED_) { + return; + } + + $order->setCurrentState(_SAFERPAY_PAYMENT_AUTHORIZED_); + } + /** TODO extract capture api code to different service like Assert for readability */ public function capture(Order $order, $refundedAmount = 0, $isRefund = false) { From 658e1e485322b50afa30f7dca474b42bee4b5dac Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 25 Sep 2024 16:53:44 +0300 Subject: [PATCH 5/8] [SL-252] X --- controllers/front/ajax.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 7895c900..04f10f23 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -26,6 +26,7 @@ use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Repository\SaferPayOrderRepository; +use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion; if (!defined('_PS_VERSION_')) { exit; @@ -147,6 +148,16 @@ private function submitHostedFields() $checkoutController = $this->module->getService(CheckoutController::class); $redirectUrl = $checkoutController->execute($checkoutData); + $saferPayOrder = new SaferPayOrder(); + $saferPayOrder->is_transaction = 1; + $saferPayOrder->update(); + + $cart = new Cart($this->context->cart->id); + + /** @var SaferPayTransactionAssertion $assertService */ + $assertService = $this->module->getService(SaferPayTransactionAssertion::class); + $assertService->assert($this->context->cart->id, false); + if (empty($redirectUrl) || Tools::getValue('action') === 'submitHostedFields') { $redirectUrl = $this->getRedirectionToControllerUrl('successHosted'); } From 6df4d7e3c6e939b8f13a896a100f530080c21be7 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 25 Sep 2024 18:02:04 +0300 Subject: [PATCH 6/8] [KS-252] fix --- .../TransactionFlow/SaferPayTransactionAssertion.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php index 5fcc3549..f2f0778c 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php @@ -24,6 +24,7 @@ namespace Invertus\SaferPay\Service\TransactionFlow; use Invertus\SaferPay\Api\Request\AssertService; +use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\Request\AssertRequestObjectCreator; @@ -71,6 +72,14 @@ public function assert($cartId, $update = true) $saferPayOrder = new SaferPayOrder($this->orderRepository->getIdByCartId($cartId)); \PrestaShopLogger::addLog('saferpayOrderId:' . $saferPayOrder->id); + $businessLicence = \Configuration::get(SaferPayConfig::BUSINESS_LICENSE . SaferPayConfig::getConfigSuffix()); + + if($businessLicence) { + $saferPayOrder = new SaferPayOrder($saferPayOrder->id); + $saferPayOrder->is_transaction = 1; + $saferPayOrder->update(); + } + $assertRequest = $this->assertRequestCreator->create($saferPayOrder->token); $assertResponse = $this->assertionService->assert($assertRequest, $saferPayOrder->id); From 4921d438d57ca539c07fa6630591789e73250e7b Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 25 Sep 2024 21:47:48 +0300 Subject: [PATCH 7/8] [SL-252] wip --- controllers/front/ajax.php | 2 +- controllers/front/hostedIframe.php | 33 +++++++++++++++++++ .../Request/Initialize/InitializeRequest.php | 6 ++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 04f10f23..b776312f 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -146,7 +146,7 @@ private function submitHostedFields() /** @var CheckoutController $checkoutController */ $checkoutController = $this->module->getService(CheckoutController::class); - $redirectUrl = $checkoutController->execute($checkoutData); +// $redirectUrl = $checkoutController->execute($checkoutData); $saferPayOrder = new SaferPayOrder(); $saferPayOrder->is_transaction = 1; diff --git a/controllers/front/hostedIframe.php b/controllers/front/hostedIframe.php index b0330637..fd9fdb0c 100755 --- a/controllers/front/hostedIframe.php +++ b/controllers/front/hostedIframe.php @@ -22,6 +22,9 @@ */ use Invertus\SaferPay\Config\SaferPayConfig; +use Invertus\SaferPay\Controller\Front\CheckoutController; +use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; +use Invertus\SaferPay\Enum\ControllerName; use PrestaShop\PrestaShop\Core\Checkout\TermsAndConditions; if (!defined('_PS_VERSION_')) { @@ -38,15 +41,45 @@ public function initContent() $paymentMethod = Tools::getValue('saved_card_method'); $selectedCard = Tools::getValue("selectedCreditCard_{$paymentMethod}"); + if (!SaferPayConfig::isVersion17()) { $selectedCard = Tools::getValue("saved_card_{$paymentMethod}"); } + try { + /** @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, + (int) Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE), + $selectedCard + ); + + $redirectUrl = $checkoutController->execute($checkoutData); + } catch (Exception $e) { + $redirectUrl = $this->context->link->getModuleLink( + $this->module->name, + ControllerName::FAIL, + [ + 'cartId' => $this->context->cart->id, + 'orderId' => Order::getOrderByCartId($this->context->cart->id), + 'secureKey' => $this->context->cart->secure_key, + 'moduleId' => $this->module->id, + ], + true + ); + $this->redirectWithNotifications($redirectUrl); + } + $this->context->smarty->assign([ 'credit_card_front_url' => "{$this->module->getPathUri()}views/img/example-card/credit-card-front.png", 'credit_card_back_url' => "{$this->module->getPathUri()}views/img/example-card/credit-card-back.png", 'tos_cms' => SaferPayConfig::isVersionAbove177() ? $this->getDefaultTermsAndConditions() : null, 'saferpay_selected_card' => $selectedCard, + 'redirect' => $redirectUrl, ]); if (SaferPayConfig::isVersion17()) { diff --git a/src/DTO/Request/Initialize/InitializeRequest.php b/src/DTO/Request/Initialize/InitializeRequest.php index 81fad549..655e08d0 100755 --- a/src/DTO/Request/Initialize/InitializeRequest.php +++ b/src/DTO/Request/Initialize/InitializeRequest.php @@ -249,9 +249,9 @@ public function getAsArray() ]; } - if ($this->alias || $this->fieldToken) { - unset($return['PaymentMethods']); - } +// if ($this->alias || $this->fieldToken) { +// unset($return['PaymentMethods']); +// } //Wallet related, payment method must be empty, instead used "Wallets" argument in request. if (in_array(\Tools::strtoupper($this->paymentMethod), SaferPayConfig::WALLET_PAYMENT_METHODS)) { From 844e74f741073b1dd78c5193d674e0427eb83c67 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 26 Sep 2024 08:46:20 +0300 Subject: [PATCH 8/8] [SL-252] fix --- controllers/front/ajax.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index b776312f..de494bbf 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -152,8 +152,6 @@ private function submitHostedFields() $saferPayOrder->is_transaction = 1; $saferPayOrder->update(); - $cart = new Cart($this->context->cart->id); - /** @var SaferPayTransactionAssertion $assertService */ $assertService = $this->module->getService(SaferPayTransactionAssertion::class); $assertService->assert($this->context->cart->id, false);