From 7f3636348b0aa688474f013b959054c8c0bb9bc7 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 7 Aug 2024 23:07:04 +0200
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20button=20insertion=20logic?=
=?UTF-8?q?=20in=20block=20checkout?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The Google Pay button was inserted into the wrong DOM wrapper
---
.../js/modules/Renderer/PaymentButton.js | 16 ++++++++--------
.../resources/js/GooglepayButton.js | 2 +-
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js
index ae2e5f668..071fe010d 100644
--- a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js
+++ b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js
@@ -659,8 +659,7 @@ export default class PaymentButton {
const wrapper = this.wrapperElement;
if ( this.#button ) {
- this.log( 'addButton.removePrevious', this.#button );
- wrapper.removeChild( this.#button );
+ this.removeButton();
}
this.#button = button;
@@ -671,17 +670,18 @@ export default class PaymentButton {
* Removes the payment button from the DOM.
*/
removeButton() {
- if ( ! this.isPresent ) {
+ if ( ! this.isPresent || ! this.#button ) {
return;
}
this.log( 'removeButton' );
- if ( this.#button ) {
- const wrapper = this.wrapperElement;
- wrapper.removeChild( this.#button );
-
- this.#button = null;
+ try {
+ this.wrapperElement.removeChild( this.#button );
+ } catch ( Exception ) {
+ // Ignore this.
}
+
+ this.#button = null;
}
}
diff --git a/modules/ppcp-googlepay/resources/js/GooglepayButton.js b/modules/ppcp-googlepay/resources/js/GooglepayButton.js
index 2944ea12b..479f855db 100644
--- a/modules/ppcp-googlepay/resources/js/GooglepayButton.js
+++ b/modules/ppcp-googlepay/resources/js/GooglepayButton.js
@@ -70,7 +70,7 @@ class GooglepayButton extends PaymentButton {
buttonConfig.button.wrapper,
buttonConfig.button.mini_cart_wrapper,
ppcpConfig.button.wrapper,
- 'express-payment-method-ppcp-googlepay',
+ 'ppc-button-googlepay-container',
'ppc-button-ppcp-googlepay'
);
}