Skip to content

Commit

Permalink
Merge pull request #96 from ratepay/M2-121-Magento2.4.6-compatibility
Browse files Browse the repository at this point in the history
M2-121 - Added compatibility for Magento 2.4.6 and PHP 8.2
  • Loading branch information
FatchipRobert authored May 9, 2023
2 parents 0a62468 + 1f12c6d commit 3c94c43
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 32 deletions.
5 changes: 5 additions & 0 deletions Block/Checkout/InstallmentPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

class InstallmentPlan extends \Magento\Framework\View\Element\Template
{
/**
* @var \Magento\Framework\View\Asset\Repository
*/
protected $assetRepo;

/**
* Constructor
*
Expand Down
5 changes: 5 additions & 0 deletions Helper/ProfileConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class ProfileConfig extends \Magento\Framework\App\Helper\AbstractHelper
*/
protected $profileConfigResource;

/**
* @var Data
*/
protected $ratepayHelper;

/**
* @var \RatePAY\Payment\Model\Entities\ProfileConfigurationFactory
*/
Expand Down
20 changes: 20 additions & 0 deletions Model/LibraryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
58 changes: 45 additions & 13 deletions Plugin/RatepayErrorProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

/**
Expand All @@ -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);
}
Expand Down
85 changes: 68 additions & 17 deletions Plugin/RatepayGuestErrorProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -23,6 +26,11 @@ class RatepayGuestErrorProcessor
*/
protected $paymentInformationManagement;

/**
* @var \Magento\Quote\Api\GuestPaymentMethodManagementInterface
*/
protected $paymentMethodManagement;

/**
* @var \Magento\Checkout\Model\Session
*/
Expand All @@ -43,13 +51,19 @@ class RatepayGuestErrorProcessor
*/
protected $apiLog;

/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;

/**
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Quote\Api\GuestBillingAddressManagementInterface $billingAddressManagement
* @param \Magento\Quote\Api\GuestPaymentMethodManagementInterface $paymentMethodManagement
* @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(
Expand All @@ -58,14 +72,16 @@ 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;
$this->checkoutSession = $checkoutSession;
$this->cartManagement = $cartManagement;
$this->productMetadata = $productMetadata;
$this->apiLog = $apiLog;
$this->logger = $logger;
}

/**
Expand All @@ -86,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();
}
}
7 changes: 5 additions & 2 deletions view/frontend/web/js/view/messages-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 3c94c43

Please sign in to comment.