The ReCaptchaCheckoutSalesRule module adds a new layoutProcessor.
In my code the form was moved using a plugin on the file Magento\Checkout\Block\Checkout\LayoutProcessor
In this way the form was moved before the recaptcha was configured using the function:
public function process($jsLayout)
{
$key = 'coupon_code';
if ($this->isCaptchaEnabled->isCaptchaEnabledFor($key)) {
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['afterMethods']['children']['discount']['children']
['checkout_sales_rule']['settings'] = $this->captchaUiConfigResolver->get($key);
} else {
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['afterMethods']['children']['discount']['children']['checkout_sales_rule'])) {
unset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['afterMethods']['children']['discount']['children']['checkout_sales_rule']);
}
}
return $jsLayout;
}
in Magento\ReCaptchaCheckoutSalesRule\Block\LayoutProcessor\Checkout\Onepage
So I had to create a new plugin for the latter file and move the code from the previous plugin to the new one
<?php
namespace Vendor\Module\Plugin\Checkout;
class MoveDiscountForm
{
protected $logger;
public function __construct(
\Psr\Log\LoggerInterface $logger
)
{
$this->logger = $logger;
}
/**
* @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
* @param array $jsLayout
* @return array
*/
public function afterProcess(
\Magento\ReCaptchaCheckoutSalesRule\Block\LayoutProcessor\Checkout\Onepage $subject,
array $jsLayout
) {
//move discount to beforeMethods
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['afterMethods']['children']['discount'])) {
$discountFormBefore = &$jsLayout['components']['checkout']['children']['steps']
['children']['billing-step']['children']['payment']['children']
['beforeMethods']['children']['discount'];
$discountFormBefore = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['afterMethods']['children']['discount'];
unset($jsLayout['components']['checkout']['children']['steps']
['children']['billing-step']['children']['payment']
['children']['afterMethods']['children']['discount']);
}
return $jsLayout;
}
}