From f5d4faba79dff72440b8d34161111029bf3bfed6 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Wed, 28 Aug 2024 13:21:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Remove=20the=20empty=20Google=20?= =?UTF-8?q?Pay=20wrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using Google Pay in a separate payment gateway, there was a left-over div-tag with a fixed height beneath the PayPal payment button. This empty div was the initial wrapper for the payment button in the smart-button block, and is removed from DOM when a separate gateway is used. --- .../js/modules/Renderer/PaymentButton.js | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js index 59e511a43..8b5dcd3e9 100644 --- a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js +++ b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js @@ -113,6 +113,13 @@ export default class PaymentButton { */ #isInitialized = false; + /** + * Whether the one-time initialization of the payment gateway is complete. + * + * @type {boolean} + */ + #gatewayInitialized = false; + /** * The button's context. * @@ -715,26 +722,34 @@ export default class PaymentButton { } /** - * Makes the custom payment gateway visible by removing initial inline styles from the DOM. + * Makes the payment gateway visible by removing initial inline styles from the DOM. + * Also, removes the button-placeholder container from the smart button block. * * Only relevant on the checkout page, i.e., when `this.isSeparateGateway` is `true` */ showPaymentGateway() { + if ( this.#gatewayInitialized ) { + return; + } + this.#gatewayInitialized = true; + if ( ! this.isSeparateGateway || ! this.isEligible ) { return; } - const styleSelectors = `style[data-hide-gateway="${ this.methodId }"]`; + const styleSelector = `style[data-hide-gateway="${ this.methodId }"]`; + const wrapperSelector = `#${ this.wrappers.Default }`; - const styles = document.querySelectorAll( styleSelectors ); + document + .querySelectorAll( styleSelector ) + .forEach( ( el ) => el.remove() ); + + document + .querySelectorAll( wrapperSelector ) + .forEach( ( el ) => el.remove() ); - if ( ! styles.length ) { - return; - } this.log( 'Show gateway' ); - styles.forEach( ( el ) => el.remove() ); - // This code runs only once, during button initialization, and fixes the initial visibility. this.isVisible = this.isCurrentGateway; }