diff --git a/vendor/magento/module-re-captcha-gift-card/view/frontend/layout/checkout_cart_index.xml b/vendor/magento/module-re-captcha-gift-card/view/frontend/layout/checkout_cart_index.xml index 8a7e43e..ce93fc6 100644 --- a/vendor/magento/module-re-captcha-gift-card/view/frontend/layout/checkout_cart_index.xml +++ b/vendor/magento/module-re-captcha-gift-card/view/frontend/layout/checkout_cart_index.xml @@ -19,7 +19,7 @@ - Magento_ReCaptchaFrontendUi/js/reCaptcha + Magento_ReCaptchaGiftCard/js/checkoutReCaptcha @@ -27,4 +27,4 @@ - \ No newline at end of file + diff --git a/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/action/get-gift-card-information-mixin.js b/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/action/get-gift-card-information-mixin.js index c16606a..4fca934 100644 --- a/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/action/get-gift-card-information-mixin.js +++ b/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/action/get-gift-card-information-mixin.js @@ -1,9 +1,21 @@ /** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. + * ADOBE CONFIDENTIAL + * + * Copyright 2021 Adobe + * All Rights Reserved. + * + * NOTICE: All information contained herein is, and remains + * the property of Adobe and its suppliers, if any. The intellectual + * and technical concepts contained herein are proprietary to Adobe + * and its suppliers and are protected by all applicable intellectual + * property laws, including trade secret and copyright laws. + * Dissemination of this information or reproduction of this material + * is strictly forbidden unless prior written permission is obtained + * from Adobe. */ - /* eslint-disable max-nested-callbacks */ + +/* eslint-disable max-nested-callbacks */ define([ 'jquery', @@ -29,8 +41,8 @@ define([ errorProcessor, wrapper, recaptchaRegistry - ) { - 'use strict'; +) { + 'use strict'; // eslint-disable-line var extender = { @@ -40,22 +52,7 @@ define([ */ check: function (originFn, giftCardCode) { var recaptchaDeferred, - self = this, - serviceUrl, headers = {}; - - if (!customer.isLoggedIn()) { - serviceUrl = urlBuilder.createUrl('/carts/guest-carts/:cartId/checkGiftCard/:giftCardCode', { - cartId: quote.getQuoteId(), - giftCardCode: giftCardCode - }); - } else { - serviceUrl = urlBuilder.createUrl('/carts/mine/checkGiftCard/:giftCardCode', { - giftCardCode: giftCardCode - }); - } - messageList.clear(); - - this.isLoading(true); + headers = {}; if (recaptchaRegistry.triggers.hasOwnProperty('recaptcha-checkout-gift-apply')) { //ReCaptcha is present for checkout @@ -64,19 +61,10 @@ define([ headers = { 'X-ReCaptcha': token }; - - storage.get( - serviceUrl, true, 'application/json', headers - ).done(function (response) { - giftCardAccount.isChecked(true); - giftCardAccount.code(giftCardCode); - giftCardAccount.amount(response); - giftCardAccount.isValid(true); - }).fail(function (response) { - giftCardAccount.isValid(false); - errorProcessor.process(response, messageList); - }).always(function () { - self.isLoading(false); + originFn(giftCardCode, true, 'application/json', headers).done(function () { + recaptchaDeferred.resolve.apply(recaptchaDeferred, arguments); + }).fail(function () { + recaptchaDeferred.reject.apply(recaptchaDeferred, arguments); }); }); //Trigger ReCaptcha validation diff --git a/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/action/set-gift-card-information-mixin.js b/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/action/set-gift-card-information-mixin.js index 25561f8..d788f66 100644 --- a/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/action/set-gift-card-information-mixin.js +++ b/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/action/set-gift-card-information-mixin.js @@ -1,9 +1,21 @@ /** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. + * ADOBE CONFIDENTIAL + * + * Copyright 2021 Adobe + * All Rights Reserved. + * + * NOTICE: All information contained herein is, and remains + * the property of Adobe and its suppliers, if any. The intellectual + * and technical concepts contained herein are proprietary to Adobe + * and its suppliers and are protected by all applicable intellectual + * property laws, including trade secret and copyright laws. + * Dissemination of this information or reproduction of this material + * is strictly forbidden unless prior written permission is obtained + * from Adobe. */ - /* eslint-disable max-nested-callbacks */ + +/* eslint-disable max-nested-callbacks */ define([ 'jquery', @@ -32,68 +44,19 @@ define([ wrapper, recaptchaRegistry ) { - 'use strict'; + 'use strict'; // eslint-disable-line return function (setGiftCardAction) { - return wrapper.wrap(setGiftCardAction, function (originalAction, giftCardCode) { + const mixin = wrapper.wrap(setGiftCardAction, function (originalAction, giftCardCode) { var recaptchaDeferred, - serviceUrl, - payload, - headers = {}, - message = $.mage.__('Gift Card %1 was added.').replace('%1', giftCardCode); - - /** - * Checkout for guest and registered customer. - */ - if (!customer.isLoggedIn()) { - serviceUrl = urlBuilder.createUrl('/carts/guest-carts/:cartId/giftCards', { - cartId: quote.getQuoteId() - }); - payload = { - cartId: quote.getQuoteId(), - giftCardAccountData: { - 'gift_cards': giftCardCode - } - }; - } else { - serviceUrl = urlBuilder.createUrl('/carts/mine/giftCards', {}); - payload = { - cartId: quote.getQuoteId(), - giftCardAccountData: { - 'gift_cards': giftCardCode - } - }; - } + headers = {}; if (recaptchaRegistry.triggers.hasOwnProperty('recaptcha-checkout-gift-apply')) { //ReCaptcha is present for checkout recaptchaDeferred = $.Deferred(); recaptchaRegistry.addListener('recaptcha-checkout-gift-apply', function (token) { headers['X-ReCaptcha'] = token; - storage.post( - serviceUrl, JSON.stringify(payload), true, 'application/json', headers - ).done(function (response) { - /** - * Callback for getPaymentInformationAction. - */ - var onGetPaymentInformationAction = function () { - totals.isLoading(false); - }, - deferred = $.Deferred(); - - if (response) { - totals.isLoading(true); - $.when(getPaymentInformationAction(deferred)).done(onGetPaymentInformationAction); - messageList.addSuccessMessage({ - 'message': message - }); - } - }).fail(function (response) { - totals.isLoading(false); - errorProcessor.process(response, messageList); - }).always(function () { - fullScreenLoader.stopLoader(); - }); + originalAction(giftCardCode, true, 'application/json', headers); }); //Trigger ReCaptcha validation recaptchaRegistry.triggers['recaptcha-checkout-gift-apply'](); @@ -111,5 +74,10 @@ define([ //No ReCaptcha, just sending the request return originalAction(giftCardCode); }); + + mixin.registerCallback = function (callback, type) { + setGiftCardAction.registerCallback(callback, type); + }; + return mixin; }; }); diff --git a/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/checkoutReCaptcha.js b/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/checkoutReCaptcha.js new file mode 100644 index 0000000..a944a05 --- /dev/null +++ b/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/checkoutReCaptcha.js @@ -0,0 +1,60 @@ +/** + * ADOBE CONFIDENTIAL + * + * Copyright 2023 Adobe + * All Rights Reserved. + * + * NOTICE: All information contained herein is, and remains + * the property of Adobe and its suppliers, if any. The intellectual + * and technical concepts contained herein are proprietary to Adobe + * and its suppliers and are protected by all applicable intellectual + * property laws, including trade secret and copyright laws. + * Dissemination of this information or reproduction of this material + * is strictly forbidden unless prior written permission is obtained + * from Adobe. + */ + +define( + [ + 'Magento_ReCaptchaFrontendUi/js/reCaptcha', + 'Magento_GiftCardAccount/js/gift-card' + ], + function (Component) { + 'use strict'; // eslint-disable-line + + return Component.extend({ + /** + * Auto-trigger validation so that ReCaptcha is ready for Quick Checkout + * + * @param {Object} parentForm + * @param {String} widgetId + */ + initParentForm: function (parentForm, widgetId) { + parentForm.find('.action.check').click(function (event) { + if (this.getIsInvisibleRecaptcha()) { + window.grecaptcha.execute(widgetId); + event.preventDefault(event); + event.stopImmediatePropagation(); + } + }.bind(this)); + parentForm.on('giftcardbalancestatus.complete', function () { + window.grecaptcha.reset(widgetId); + }); + if (this.getIsInvisibleRecaptcha()) { + window.grecaptcha.execute(widgetId); + } + }, + + /** + * Recording the token + * + * @param {String} token + */ + reCaptchaCallback: function (token) { + if (this.getIsInvisibleRecaptcha() && this.tokenField) { + this.tokenField.value = token; + } + } + }); + } +); diff --git a/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/gift-card-recaptcha.js b/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/gift-card-recaptcha.js index 53bd483..6382767 100644 --- a/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/gift-card-recaptcha.js +++ b/vendor/magento/module-re-captcha-gift-card/view/frontend/web/js/gift-card-recaptcha.js @@ -1,8 +1,20 @@ /** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. + * ADOBE CONFIDENTIAL + * + * Copyright 2021 Adobe + * All Rights Reserved. + * + * NOTICE: All information contained herein is, and remains + * the property of Adobe and its suppliers, if any. The intellectual + * and technical concepts contained herein are proprietary to Adobe + * and its suppliers and are protected by all applicable intellectual + * property laws, including trade secret and copyright laws. + * Dissemination of this information or reproduction of this material + * is strictly forbidden unless prior written permission is obtained + * from Adobe. */ + /* eslint-disable no-unused-vars */ define( [ @@ -11,9 +23,11 @@ define( 'jquery', 'Magento_GiftCardAccount/js/action/set-gift-card-information', 'Magento_Checkout/js/model/quote', - 'ko' - ], function (Component, recaptchaRegistry, $, setGiftCardAction, quote, ko) { - 'use strict'; + 'ko', + 'Magento_GiftCardAccount/js/action/get-gift-card-information' + ], + function (Component, recaptchaRegistry, $, setGiftCardAction, quote, ko, getGiftCardInformation) { + 'use strict'; // eslint-disable-line var totals = quote.getTotals(), GiftCode = ko.observable(null), @@ -48,6 +62,12 @@ define( $('#' + captchaId).hide(); } } + getGiftCardInformation.registerCallback(function () { + window.grecaptcha.reset(widgetId); + }); + setGiftCardAction.registerCallback(function () { + window.grecaptcha.reset(widgetId); + }); }, /** @@ -61,4 +81,5 @@ define( } } }); - }); + } +);