From 858f0f97e9987162a853996acd61c5ec2890288a Mon Sep 17 00:00:00 2001 From: Tigran Date: Thu, 4 Apr 2024 19:04:31 +0400 Subject: [PATCH 1/2] PT-1282 add explicit check in Success controller to not confirm order twice --- .../Checkout/AbstractPaymentController.php | 14 ++++++++++++-- .../Checkout/AbstractSuccessController.php | 18 ++++++++++++++++-- Controller/Payment/Checkout/Success.php | 15 +++++++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Controller/Payment/Checkout/AbstractPaymentController.php b/Controller/Payment/Checkout/AbstractPaymentController.php index c8557fe..e87b1c6 100644 --- a/Controller/Payment/Checkout/AbstractPaymentController.php +++ b/Controller/Payment/Checkout/AbstractPaymentController.php @@ -12,7 +12,7 @@ use Mondu\Mondu\Helpers\ABTesting\ABTesting; use Mondu\Mondu\Helpers\Logger\Logger as MonduFileLogger; use Mondu\Mondu\Model\Request\Factory as RequestFactory; - +use Mondu\Mondu\Helpers\Log as MonduTransactions; abstract class AbstractPaymentController implements ActionInterface { /** @@ -57,6 +57,12 @@ abstract class AbstractPaymentController implements ActionInterface * @var ABTesting */ protected $aBTesting; + + /** + * @var MonduTransactions + */ + protected $monduTransactions; + /** * Execute * @@ -73,6 +79,8 @@ abstract public function execute(); * @param MonduFileLogger $monduFileLogger * @param RequestFactory $requestFactory * @param JsonFactory $jsonResultFactory + * @param ABTesting $aBTesting + * @param MonduTransactions $monduTransactions */ public function __construct( RequestInterface $request, @@ -83,7 +91,8 @@ public function __construct( MonduFileLogger $monduFileLogger, RequestFactory $requestFactory, JsonFactory $jsonResultFactory, - ABTesting $aBTesting + ABTesting $aBTesting, + MonduTransactions $monduTransactions ) { $this->request = $request; $this->response = $response; @@ -94,6 +103,7 @@ public function __construct( $this->requestFactory = $requestFactory; $this->jsonResultFactory = $jsonResultFactory; $this->aBTesting = $aBTesting; + $this->monduTransactions = $monduTransactions; } diff --git a/Controller/Payment/Checkout/AbstractSuccessController.php b/Controller/Payment/Checkout/AbstractSuccessController.php index 0b60a7a..b5fb1f3 100644 --- a/Controller/Payment/Checkout/AbstractSuccessController.php +++ b/Controller/Payment/Checkout/AbstractSuccessController.php @@ -10,12 +10,14 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Message\ManagerInterface as MessageManagerInterface; use Magento\Quote\Model\Quote; +use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Model\Order\Email\Sender\OrderSender; use Magento\Checkout\Helper\Data as CheckoutData; use Magento\Quote\Api\CartManagementInterface; use Mondu\Mondu\Helpers\ABTesting\ABTesting; use Mondu\Mondu\Helpers\Logger\Logger as MonduFileLogger; use Mondu\Mondu\Model\Request\Factory as RequestFactory; +use Mondu\Mondu\Helpers\Log as MonduTransactions; abstract class AbstractSuccessController extends AbstractPaymentController { @@ -39,6 +41,11 @@ abstract class AbstractSuccessController extends AbstractPaymentController */ private $checkoutData; + /** + * @var OrderRepositoryInterface + */ + protected $orderRepository; + /** * @param RequestInterface $request * @param ResponseInterface $response @@ -52,6 +59,9 @@ abstract class AbstractSuccessController extends AbstractPaymentController * @param OrderSender $orderSender * @param CheckoutData $checkoutData * @param CartManagementInterface $quoteManagement + * @param ABTesting $aBTesting + * @param MonduTransactions $monduTransactions + * @param OrderRepositoryInterface $orderRepository */ public function __construct( RequestInterface $request, @@ -66,7 +76,9 @@ public function __construct( OrderSender $orderSender, CheckoutData $checkoutData, CartManagementInterface $quoteManagement, - ABTesting $aBTesting + ABTesting $aBTesting, + MonduTransactions $monduTransactions, + OrderRepositoryInterface $orderRepository ) { parent::__construct( $request, @@ -77,13 +89,15 @@ public function __construct( $monduFileLogger, $requestFactory, $jsonResultFactory, - $aBTesting + $aBTesting, + $monduTransactions ); $this->customerSession = $customerSession; $this->orderSender = $orderSender; $this->checkoutData = $checkoutData; $this->quoteManagement = $quoteManagement; + $this->orderRepository = $orderRepository; } /** diff --git a/Controller/Payment/Checkout/Success.php b/Controller/Payment/Checkout/Success.php index 0643db2..a7ae84b 100644 --- a/Controller/Payment/Checkout/Success.php +++ b/Controller/Payment/Checkout/Success.php @@ -22,11 +22,23 @@ public function execute() } try { + $monduTransaction = $this->monduTransactions->getTransactionByOrderUid($monduId); + + if ($monduTransaction && $monduTransaction['is_confirmed']) { + $order = $this->orderRepository->get($monduTransaction['order_id']); + $this->checkoutSession->setLastOrderId($order->getId()) + ->setLastRealOrderId($order->getIncrementId()) + ->setLastOrderStatus($order->getStatus()) + ->setLastSuccessQuoteId($order->getQuoteId()) + ->setLastQuoteId($order->getQuoteId()); + + return $this->redirect('checkout/onepage/success/'); + } + $quote = $this->checkoutSession->getQuote(); $this->authorizeMonduOrder($monduId, $this->getExternalReferenceId($quote)); $order = $this->placeOrder($quote); - $this->checkoutSession->clearHelperData(); $quoteId = $this->checkoutSession->getQuoteId(); $this->checkoutSession->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId); @@ -43,7 +55,6 @@ public function execute() } } return $this->redirect('checkout/onepage/success/'); - } catch (LocalizedException $e) { return $this->processException($e, 'Mondu: An error occurred while trying to confirm the order'); } catch (\Exception $e) { From 9f972850833305b091c501123a6546789a6989a9 Mon Sep 17 00:00:00 2001 From: Tigran Date: Mon, 8 Apr 2024 17:36:22 +0400 Subject: [PATCH 2/2] PT-1282 version bump --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0c07ff8..37e0939 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "mondu_gmbh/magento2-payment", "description": "Mondu payment method for magento 2", "type": "magento2-module", - "version": "2.3.4", + "version": "2.3.5", "license": [ "MIT" ],