From b7d18f105eb855a574d52d9000f1b484515565b4 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 28 Aug 2024 12:56:07 +0200
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20incorrect=20display=20of?=
=?UTF-8?q?=20initial=20button?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Logic to hide the payment button when used as a smart-button (not as a separate gateway) had a bug, if the PayPal method was not the first payment gateway.
The new logic ensures that the payment button’s visibility is correct, regardless on whether it’s a separate payment gateway or included in the PayPal smart-button block.
---
.../js/modules/Renderer/PaymentButton.js | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js
index 11fe31f79..59e511a43 100644
--- a/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js
+++ b/modules/ppcp-button/resources/js/modules/Renderer/PaymentButton.js
@@ -461,16 +461,19 @@ export default class PaymentButton {
* @return {boolean} True means that this payment method is selected as current gateway.
*/
get isCurrentGateway() {
- if ( ! this.isSeparateGateway ) {
- return false;
- }
-
/*
* We need to rely on `getCurrentPaymentMethod()` here, as the `CheckoutBootstrap.js`
* module fires the "ButtonEvents.RENDER" event before any PaymentButton instances are
* created. I.e. we cannot observe the initial gateway selection event.
*/
- return this.methodId === getCurrentPaymentMethod();
+ const currentMethod = getCurrentPaymentMethod();
+
+ if ( this.isSeparateGateway ) {
+ return this.methodId === currentMethod;
+ }
+
+ // Button is rendered inside the Smart Buttons block.
+ return PaymentMethods.PAYPAL === currentMethod;
}
/**
@@ -703,7 +706,7 @@ export default class PaymentButton {
this.applyWrapperStyles();
- if ( this.isEligible && this.isPresent && this.isVisible ) {
+ if ( this.isEligible && this.isCurrentGateway && this.isVisible ) {
if ( ! this.isButtonAttached ) {
this.log( 'refresh.addButton' );
this.addButton();