From da5d85140c8b7096496146d67a11cafa80d53152 Mon Sep 17 00:00:00 2001 From: Preston Choate Date: Fri, 28 Jan 2022 11:19:03 -0500 Subject: [PATCH 1/2] Added gitignore, changelog, and additional plugin function --- .gitignore | 2 ++ CHANGELOG.md | 4 +++ .../Model/CardingPreventionPlugin.php | 28 ++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 CHANGELOG.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1814a26 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +nohup.out +.idea \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a87b903 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog + +## 1.1.0 +* Added plugin for `savePaymentInformation` function as some customized checkouts make a call to this guest cart function as well \ No newline at end of file diff --git a/Plugin/Magento/Checkout/Model/CardingPreventionPlugin.php b/Plugin/Magento/Checkout/Model/CardingPreventionPlugin.php index e0da380..3bd6e7a 100644 --- a/Plugin/Magento/Checkout/Model/CardingPreventionPlugin.php +++ b/Plugin/Magento/Checkout/Model/CardingPreventionPlugin.php @@ -41,7 +41,6 @@ public function __construct( * @param $email * @param PaymentInterface $paymentMethod * @param AddressInterface|null $billingAddress - * @throws AuthorizationException */ public function beforeSavePaymentInformationAndPlaceOrder( GuestPaymentInformationManagement $subject, @@ -49,6 +48,33 @@ public function beforeSavePaymentInformationAndPlaceOrder( $email, PaymentInterface $paymentMethod, AddressInterface $billingAddress = null) + { + $this->checkCartId($cartId); + } + + /** + * @param GuestPaymentInformationManagement $subject + * @param $cartId + * @param $email + * @param PaymentInterface $paymentMethod + * @param AddressInterface|null $billingAddress + */ + public function beforeSavePaymentInformation( + GuestPaymentInformationManagement $subject, + $cartId, + $email, + PaymentInterface $paymentMethod, + AddressInterface $billingAddress = null) + { + $this->checkCartId($cartId); + } + + /** + * Checks cart ID and throws exception if it has been used too frequently + * + * @param $cartId + */ + protected function checkCartId($cartId) { $lifetime = $this->config->getThreshold(); $lifetime = ctype_digit($lifetime) ? intval($lifetime) : 0; From b1399dc7da436bf25377c1e7c5d3a297c5d4d584 Mon Sep 17 00:00:00 2001 From: Preston Choate Date: Fri, 28 Jan 2022 12:13:59 -0500 Subject: [PATCH 2/2] Removed secondary plugin function, changed exception type --- CHANGELOG.md | 3 ++- .../Model/CardingPreventionPlugin.php | 21 ++----------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a87b903..64360dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Changelog ## 1.1.0 -* Added plugin for `savePaymentInformation` function as some customized checkouts make a call to this guest cart function as well \ No newline at end of file +* Extracted call for checking cart to its own function +* Changed type of exception that is thrown to prevent redirects \ No newline at end of file diff --git a/Plugin/Magento/Checkout/Model/CardingPreventionPlugin.php b/Plugin/Magento/Checkout/Model/CardingPreventionPlugin.php index 3bd6e7a..7036351 100644 --- a/Plugin/Magento/Checkout/Model/CardingPreventionPlugin.php +++ b/Plugin/Magento/Checkout/Model/CardingPreventionPlugin.php @@ -8,9 +8,9 @@ namespace PrestonChoate\CardingPrevention\Plugin\Magento\Checkout\Model; use PrestonChoate\CardingPrevention\Model\Config; +use Magento\Checkout\Exception as CheckoutException; use Magento\Checkout\Model\GuestPaymentInformationManagement; use Magento\Framework\App\CacheInterface; -use Magento\Framework\Exception\AuthorizationException; use Magento\Quote\Api\Data\AddressInterface; use Magento\Quote\Api\Data\PaymentInterface; @@ -52,23 +52,6 @@ public function beforeSavePaymentInformationAndPlaceOrder( $this->checkCartId($cartId); } - /** - * @param GuestPaymentInformationManagement $subject - * @param $cartId - * @param $email - * @param PaymentInterface $paymentMethod - * @param AddressInterface|null $billingAddress - */ - public function beforeSavePaymentInformation( - GuestPaymentInformationManagement $subject, - $cartId, - $email, - PaymentInterface $paymentMethod, - AddressInterface $billingAddress = null) - { - $this->checkCartId($cartId); - } - /** * Checks cart ID and throws exception if it has been used too frequently * @@ -88,7 +71,7 @@ protected function checkCartId($cartId) $value = $this->cache->load($cartId); $this->cache->save($data, $cartId, $tags, $lifetime); if ($value) { - throw new AuthorizationException(__('Too many requests')); + throw new CheckoutException(__('Too many requests')); } }