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/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; diff --git a/Gateway/Response/GetOnlyStatusHandler.php b/Gateway/Response/GetOnlyStatusHandler.php index 88180ba..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 { @@ -36,20 +34,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/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 + ); } /** 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 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/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": "*", 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 + +