From 4e04df066c8d58dfc1e07b90ed6540c6c81993da Mon Sep 17 00:00:00 2001 From: Juhani Haapala Date: Mon, 11 Sep 2023 10:50:11 +0300 Subject: [PATCH 1/5] Add updateOnlyOrderPaymentStatus method to update order status --- Api/QuotePaymentManagementInterface.php | 10 +++++++++- Gateway/Response/GetOnlyStatusHandler.php | 8 +++----- Model/QuotePaymentManagement.php | 8 ++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Api/QuotePaymentManagementInterface.php b/Api/QuotePaymentManagementInterface.php index 83a686f..97b0106 100644 --- a/Api/QuotePaymentManagementInterface.php +++ b/Api/QuotePaymentManagementInterface.php @@ -80,13 +80,21 @@ public function updatePaymentStatus($cartId); public function updateOnlyPaymentStatus($quote); /** - * Update order payment status from Avarda. + * Update order payment status and info from Avarda. * * @param OrderInterface $order * @return void */ public function updateOrderPaymentStatus($order); + /** + * Update order payment status from Avarda. + * + * @param OrderInterface $order + * @return void + */ + public function updateOnlyOrderPaymentStatus($order); + /** * Get quote ID by Avarda purchase ID * diff --git a/Gateway/Response/GetOnlyStatusHandler.php b/Gateway/Response/GetOnlyStatusHandler.php index 88180ba..dd821ee 100644 --- a/Gateway/Response/GetOnlyStatusHandler.php +++ b/Gateway/Response/GetOnlyStatusHandler.php @@ -36,20 +36,18 @@ public function __construct( public function handle(array $handlingSubject, array $response) { $paymentDO = SubjectReader::readPayment($handlingSubject); - $order = $paymentDO->getOrder(); + $payment = $paymentDO->getPayment(); - $entityId = $order->getId(); - $quote = $this->quoteRepository->get($entityId); $mode = $response['mode'] == 'B2B' ? 'b2B' : 'b2C'; // Set payment method if (isset($response['paymentMethods']['selectedPayment']['type'])) { $paymentMethod = $this->methodHelper->getPaymentMethod($response['paymentMethods']['selectedPayment']['type']); - $quote->getPayment()->setMethod($paymentMethod); + $payment->setMethod($paymentMethod); } // Set payment state - $quote->getPayment()->setAdditionalInformation( + $payment->setAdditionalInformation( PaymentData::STATE, $response[$mode]['step']['current'] )->setAdditionalInformation('renew', false); diff --git a/Model/QuotePaymentManagement.php b/Model/QuotePaymentManagement.php index 4453bfb..da3e096 100644 --- a/Model/QuotePaymentManagement.php +++ b/Model/QuotePaymentManagement.php @@ -312,6 +312,14 @@ public function updateOrderPaymentStatus($order) $this->executeCommand('avarda_update_order_status', $order); } + /** + * {@inheritdoc} + */ + public function updateOnlyOrderPaymentStatus($order) + { + $this->executeCommand('avarda_get_only_status', $order); + } + /** * @param $order OrderInterface|Order * @return void From 3593543803b239611cc89ea2800ac11dd5051584 Mon Sep 17 00:00:00 2001 From: Juhani Haapala Date: Wed, 8 Nov 2023 14:47:04 +0200 Subject: [PATCH 2/5] Don't do anything in aftercollect plugins if avarda checkout is not enabled --- .../Quote/QuoteCollectTotalsPrepareItems.php | 12 +++++++++- .../Quote/QuoteCollectTotalsUpdateItems.php | 22 +++++++++++-------- etc/di.xml | 10 +++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Plugin/PrepareItems/Quote/QuoteCollectTotalsPrepareItems.php b/Plugin/PrepareItems/Quote/QuoteCollectTotalsPrepareItems.php index 7add72e..aeb13be 100644 --- a/Plugin/PrepareItems/Quote/QuoteCollectTotalsPrepareItems.php +++ b/Plugin/PrepareItems/Quote/QuoteCollectTotalsPrepareItems.php @@ -11,6 +11,7 @@ use Avarda\Checkout3\Gateway\Data\ItemAdapter\QuoteItemFactory; use Avarda\Checkout3\Gateway\Data\ItemDataObjectFactory; use Avarda\Checkout3\Helper\PaymentData; +use Magento\Payment\Gateway\ConfigInterface; use Magento\Quote\Api\Data\CartInterface; use Psr\Log\LoggerInterface; @@ -46,11 +47,14 @@ class QuoteCollectTotalsPrepareItems */ protected $paymentDataHelper; + protected ConfigInterface $config; + /** * @var bool */ protected $collectTotalsFlag = false; + /** * QuoteCollectTotals constructor. * @@ -67,7 +71,8 @@ public function __construct( ItemDataObjectFactory $itemDataObjectFactory, QuoteItemFactory $quoteItemAdapterFactory, ArrayDataItemFactory $arrayDataItemAdapterFactory, - PaymentData $paymentDataHelper + PaymentData $paymentDataHelper, + ConfigInterface $config ) { $this->logger = $logger; $this->itemStorage = $itemStorage; @@ -75,6 +80,7 @@ public function __construct( $this->quoteItemAdapterFactory = $quoteItemAdapterFactory; $this->arrayDataItemAdapterFactory = $arrayDataItemAdapterFactory; $this->paymentDataHelper = $paymentDataHelper; + $this->config = $config; } /** @@ -86,6 +92,10 @@ public function __construct( */ public function afterCollectTotals(CartInterface $subject, CartInterface $result) { + if (!$this->config->isActive()) { + return $result; + } + try { if (!$this->collectTotalsFlag && $subject->getItemsCount() > 0 && diff --git a/Plugin/PrepareItems/Quote/QuoteCollectTotalsUpdateItems.php b/Plugin/PrepareItems/Quote/QuoteCollectTotalsUpdateItems.php index c017b99..2473a2d 100644 --- a/Plugin/PrepareItems/Quote/QuoteCollectTotalsUpdateItems.php +++ b/Plugin/PrepareItems/Quote/QuoteCollectTotalsUpdateItems.php @@ -13,19 +13,16 @@ use Magento\Framework\App\Request\Http; use Magento\Framework\Exception\PaymentException; use Magento\Framework\Webapi\Exception as WebapiException; +use Magento\Payment\Gateway\ConfigInterface; use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Model\Quote; class QuoteCollectTotalsUpdateItems { - /** @var QuotePaymentManagementInterface */ - protected $quotePaymentManagement; - - /** @var PaymentData */ - protected $paymentDataHelper; - - /** @var PurchaseState */ - protected $purchaseStateHelper; + protected QuotePaymentManagementInterface $quotePaymentManagement; + protected PaymentData $paymentDataHelper; + protected PurchaseState $purchaseStateHelper; + protected ConfigInterface $config; /** @var bool */ static $collectTotalsFlag = false; @@ -33,16 +30,19 @@ class QuoteCollectTotalsUpdateItems /** @var Http */ protected $request; + public function __construct( QuotePaymentManagementInterface $quotePaymentManagement, PaymentData $paymentDataHelper, PurchaseState $purchaseStateHelper, - Http $request + Http $request, + ConfigInterface $config ) { $this->quotePaymentManagement = $quotePaymentManagement; $this->paymentDataHelper = $paymentDataHelper; $this->purchaseStateHelper = $purchaseStateHelper; $this->request = $request; + $this->config = $config; } /** @@ -56,6 +56,10 @@ public function __construct( */ public function afterCollectTotals(CartInterface $subject, CartInterface $result) { + if (!$this->config->isActive()) { + return $result; + } + $payment = $subject->getPayment(); if (!self::$collectTotalsFlag && $subject->getItemsCount() > 0 && diff --git a/etc/di.xml b/etc/di.xml index d8b9967..b283169 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -773,4 +773,14 @@ Avarda\Checkout3\Model\Ui\ConfigProviderZeroAmount::CODE + + + Avarda\Checkout3\Gateway\Config\Config + + + + + Avarda\Checkout3\Gateway\Config\Config + + From d26f03b055577f0062dab5bb315f3c66d5b791f8 Mon Sep 17 00:00:00 2001 From: Juhani Haapala Date: Wed, 8 Nov 2023 14:47:21 +0200 Subject: [PATCH 3/5] Tiny code clean up --- Gateway/Response/GetOnlyStatusHandler.php | 2 -- Helper/PaymentData.php | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Gateway/Response/GetOnlyStatusHandler.php b/Gateway/Response/GetOnlyStatusHandler.php index dd821ee..badbef7 100644 --- a/Gateway/Response/GetOnlyStatusHandler.php +++ b/Gateway/Response/GetOnlyStatusHandler.php @@ -11,8 +11,6 @@ use Magento\Payment\Gateway\Helper\SubjectReader; use Magento\Payment\Gateway\Response\HandlerInterface; use Magento\Quote\Api\CartRepositoryInterface; -use Magento\Quote\Api\Data\AddressInterfaceFactory; -use Magento\Quote\Model\Quote\PaymentFactory; class GetOnlyStatusHandler implements HandlerInterface { diff --git a/Helper/PaymentData.php b/Helper/PaymentData.php index 3c24446..2b2a371 100644 --- a/Helper/PaymentData.php +++ b/Helper/PaymentData.php @@ -83,11 +83,11 @@ public function isAvardaPayment(InfoInterface $payment) $purchaseData = $this->getPurchaseData($payment); return $purchaseData && count($purchaseData)>=1 && ( - !$paymentCode || - strpos($paymentCode, 'avarda_checkout3') !== false || - // free method is automatically set in checkout, but it will be changed to avarda zero_sum on status update - $paymentCode == Free::PAYMENT_METHOD_FREE_CODE - ); + !$paymentCode || + strpos($paymentCode, 'avarda_checkout3') !== false || + // free method is automatically set in checkout, but it will be changed to avarda zero_sum on status update + $paymentCode == Free::PAYMENT_METHOD_FREE_CODE + ); } /** From 6ff4e5c00f4fda92d7fb8d13854fbc0fa6f28203 Mon Sep 17 00:00:00 2001 From: Juhani Haapala Date: Wed, 8 Nov 2023 14:47:44 +0200 Subject: [PATCH 4/5] Changed Zend consts to Laminas --- Gateway/Client/AvardaGatewayClient.php | 7 ++++--- Gateway/Client/TransferFactory.php | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Gateway/Client/AvardaGatewayClient.php b/Gateway/Client/AvardaGatewayClient.php index c66b57f..b882b46 100644 --- a/Gateway/Client/AvardaGatewayClient.php +++ b/Gateway/Client/AvardaGatewayClient.php @@ -6,6 +6,7 @@ namespace Avarda\Checkout3\Gateway\Client; +use Laminas\Http\Request; use Magento\Framework\Webapi\Exception as WebapiException; use Magento\Payment\Gateway\Http\ClientInterface; use Magento\Payment\Gateway\Http\ConverterInterface; @@ -50,14 +51,14 @@ public function placeRequest(TransferInterface $transferObject) try { switch ($transferObject->getMethod()) { - case \Zend_Http_Client::GET: + case Request::METHOD_GET: $result = $client->get($uri, $headers); break; - case \Zend_Http_Client::POST: + case Request::METHOD_POST: $response = $client->post($uri, $body, $headers); $result = $this->converter->convert($response); break; - case \Zend_Http_Client::PUT: + case Request::METHOD_PUT: $response = $client->put($uri, $body, $headers); $result = $this->converter->convert($response); break; diff --git a/Gateway/Client/TransferFactory.php b/Gateway/Client/TransferFactory.php index 12c0f50..c61cd5d 100644 --- a/Gateway/Client/TransferFactory.php +++ b/Gateway/Client/TransferFactory.php @@ -6,6 +6,7 @@ namespace Avarda\Checkout3\Gateway\Client; use Avarda\Checkout3\Gateway\Config\Config; +use Laminas\Http\Request; use Magento\Framework\Encryption\EncryptorInterface; use Magento\Payment\Gateway\Http\TransferBuilder; use Magento\Payment\Gateway\Http\TransferFactoryInterface; @@ -33,7 +34,7 @@ public function __construct( EncryptorInterface $encryptor, TransferBuilder $transferBuilder, Config $config, - $method = \Zend_Http_Client::POST, + $method = Request::METHOD_GET, $uri = '' ) { $this->encryptor = $encryptor; From 3159a05b1771c9a21974f0dc7dee048c2e3c2489 Mon Sep 17 00:00:00 2001 From: Juhani Haapala Date: Wed, 8 Nov 2023 14:48:25 +0200 Subject: [PATCH 5/5] Pump up version number --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cca692f..75cd3bc 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "avarda/checkout3", "description": "Avarda Checkout V3 module for Magento 2 module.", "type": "magento2-module", - "version": "1.3.9", + "version": "1.3.10", "require": { "ext-json": "*", "magento/module-backend": "*",