|
| 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 | +} |
0 commit comments