diff --git a/vendor/magento/module-re-captcha-checkout/view/frontend/requirejs-config.js b/vendor/magento/module-re-captcha-checkout/view/frontend/requirejs-config.js index 2c6f3490..57feceac 100644 --- a/vendor/magento/module-re-captcha-checkout/view/frontend/requirejs-config.js +++ b/vendor/magento/module-re-captcha-checkout/view/frontend/requirejs-config.js @@ -9,7 +9,11 @@ var config = { mixins: { 'Magento_Checkout/js/model/place-order': { 'Magento_ReCaptchaCheckout/js/model/place-order-mixin': true + }, + 'Magento_ReCaptchaWebapiUi/js/webapiReCaptchaRegistry': { + 'Magento_ReCaptchaCheckout/js/webapiReCaptchaRegistry-mixin': true } } } }; + diff --git a/vendor/magento/module-re-captcha-checkout/view/frontend/web/js/model/place-order-mixin.js b/vendor/magento/module-re-captcha-checkout/view/frontend/web/js/model/place-order-mixin.js index 1cb64d19..c376b915 100644 --- a/vendor/magento/module-re-captcha-checkout/view/frontend/web/js/model/place-order-mixin.js +++ b/vendor/magento/module-re-captcha-checkout/view/frontend/web/js/model/place-order-mixin.js @@ -31,6 +31,14 @@ define([ //Trigger ReCaptcha validation recaptchaRegistry.triggers['recaptcha-checkout-place-order'](); + if ( + !recaptchaRegistry._isInvisibleType.hasOwnProperty('recaptcha-checkout-place-order') || + recaptchaRegistry._isInvisibleType['recaptcha-checkout-place-order'] === false + ) { + //remove listener so that place order action is only triggered by the 'Place Order' button + recaptchaRegistry.removeListener('recaptcha-checkout-place-order'); + } + return recaptchaDeferred; } diff --git a/vendor/magento/module-re-captcha-checkout/view/frontend/web/js/webapiReCaptchaRegistry-mixin.js b/vendor/magento/module-re-captcha-checkout/view/frontend/web/js/webapiReCaptchaRegistry-mixin.js new file mode 100644 index 00000000..b7780d54 --- /dev/null +++ b/vendor/magento/module-re-captcha-checkout/view/frontend/web/js/webapiReCaptchaRegistry-mixin.js @@ -0,0 +1,20 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([], function () { + 'use strict'; + + return function (originalFunction) { + /** + * {@inheritDoc} + */ + originalFunction.addListener = function (id , func) { + this._listeners[id] = func; + }; + + return originalFunction; + }; + +}); diff --git a/vendor/magento/module-re-captcha-webapi-ui/view/frontend/web/js/webapiReCaptcha.js b/vendor/magento/module-re-captcha-webapi-ui/view/frontend/web/js/webapiReCaptcha.js index c7c7c15d..312a68b5 100644 --- a/vendor/magento/module-re-captcha-webapi-ui/view/frontend/web/js/webapiReCaptcha.js +++ b/vendor/magento/module-re-captcha-webapi-ui/view/frontend/web/js/webapiReCaptcha.js @@ -43,14 +43,16 @@ define( var self = this, trigger; + trigger = function () { + self.reCaptchaCallback(grecaptcha.getResponse(widgetId)); + }; + registry._isInvisibleType[this.getReCaptchaId()] = false; + if (this.getIsInvisibleRecaptcha()) { trigger = function () { grecaptcha.execute(widgetId); }; - } else { - trigger = function () { - self.reCaptchaCallback(grecaptcha.getResponse(widgetId)); - }; + registry._isInvisibleType[this.getReCaptchaId()] = true; } if (this.autoTrigger) { diff --git a/vendor/magento/module-re-captcha-webapi-ui/view/frontend/web/js/webapiReCaptchaRegistry.js b/vendor/magento/module-re-captcha-webapi-ui/view/frontend/web/js/webapiReCaptchaRegistry.js index ba2f786d..3d504c14 100644 --- a/vendor/magento/module-re-captcha-webapi-ui/view/frontend/web/js/webapiReCaptchaRegistry.js +++ b/vendor/magento/module-re-captcha-webapi-ui/view/frontend/web/js/webapiReCaptchaRegistry.js @@ -26,6 +26,11 @@ define([], function () { */ _listeners: {}, + /** + * recaptchaId: bool map + */ + _isInvisibleType: {}, + /** * Add a listener to when the ReCaptcha finishes verification * @param {String} id - ReCaptchaId @@ -37,6 +42,15 @@ define([], function () { } else { this._listeners[id] = func; } + }, + + /** + * Remove a listener + * + * @param id + */ + removeListener: function (id) { + this._listeners[id] = undefined; } }; });