Skip to content

Commit b53fbed

Browse files
committed
ACP2E-1338: Google reCaptcha in Incorrect position
1 parent 0564dde commit b53fbed

File tree

4 files changed

+91
-2
lines changed

4 files changed

+91
-2
lines changed

ReCaptchaPaypal/Block/LayoutProcessor/Checkout/Onepage.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
1111
use Magento\Framework\Exception\InputException;
12+
use Magento\Paypal\Model\Config;
1213
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
1314
use Magento\ReCaptchaUi\Model\UiConfigResolverInterface;
1415

@@ -56,7 +57,12 @@ public function process($jsLayout)
5657
if ($this->isCaptchaEnabled->isCaptchaEnabledFor('place_order')) {
5758
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
5859
['payment']['children']['payments-list']['children']['before-place-order']['children']
59-
['place-order-recaptcha']['skipPayments']['payflowpro'] = true;
60+
['place-order-recaptcha']['skipPayments'] += [
61+
Config::METHOD_EXPRESS => true,
62+
Config::METHOD_PAYFLOWPRO => true,
63+
Config::METHOD_WPP_PE_EXPRESS => true,
64+
Config::METHOD_WPP_PE_BML => true,
65+
];
6066
}
6167
} else {
6268
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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\ReCaptchaPaypal\Plugin;
9+
10+
use Magento\Framework\Webapi\Rest\Request;
11+
use Magento\Paypal\Model\Config;
12+
use Magento\ReCaptchaCheckout\Model\WebapiConfigProvider;
13+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
14+
use Magento\ReCaptchaValidationApi\Api\Data\ValidationConfigInterface;
15+
use Magento\ReCaptchaWebapiApi\Api\Data\EndpointInterface;
16+
17+
class SkipPlaceOrderRecaptchaValidation
18+
{
19+
private const PAYPAL_PAYFLOWPRO_CAPTCHA_ID = 'paypal_payflowpro';
20+
21+
/**
22+
* @var IsCaptchaEnabledInterface
23+
*/
24+
private IsCaptchaEnabledInterface $isCaptchaEnabled;
25+
26+
/**
27+
* @var Request
28+
*/
29+
private Request $request;
30+
31+
/**
32+
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
33+
* @param Request $request
34+
*/
35+
public function __construct(
36+
IsCaptchaEnabledInterface $isCaptchaEnabled,
37+
Request $request
38+
) {
39+
$this->isCaptchaEnabled = $isCaptchaEnabled;
40+
$this->request = $request;
41+
}
42+
43+
/**
44+
* Skip captcha validation for "place order" button if captcha is enabled for payflow
45+
*
46+
* @param WebapiConfigProvider $subject
47+
* @param ValidationConfigInterface $result
48+
* @param EndpointInterface $endpoint
49+
* @return ValidationConfigInterface
50+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
51+
*/
52+
public function afterGetConfigFor(
53+
WebapiConfigProvider $subject,
54+
?ValidationConfigInterface $result,
55+
EndpointInterface $endpoint
56+
): ?ValidationConfigInterface {
57+
58+
if ($result && $this->isCaptchaEnabled->isCaptchaEnabledFor(self::PAYPAL_PAYFLOWPRO_CAPTCHA_ID)) {
59+
$bodyParams = $this->request->getBodyParams();
60+
$paymentMethod = $bodyParams['paymentMethod'] ?? $bodyParams['payment_method'] ?? [];
61+
if (isset($paymentMethod['method']) && $paymentMethod['method'] === Config::METHOD_PAYFLOWPRO) {
62+
return null;
63+
}
64+
}
65+
66+
return $result;
67+
}
68+
}

ReCaptchaPaypal/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"magento/module-re-captcha-ui": "*",
88
"magento/module-re-captcha-validation-api": "*",
99
"magento/module-checkout": "*",
10-
"magento/module-re-captcha-webapi-api": "*"
10+
"magento/module-re-captcha-webapi-api": "*",
11+
"magento/module-paypal": "*",
12+
"magento/module-re-captcha-checkout": "*"
1113
},
1214
"type": "magento2-module",
1315
"license": "OSL-3.0",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10+
<type name="Magento\ReCaptchaCheckout\Model\WebapiConfigProvider">
11+
<plugin name="skip_place_order_recaptcha_validation" type="Magento\ReCaptchaPaypal\Plugin\SkipPlaceOrderRecaptchaValidation"/>
12+
</type>
13+
</config>

0 commit comments

Comments
 (0)