Skip to content

Commit 06ac0f3

Browse files
committed
ACP2E-1338: Google reCaptcha in Incorrect position
1 parent 4b1ac02 commit 06ac0f3

File tree

6 files changed

+100
-16
lines changed

6 files changed

+100
-16
lines changed

ReCaptchaCheckout/Block/LayoutProcessor/Checkout/Onepage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public function process($jsLayout)
7575
$key = 'place_order';
7676
if ($this->isCaptchaEnabled->isCaptchaEnabledFor($key)) {
7777
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
78-
['payment']['children']['beforeMethods']['children']['place-order-recaptcha-container']['children']
78+
['payment']['children']['payments-list']['children']['before-place-order']['children']
7979
['place-order-recaptcha']['settings'] = $this->captchaUiConfigResolver->get($key);
8080
} else {
8181
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
82-
['payment']['children']['beforeMethods']['children']['place-order-recaptcha-container']['children']
82+
['payment']['children']['payments-list']['children']['before-place-order']['children']
8383
['place-order-recaptcha'])) {
8484
unset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
85-
['payment']['children']['beforeMethods']['children']['place-order-recaptcha-container']
85+
['payment']['children']['payments-list']['children']['before-place-order']
8686
['children']['place-order-recaptcha']);
8787
}
8888
}

ReCaptchaCheckout/view/frontend/layout/checkout_index_index.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@
4949
</item>
5050
</item>
5151
</item>
52-
<item name="beforeMethods" xsi:type="array">
52+
<item name="payments-list" xsi:type="array">
5353
<item name="children" xsi:type="array">
54-
<item name="place-order-recaptcha-container" xsi:type="array">
55-
<item name="component" xsi:type="string">uiComponent</item>
56-
<item name="template" xsi:type="string">Magento_ReCaptchaCheckout/payment-recaptcha-container</item>
57-
<item name="displayArea" xsi:type="string">beforeMethods</item>
54+
<item name="before-place-order" xsi:type="array">
5855
<item name="children" xsi:type="array">
5956
<item name="place-order-recaptcha" xsi:type="array">
60-
<item name="component" xsi:type="string">Magento_ReCaptchaWebapiUi/js/webapiReCaptcha</item>
57+
<item name="component" xsi:type="string">Magento_ReCaptchaCheckout/js/reCaptchaCheckout</item>
6158
<item name="displayArea" xsi:type="string">place-order-recaptcha</item>
6259
<item name="configSource" xsi:type="string">checkoutConfig</item>
6360
<item name="reCaptchaId" xsi:type="string">recaptcha-checkout-place-order</item>
61+
<item name="skipPayments" xsi:type="array">
62+
63+
</item>
6464
</item>
6565
</item>
6666
</item>

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@
44
*/
55

66
/* eslint-disable max-nested-callbacks */
7+
/* eslint-disable max-depth */
78

89
define([
910
'jquery',
1011
'mage/utils/wrapper',
11-
'Magento_ReCaptchaWebapiUi/js/webapiReCaptchaRegistry'
12-
], function ($, wrapper, recaptchaRegistry) {
12+
'Magento_ReCaptchaWebapiUi/js/webapiReCaptchaRegistry',
13+
'Magento_Checkout/js/model/quote'
14+
], function ($, wrapper, recaptchaRegistry, quote) {
1315
'use strict';
1416

1517
return function (placeOrder) {
1618
return wrapper.wrap(placeOrder, function (originalAction, serviceUrl, payload, messageContainer) {
17-
var recaptchaDeferred;
19+
var recaptchaDeferred,
20+
reCaptchaId;
1821

19-
if (recaptchaRegistry.triggers.hasOwnProperty('recaptcha-checkout-place-order')) {
22+
if (quote.paymentMethod()) {
23+
reCaptchaId = 'recaptcha-checkout-place-order-' + quote.paymentMethod().method;
24+
}
25+
26+
if (reCaptchaId !== undefined && recaptchaRegistry.triggers.hasOwnProperty(reCaptchaId)) {
2027
//ReCaptcha is present for checkout
2128
recaptchaDeferred = $.Deferred();
22-
recaptchaRegistry.addListener('recaptcha-checkout-place-order', function (token) {
29+
recaptchaRegistry.addListener(reCaptchaId, function (token) {
2330
//Add reCaptcha value to place-order request and resolve deferred with the API call results
2431
payload.xReCaptchaValue = token;
2532
originalAction(serviceUrl, payload, messageContainer).done(function () {
@@ -29,9 +36,9 @@ define([
2936
});
3037
});
3138
//Trigger ReCaptcha validation
32-
recaptchaRegistry.triggers['recaptcha-checkout-place-order']();
39+
recaptchaRegistry.triggers[reCaptchaId]();
3340
//remove listener so that place order action is only triggered by the 'Place Order' button
34-
recaptchaRegistry.removeListener('recaptcha-checkout-place-order');
41+
recaptchaRegistry.removeListener(reCaptchaId);
3542
return recaptchaDeferred;
3643
}
3744

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
// jscs:disable jsDoc
7+
8+
/* global grecaptcha */
9+
define(
10+
[
11+
'Magento_ReCaptchaWebapiUi/js/webapiReCaptcha',
12+
'jquery'
13+
],
14+
function (Component, $) {
15+
'use strict';
16+
17+
return Component.extend({
18+
defaults: {
19+
template: 'Magento_ReCaptchaCheckout/reCaptcha',
20+
skipPayments: []
21+
},
22+
23+
/**
24+
* Render reCAPTCHA
25+
*/
26+
renderReCaptchaForPayment: function (method) {
27+
var reCaptcha;
28+
29+
if (!this.skipPayments || !this.skipPayments.hasOwnProperty(method.getCode())) {
30+
reCaptcha = $.extend({}, this);
31+
32+
reCaptcha.reCaptchaId = this.getPaymentReCaptchaId(method);
33+
reCaptcha.renderReCaptcha();
34+
}
35+
},
36+
37+
/**
38+
* Render reCAPTCHA
39+
*/
40+
getPaymentReCaptchaId: function (method) {
41+
return this.getReCaptchaId() + '-' + method.getCode();
42+
}
43+
});
44+
}
45+
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
8+
<div data-bind="{
9+
attr: {
10+
'id': getPaymentReCaptchaId($parents[1]) + '-wrapper'
11+
},
12+
'afterRender': renderReCaptchaForPayment($parents[1])
13+
}">
14+
<div class="g-recaptcha"></div>
15+
<!-- ko if: (!getIsInvisibleRecaptcha()) -->
16+
<div class="field">
17+
<div class="control">
18+
<input type="checkbox"
19+
value=""
20+
class="required-captcha checkbox"
21+
name="recaptcha-validate-"
22+
data-validate="{required:true}"
23+
tabindex="-1">
24+
</div>
25+
</div>
26+
<!-- /ko -->
27+
</div>

ReCaptchaPaypal/Block/LayoutProcessor/Checkout/Onepage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public function process($jsLayout)
5353
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
5454
['payment']['children']['payments-list']['children']['paypal-captcha']['children']
5555
['recaptcha']['settings'] = $this->captchaUiConfigResolver->get($key);
56+
if ($this->isCaptchaEnabled->isCaptchaEnabledFor('place_order')) {
57+
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
58+
['payment']['children']['payments-list']['children']['before-place-order']['children']
59+
['place-order-recaptcha']['skipPayments']['payflowpro'] = true;
60+
}
5661
} else {
5762
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
5863
['payment']['children']['payments-list']['children']['paypal-captcha']['children']['recaptcha'])) {

0 commit comments

Comments
 (0)