Skip to content

Commit c126e1c

Browse files
committed
MC-41001: CAPTCHA fields not displaying after unsuccessful number of attempts in Checkout for 3rd-party payment providers
1 parent f258736 commit c126e1c

File tree

7 files changed

+95
-3
lines changed

7 files changed

+95
-3
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Captcha\Plugin;
7+
8+
use Magento\Captcha\Helper\Data as HelperCaptcha;
9+
use Magento\Captcha\Model\ResourceModel\LogFactory;
10+
use Magento\Sales\Api\Data\OrderInterface;
11+
use Magento\Sales\Api\OrderManagementInterface;
12+
13+
/**
14+
* Reset attempts for frontend checkout
15+
*/
16+
class FrontendOrderPlacementPlugin
17+
{
18+
/**
19+
* Form ID
20+
*/
21+
private const FORM_ID = 'payment_processing_request';
22+
23+
/**
24+
* @var HelperCaptcha
25+
*/
26+
private HelperCaptcha $helper;
27+
28+
/**
29+
* @var LogFactory
30+
*/
31+
private $resLogFactory;
32+
33+
/**
34+
* ResetAttemptForFrontendAccountEditObserver constructor
35+
*
36+
* @param HelperCaptcha $helper
37+
* @param LogFactory $resLogFactory
38+
*/
39+
public function __construct(
40+
HelperCaptcha $helper,
41+
LogFactory $resLogFactory
42+
) {
43+
$this->helper = $helper;
44+
$this->resLogFactory = $resLogFactory;
45+
}
46+
47+
/**
48+
* Reset attempts for frontend checkout
49+
*
50+
* @param OrderManagementInterface $subject
51+
* @param OrderInterface $result
52+
* @param OrderInterface $order
53+
* @return OrderInterface
54+
*/
55+
public function afterPlace(
56+
OrderManagementInterface $subject,
57+
OrderInterface $result,
58+
OrderInterface $order
59+
): OrderInterface {
60+
$captchaModel = $this->helper->getCaptcha(self::FORM_ID);
61+
$captchaModel->setShowCaptchaInSession(false);
62+
$this->resLogFactory->create()->deleteUserAttempts($order->getCustomerEmail());
63+
return $result;
64+
}
65+
}

app/code/Magento/Captcha/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"magento/module-backend": "*",
1111
"magento/module-checkout": "*",
1212
"magento/module-customer": "*",
13+
"magento/module-sales": "*",
1314
"magento/module-store": "*",
1415
"magento/module-authorization": "*",
1516
"laminas/laminas-captcha": "^2.7.1",

app/code/Magento/Captcha/etc/frontend/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@
3434
</argument>
3535
</arguments>
3636
</type>
37+
<type name="Magento\Sales\Api\OrderManagementInterface">
38+
<plugin name="frontend_order_placement_reset_captcha_attempt" type="Magento\Captcha\Plugin\FrontendOrderPlacementPlugin"/>
39+
</type>
3740
</config>

app/code/Magento/Captcha/etc/frontend/sections.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@
1010
<action name="customer/ajax/login">
1111
<section name="captcha"/>
1212
</action>
13+
<action name="rest/*/V1/carts/*/payment-information">
14+
<section name="captcha"/>
15+
</action>
16+
<action name="rest/*/V1/guest-carts/*/payment-information">
17+
<section name="captcha"/>
18+
</action>
1319
</config>

app/code/Magento/Captcha/etc/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<sequence>
1111
<module name="Magento_Customer"/>
1212
<module name="Magento_Checkout"/>
13+
<module name="Magento_Sales"/>
1314
</sequence>
1415
</module>
1516
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Sales\Api\OrderManagementInterface">
10+
<plugin name="frontend_order_placement_reset_captcha_attempt" type="Magento\Captcha\Plugin\FrontendOrderPlacementPlugin"/>
11+
</type>
12+
</config>

app/code/Magento/Captcha/view/frontend/web/js/view/checkout/defaultCaptcha.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ define([
2121
},
2222
dataScope: 'global',
2323
currentCaptcha: null,
24+
subscribedFormIds: [],
2425

2526
/**
2627
* @return {*}
@@ -74,9 +75,12 @@ define([
7475
* @param {Object} captcha
7576
*/
7677
subscribeCustomerData: function (formId, captcha) {
77-
customerData.get('captcha').subscribe(function (captchaData) {
78-
this.checkCustomerData(formId, captchaData, captcha);
79-
}.bind(this));
78+
if (this.subscribedFormIds.includes(formId) === false) {
79+
this.subscribedFormIds.push(formId);
80+
customerData.get('captcha').subscribe(function (captchaData) {
81+
this.checkCustomerData(formId, captchaData, captcha);
82+
}.bind(this));
83+
}
8084
},
8185

8286
/**

0 commit comments

Comments
 (0)