Skip to content

Commit 216af65

Browse files
Merge pull request #109 from magento-cia/pre-release-develop-sync-03062023
Sync of pre-release with develop
2 parents c3bd993 + cc61800 commit 216af65

File tree

45 files changed

+2187
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2187
-384
lines changed

.github/CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Contributions to the Magento 2 codebase are done using the fork & pull model.
44
This contribution model has contributors maintaining their own fork of the Magento 2 repository.
5-
The forked repository is then used to submit a request to the base repository to pull a set of changes.
5+
The forked repository is then used to submit a request to the base repository to "pull" a set of changes.
66
For more information on pull requests please refer to [GitHub Help](https://help.github.com/articles/about-pull-requests/).
77

88
Contributions can take the form of new components or features, changes to existing features, tests, documentation (such as developer guides, user guides, examples, or specifications), bug fixes or optimizations.
@@ -15,7 +15,7 @@ For more detailed information on contribution please read our [beginners guide](
1515

1616
## Contribution requirements
1717

18-
1. Contributions must adhere to the [Magento coding standards](https://devdocs.magento.com/guides/v2.3/coding-standards/bk-coding-standards.html).
18+
1. Contributions must adhere to the [Magento coding standards](https://developer.adobe.com/commerce/php/coding-standards/).
1919
2. Pull requests (PRs) must be accompanied by a meaningful description of their purpose. Comprehensive descriptions increase the chances of a pull request being merged quickly and without additional clarification requests.
2020
3. Commits must be accompanied by meaningful commit messages. Please see the [Magento Pull Request Template](https://github.com/magento/magento2/blob/2.3-develop/.github/PULL_REQUEST_TEMPLATE.md) for more information.
2121
4. PRs which include bug fixes must be accompanied with a step-by-step description of how to reproduce the bug.
@@ -33,7 +33,7 @@ This will allow you to collaborate with the Magento 2 development team, fork the
3333
1. Search current [listed issues](https://github.com/magento/magento2/issues) (open or closed) for similar proposals of intended contribution before starting work on a new contribution.
3434
2. Sign the [Adobe Contributor License Agreement](https://opensource.adobe.com/cla.html) if you have not signed it before.
3535
3. Create and test your work.
36-
4. Fork the Magento 2 repository according to the [Fork A Repository instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#fork) and when you are ready to send us a pull request – follow the [Create A Pull Request instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#pull_request).
36+
4. Fork the Magento 2 repository according to the [Fork A Repository instructions](https://developer.adobe.com/commerce/contributor/guides/code-contributions/) and when you are ready to send us a pull request – follow the [Create A Pull Request instructions](https://developer.adobe.com/commerce/contributor/guides/code-contributions/).
3737
5. Once your contribution is received the Magento 2 development team will review the contribution and collaborate with you as needed.
3838

3939
## Code of Conduct

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ disclosure practices.
1111

1212
- Complete documentation located on the project [wiki pages](https://github.com/magento/security-package/wiki):
1313
- How to start local development described in the [installation guide](https://github.com/magento/security-package/wiki/Metapackage-Installation-Guide)
14-
- Two-factor authentication [user guide](https://docs.magento.com/user-guide/stores/security-two-factor-authentication.html) and [technical guide](https://devdocs.magento.com/guides/v2.4/security/two-factor-authentication.html).
15-
- Google ReCAPTCHA [user guide](https://docs.magento.com/user-guide/stores/security-google-recaptcha.html) and [technical guide](https://devdocs.magento.com/guides/v2.4/security/google-recaptcha.html).
16-
- Security.txt [user guide](https://docs.magento.com/user-guide/configuration/security/security-txt.html) and [technical guide](https://devdocs.magento.com/guides/v2.4/security/security-txt.html).
14+
- Two-factor authentication [user guide](https://docs.magento.com/user-guide/stores/security-two-factor-authentication.html) and [technical guide](https://developer.adobe.com/commerce/testing/functional-testing-framework/two-factor-authentication/).
15+
- Google ReCAPTCHA [user guide](https://docs.magento.com/user-guide/stores/security-google-recaptcha.html) and [technical guide](https://experienceleague.adobe.com/docs/commerce-admin/systems/security/captcha/security-google-recaptcha.html).
16+
- Security.txt [user guide](https://docs.magento.com/user-guide/configuration/security/security-txt.html) and [technical guide](https://experienceleague.adobe.com/docs/commerce-operations/configuration-guide/security/security-txt.html).
1717

1818
## Community Engineering Slack
1919

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
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ReCaptchaCheckout\Test\Unit\Block\LayoutProcessor\Checkout;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\ReCaptchaCheckout\Block\LayoutProcessor\Checkout\Onepage;
12+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
13+
use Magento\ReCaptchaUi\Model\UiConfigResolverInterface;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class OnepageTest extends TestCase
18+
{
19+
/**
20+
* @var UiConfigResolverInterface|MockObject
21+
*/
22+
private $uiConfigResolver;
23+
24+
/**
25+
* @var IsCaptchaEnabledInterface|MockObject
26+
*/
27+
private $isCaptchEnabled;
28+
29+
/**
30+
* @var Onepage
31+
*/
32+
private $model;
33+
34+
/**
35+
* @var array
36+
*/
37+
private $jsLayout = [
38+
'components' => [
39+
'checkout' => [
40+
'children' => [
41+
'steps' => [
42+
'children' => [
43+
'shipping-step' => [
44+
'children' => [
45+
'shippingAddress' => [
46+
'children' => [
47+
'customer-email' => [
48+
'children' => [
49+
'recaptcha' => []
50+
]
51+
]
52+
]
53+
]
54+
]
55+
],
56+
'billing-step' => [
57+
'children' => [
58+
'payment' => [
59+
'children' => [
60+
'customer-email' => [
61+
'children' => [
62+
'recaptcha' => []
63+
]
64+
],
65+
'payments-list' => [
66+
'children' => [
67+
'before-place-order' => [
68+
'children' => [
69+
'place-order-recaptcha' => []
70+
]
71+
]
72+
]
73+
]
74+
]
75+
]
76+
]
77+
]
78+
]
79+
],
80+
'authentication' => [
81+
'children' => [
82+
'recaptcha' => []
83+
]
84+
]
85+
]
86+
]
87+
]
88+
];
89+
90+
/**
91+
* @inheritdoc
92+
*/
93+
protected function setUp(): void
94+
{
95+
parent::setUp();
96+
$this->uiConfigResolver = $this->getMockForAbstractClass(UiConfigResolverInterface::class);
97+
$this->isCaptchEnabled = $this->getMockForAbstractClass(IsCaptchaEnabledInterface::class);
98+
$this->model = new Onepage(
99+
$this->uiConfigResolver,
100+
$this->isCaptchEnabled
101+
);
102+
}
103+
104+
/**
105+
* @dataProvider processDataProvider
106+
*/
107+
public function testProcess(array $mocks, array $expected): void
108+
{
109+
$this->uiConfigResolver->method('get')
110+
->willReturnMap($mocks['uiConfigResolver']);
111+
$this->isCaptchEnabled->method('isCaptchaEnabledFor')
112+
->willReturnMap($mocks['isCaptchaEnabled']);
113+
$prefix = 'components/checkout/children/';
114+
$config = new DataObject($this->model->process($this->jsLayout));
115+
$actual = [];
116+
foreach (array_keys($expected) as $path) {
117+
$actual[$path] = $config->getDataByPath($prefix.$path);
118+
}
119+
$this->assertSame($expected, $actual);
120+
}
121+
122+
public function processDataProvider(): array
123+
{
124+
return [
125+
[
126+
[
127+
'isCaptchaEnabled' => [
128+
['customer_login', false],
129+
['place_order', false],
130+
],
131+
'uiConfigResolver' => [
132+
['customer_login', ['type' => 'invisible']],
133+
['place_order', ['type' => 'robot']],
134+
],
135+
],
136+
[
137+
'steps/children/shipping-step/children/shippingAddress/children/customer-email/children' => [],
138+
'steps/children/billing-step/children/payment/children/customer-email/children' => [],
139+
'authentication/children' => [],
140+
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' .
141+
'children' => [],
142+
]
143+
],
144+
[
145+
[
146+
'isCaptchaEnabled' => [
147+
['customer_login', true],
148+
['place_order', true],
149+
],
150+
'uiConfigResolver' => [
151+
['customer_login', ['type' => 'invisible']],
152+
['place_order', ['type' => 'robot']],
153+
],
154+
],
155+
[
156+
'steps/children/shipping-step/children/shippingAddress/children/' .
157+
'customer-email/children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]],
158+
'steps/children/billing-step/children/payment/children/' .
159+
'customer-email/children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]],
160+
'authentication/children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]],
161+
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' .
162+
'children' => ['place-order-recaptcha' => ['settings' => ['type' => 'robot']]],
163+
]
164+
]
165+
];
166+
}
167+
}

ReCaptchaCheckout/view/frontend/layout/checkout_index_index.xml

Lines changed: 7 additions & 7 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>
61-
<item name="displayArea" xsi:type="string">place-order-recaptcha</item>
57+
<item name="component" xsi:type="string">Magento_ReCaptchaCheckout/js/reCaptchaCheckout</item>
58+
<item name="displayArea" xsi:type="string">before-place-order</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: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ define([
1414

1515
return function (placeOrder) {
1616
return wrapper.wrap(placeOrder, function (originalAction, serviceUrl, payload, messageContainer) {
17-
var recaptchaDeferred;
17+
var recaptchaDeferred,
18+
reCaptchaId,
19+
$activeReCaptcha;
1820

19-
if (recaptchaRegistry.triggers.hasOwnProperty('recaptcha-checkout-place-order')) {
21+
$activeReCaptcha = $('.recaptcha-checkout-place-order:visible .g-recaptcha');
22+
23+
if ($activeReCaptcha.length > 0) {
24+
reCaptchaId = $activeReCaptcha.last().attr('id');
25+
}
26+
27+
if (reCaptchaId !== undefined && recaptchaRegistry.triggers.hasOwnProperty(reCaptchaId)) {
2028
//ReCaptcha is present for checkout
2129
recaptchaDeferred = $.Deferred();
22-
recaptchaRegistry.addListener('recaptcha-checkout-place-order', function (token) {
30+
recaptchaRegistry.addListener(reCaptchaId, function (token) {
2331
//Add reCaptcha value to place-order request and resolve deferred with the API call results
2432
payload.xReCaptchaValue = token;
2533
originalAction(serviceUrl, payload, messageContainer).done(function () {
@@ -29,9 +37,16 @@ define([
2937
});
3038
});
3139
//Trigger ReCaptcha validation
32-
recaptchaRegistry.triggers['recaptcha-checkout-place-order']();
33-
//remove listener so that place order action is only triggered by the 'Place Order' button
34-
recaptchaRegistry.removeListener('recaptcha-checkout-place-order');
40+
recaptchaRegistry.triggers[reCaptchaId]();
41+
42+
if (
43+
!recaptchaRegistry._isInvisibleType.hasOwnProperty(reCaptchaId) ||
44+
recaptchaRegistry._isInvisibleType[reCaptchaId] === false
45+
) {
46+
//remove listener so that place order action is only triggered by the 'Place Order' button
47+
recaptchaRegistry.removeListener(reCaptchaId);
48+
}
49+
3550
return recaptchaDeferred;
3651
}
3752

0 commit comments

Comments
 (0)