Skip to content

Commit 584a492

Browse files
committed
ACP2E-1338: Google reCaptcha in Incorrect position
1 parent 0e537a5 commit 584a492

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

ReCaptchaCheckout/view/frontend/web/js/model/place-order-mixin.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@
44
*/
55

66
/* eslint-disable max-nested-callbacks */
7-
/* eslint-disable max-depth */
87

98
define([
109
'jquery',
1110
'mage/utils/wrapper',
12-
'Magento_ReCaptchaWebapiUi/js/webapiReCaptchaRegistry',
13-
'Magento_Checkout/js/model/quote'
14-
], function ($, wrapper, recaptchaRegistry, quote) {
11+
'Magento_ReCaptchaWebapiUi/js/webapiReCaptchaRegistry'
12+
], function ($, wrapper, recaptchaRegistry) {
1513
'use strict';
1614

1715
return function (placeOrder) {
1816
return wrapper.wrap(placeOrder, function (originalAction, serviceUrl, payload, messageContainer) {
1917
var recaptchaDeferred,
20-
reCaptchaId;
18+
reCaptchaId,
19+
$activeReCaptcha;
2120

22-
if (quote.paymentMethod()) {
23-
reCaptchaId = 'recaptcha-checkout-place-order-' + quote.paymentMethod().method;
21+
$activeReCaptcha = $('.recaptcha-checkout-place-order:visible .g-recaptcha');
22+
23+
if ($activeReCaptcha.length > 0) {
24+
reCaptchaId = $activeReCaptcha.last().attr('id');
2425
}
2526

2627
if (reCaptchaId !== undefined && recaptchaRegistry.triggers.hasOwnProperty(reCaptchaId)) {

ReCaptchaCheckout/view/frontend/web/js/reCaptchaCheckout.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ define(
1111
function (Component, $) {
1212
'use strict';
1313

14+
var reCaptchaIds = new WeakMap(),
15+
uuid = 0;
16+
1417
return Component.extend({
1518
defaults: {
1619
template: 'Magento_ReCaptchaCheckout/reCaptcha',
@@ -38,7 +41,10 @@ define(
3841
* @returns {String}
3942
*/
4043
getReCaptchaIdFor: function (method) {
41-
return this.getReCaptchaId() + '-' + method.getCode();
44+
if (!reCaptchaIds.has(method)) {
45+
reCaptchaIds.set(method, this.getReCaptchaId() + '-' + uuid++);
46+
}
47+
return reCaptchaIds.get(method);
4248
},
4349

4450
/**

ReCaptchaCheckout/view/frontend/web/template/reCaptcha.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
-->
77
<!-- ko if: (isCheckoutReCaptchaRequiredFor($parents[1]))-->
8-
<div data-bind="{
8+
<div class="recaptcha-checkout-place-order" data-bind="{
99
attr: {
1010
'id': getReCaptchaIdFor($parents[1]) + '-wrapper'
1111
},

0 commit comments

Comments
 (0)