From cf821811e676a274b301ea6bc8a1afd8ce7667da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 23 Mar 2023 15:11:39 +0100 Subject: [PATCH 1/3] M2-121 - Added compatibility for Magento 2.4.6 and PHP 8.2 --- Block/Checkout/InstallmentPlan.php | 5 +++++ Helper/ProfileConfig.php | 5 +++++ Model/LibraryModel.php | 20 ++++++++++++++++++++ Plugin/RatepayGuestErrorProcessor.php | 5 +++++ 4 files changed, 35 insertions(+) diff --git a/Block/Checkout/InstallmentPlan.php b/Block/Checkout/InstallmentPlan.php index 4d927cc..028173c 100644 --- a/Block/Checkout/InstallmentPlan.php +++ b/Block/Checkout/InstallmentPlan.php @@ -13,6 +13,11 @@ class InstallmentPlan extends \Magento\Framework\View\Element\Template { + /** + * @var \Magento\Framework\View\Asset\Repository + */ + protected $assetRepo; + /** * Constructor * diff --git a/Helper/ProfileConfig.php b/Helper/ProfileConfig.php index bcb30c2..90731c9 100644 --- a/Helper/ProfileConfig.php +++ b/Helper/ProfileConfig.php @@ -33,6 +33,11 @@ class ProfileConfig extends \Magento\Framework\App\Helper\AbstractHelper */ protected $profileConfigResource; + /** + * @var Data + */ + protected $ratepayHelper; + /** * @var \RatePAY\Payment\Model\Entities\ProfileConfigurationFactory */ diff --git a/Model/LibraryModel.php b/Model/LibraryModel.php index d11201d..6d5a322 100644 --- a/Model/LibraryModel.php +++ b/Model/LibraryModel.php @@ -14,6 +14,26 @@ class LibraryModel { + /** + * @var \RatePAY\Payment\Helper\Head\Head + */ + protected $rpHeadHelper; + + /** + * @var \RatePAY\Payment\Helper\Head\Additional + */ + protected $rpHeadAdditionalHelper; + + /** + * @var \RatePAY\Payment\Helper\Head\External + */ + protected $rpHeadExternalHelper; + + /** + * @var \RatePAY\Payment\Helper\Content\ContentBuilder + */ + protected $rpContentBuilder; + /** * @var Discount */ diff --git a/Plugin/RatepayGuestErrorProcessor.php b/Plugin/RatepayGuestErrorProcessor.php index 2d69071..83e6809 100644 --- a/Plugin/RatepayGuestErrorProcessor.php +++ b/Plugin/RatepayGuestErrorProcessor.php @@ -23,6 +23,11 @@ class RatepayGuestErrorProcessor */ protected $paymentInformationManagement; + /** + * @var \Magento\Quote\Api\GuestPaymentMethodManagementInterface + */ + protected $paymentMethodManagement; + /** * @var \Magento\Checkout\Model\Session */ From 3700a151bda70006f46526ae38a325473be1aa87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 28 Mar 2023 18:40:43 +0200 Subject: [PATCH 2/3] M2-121 - Fixed problems with displaying error messages in payment list --- Plugin/RatepayErrorProcessor.php | 58 ++++++++++++++++----- view/frontend/web/js/view/messages-mixin.js | 7 ++- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/Plugin/RatepayErrorProcessor.php b/Plugin/RatepayErrorProcessor.php index cd2dc79..7823388 100644 --- a/Plugin/RatepayErrorProcessor.php +++ b/Plugin/RatepayErrorProcessor.php @@ -9,6 +9,8 @@ namespace RatePAY\Payment\Plugin; +use Magento\Framework\Exception\CouldNotSaveException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\PaymentException; use RatePAY\Payment\Model\Exception\DisablePaymentMethodException; @@ -29,20 +31,28 @@ class RatepayErrorProcessor */ protected $productMetadata; + /** + * @var \Psr\Log\LoggerInterface + */ + private $logger; + /** * RatepayErrorProcessor constructor. * @param \Magento\Checkout\Model\Session $session * @param \Magento\Quote\Api\CartManagementInterface $cartManagement * @param \Magento\Framework\App\ProductMetadata $productMetadata + * @param LoggerInterface $logger */ public function __construct( \Magento\Checkout\Model\Session $session, \Magento\Quote\Api\CartManagementInterface $cartManagement, - \Magento\Framework\App\ProductMetadata $productMetadata + \Magento\Framework\App\ProductMetadata $productMetadata, + \Psr\Log\LoggerInterface $logger ) { $this->session = $session; $this->cartManagement = $cartManagement; $this->productMetadata = $productMetadata; + $this->logger = $logger; } /** @@ -62,21 +72,43 @@ public function aroundSavePaymentInformationAndPlaceOrder( \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress ) { - if (version_compare($this->productMetadata->getVersion(), '2.1.0', '>=') && - version_compare($this->productMetadata->getVersion(), '2.2.0', '<') && - strpos($paymentMethod->getMethod(), 'ratepay_') !== false - ) { // Problem only exists in Magento 2.1.X - $subject->savePaymentInformation($cartId, $paymentMethod, $billingAddress); - try { - $orderId = $this->cartManagement->placeOrder($cartId); - } catch (DisablePaymentMethodException $e) { - throw $e; - } catch (\Exception $e) { - throw new PaymentException(__($e->getMessage()), $e); + if (strpos($paymentMethod->getMethod(), 'ratepay_') !== false) { + if (version_compare($this->productMetadata->getVersion(), '2.1.0', '>=') && version_compare($this->productMetadata->getVersion(), '2.2.0', '<')) { + // Fixes a problem where Magento did not allow to pass through specific error messages in Magento 2.1.X + $subject->savePaymentInformation($cartId, $paymentMethod, $billingAddress); + try { + $orderId = $this->cartManagement->placeOrder($cartId); + } catch (DisablePaymentMethodException $e) { + throw $e; + } catch (\Exception $e) { + throw new PaymentException(__($e->getMessage()), $e); + } + return $orderId; } - return $orderId; + if (version_compare($this->productMetadata->getVersion(), '2.4.6', '>=')) { + // Fixes a problem where Magento forces the user back to the shipping address form when a payment error occured since Magento 2.4.6 + $subject->savePaymentInformation($cartId, $paymentMethod, $billingAddress); + try { + $orderId = $this->cartManagement->placeOrder($cartId); + } catch (DisablePaymentMethodException $e) { + throw $e; + } catch (LocalizedException $e) { + $this->logger->critical( + 'Placing an order with quote_id ' . $cartId . ' is failed: ' . $e->getMessage() + ); + throw $e; + } catch (\Exception $e) { + $this->logger->critical($e); + throw new CouldNotSaveException( + __('A server error stopped your order from being placed. Please try to place your order again.'), + $e + ); + } + return $orderId; + } } + // run core method return $proceed($cartId, $paymentMethod, $billingAddress); } diff --git a/view/frontend/web/js/view/messages-mixin.js b/view/frontend/web/js/view/messages-mixin.js index 1297f49..8e35b79 100644 --- a/view/frontend/web/js/view/messages-mixin.js +++ b/view/frontend/web/js/view/messages-mixin.js @@ -51,8 +51,11 @@ define([ } setTimeout(function () { - $(self.selector).hide('blind', {}, 500) - }, 20000); // show errorbox for 20 seconds instead auf 5 sec standard + $(self.selector).hide('slow'); + + //commented because effect-blind.js(1.13.1) is having show & hide issue + // $(this.selector).hide('blind', {}, this.hideSpeed); + }.bind(this), 20000); } }, removeAll: function () { From 1f12c6d2915dfb0de11e92f49dd3fffacc9015ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Wed, 29 Mar 2023 17:42:49 +0200 Subject: [PATCH 3/3] M2-121 - Fixed redirect to shipping address for guest checkout --- Plugin/RatepayGuestErrorProcessor.php | 80 +++++++++++++++++++++------ 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/Plugin/RatepayGuestErrorProcessor.php b/Plugin/RatepayGuestErrorProcessor.php index 83e6809..36f73ca 100644 --- a/Plugin/RatepayGuestErrorProcessor.php +++ b/Plugin/RatepayGuestErrorProcessor.php @@ -9,7 +9,10 @@ namespace RatePAY\Payment\Plugin; +use Magento\Framework\Exception\CouldNotSaveException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\PaymentException; +use RatePAY\Payment\Model\Exception\DisablePaymentMethodException; class RatepayGuestErrorProcessor { @@ -48,6 +51,11 @@ class RatepayGuestErrorProcessor */ protected $apiLog; + /** + * @var \Psr\Log\LoggerInterface + */ + private $logger; + /** * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Quote\Api\GuestBillingAddressManagementInterface $billingAddressManagement @@ -55,6 +63,7 @@ class RatepayGuestErrorProcessor * @param \Magento\Quote\Api\GuestCartManagementInterface $cartManagement * @param \Magento\Framework\App\ProductMetadata $productMetadata * @param \RatePAY\Payment\Model\ResourceModel\ApiLog $apiLog + * @param \Psr\Log\LoggerInterface $logger * @codeCoverageIgnore */ public function __construct( @@ -63,7 +72,8 @@ public function __construct( \Magento\Quote\Api\GuestPaymentMethodManagementInterface $paymentMethodManagement, \Magento\Quote\Api\GuestCartManagementInterface $cartManagement, \Magento\Framework\App\ProductMetadata $productMetadata, - \RatePAY\Payment\Model\ResourceModel\ApiLog $apiLog + \RatePAY\Payment\Model\ResourceModel\ApiLog $apiLog, + \Psr\Log\LoggerInterface $logger ) { $this->billingAddressManagement = $billingAddressManagement; $this->paymentMethodManagement = $paymentMethodManagement; @@ -71,6 +81,7 @@ public function __construct( $this->cartManagement = $cartManagement; $this->productMetadata = $productMetadata; $this->apiLog = $apiLog; + $this->logger = $logger; } /** @@ -91,31 +102,66 @@ public function aroundSavePaymentInformationAndPlaceOrder( \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress ) { - if (version_compare($this->productMetadata->getVersion(), '2.1.0', '>=') && - version_compare($this->productMetadata->getVersion(), '2.2.0', '<') && - strpos($paymentMethod->getMethod(), 'ratepay_') !== false - ) { // Problem only exists in Magento 2.1.X - $subject->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress); - try { - $orderId = $this->cartManagement->placeOrder($cartId); - } catch (\Exception $e) { - throw new PaymentException(__($e->getMessage()), $e); + if (strpos($paymentMethod->getMethod(), 'ratepay_') !== false) { + if (version_compare($this->productMetadata->getVersion(), '2.1.0', '>=') && + version_compare($this->productMetadata->getVersion(), '2.2.0', '<') + ) { // Problem only exists in Magento 2.1.X + $subject->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress); + try { + $orderId = $this->cartManagement->placeOrder($cartId); + } catch (\Exception $e) { + throw new PaymentException(__($e->getMessage()), $e); + } + + return $orderId; } - return $orderId; + if (version_compare($this->productMetadata->getVersion(), '2.4.6', '>=')) { + // Fixes a problem where Magento forces the user back to the shipping address form when a payment error occured since Magento 2.4.6 + $subject->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress); + try { + $orderId = $this->cartManagement->placeOrder($cartId); + } catch (DisablePaymentMethodException $e) { + throw $e; + } catch (LocalizedException $e) { + $this->logger->critical( + 'Placing an order with quote_id ' . $cartId . ' is failed: ' . $e->getMessage() + ); + throw $e; + } catch (\Exception $e) { + $this->handleApiLogEntry(); + $this->logger->critical($e); + throw new CouldNotSaveException( + __('A server error stopped your order from being placed. Please try to place your order again.'), + $e + ); + } + return $orderId; + } } // run core method try { $return = $proceed($cartId, $email, $paymentMethod, $billingAddress); } catch (\Exception $e) { - $request = $this->checkoutSession->getRatepayRequest(); - if (!empty($request)) { - // Rewrite the log-entry after it was rolled back in the db-transaction - $this->apiLog->addApiLogEntry($request); - } - $this->checkoutSession->unsRatepayRequest(); + $this->handleApiLogEntry(); throw $e; } return $return; } + + /** + * API log entry is lost in rollback when an error occured + * This writes it again after rollback + * + * @return void + */ + protected function handleApiLogEntry() + { + $request = $this->checkoutSession->getRatepayRequest(); + if (!empty($request)) { + // Rewrite the log-entry after it was rolled back in the db-transaction + $this->apiLog->addApiLogEntry($request); + } + $this->checkoutSession->unsRatepayRequest(); + } }