🐛 Fix incorrect display of initial button

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.
This commit is contained in:
Philipp Stracker 2024-08-28 12:56:07 +02:00
parent 8c1a6f72dc
commit b7d18f105e
No known key found for this signature in database

View file

@ -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();