mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
♻️ Slightly improve code readability
This commit is contained in:
parent
745c1cc88c
commit
3cfbd1002f
1 changed files with 12 additions and 15 deletions
|
@ -133,10 +133,7 @@ class Renderer {
|
||||||
this.onSmartButtonClick( data, actions );
|
this.onSmartButtonClick( data, actions );
|
||||||
}
|
}
|
||||||
|
|
||||||
venmoButtonClicked = false;
|
venmoButtonClicked = data.fundingSource === 'venmo';
|
||||||
if ( data.fundingSource === 'venmo' ) {
|
|
||||||
venmoButtonClicked = true;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onInit: ( data, actions ) => {
|
onInit: ( data, actions ) => {
|
||||||
if ( this.onSmartButtonsInit ) {
|
if ( this.onSmartButtonsInit ) {
|
||||||
|
@ -219,10 +216,7 @@ class Renderer {
|
||||||
|
|
||||||
this.renderedSources.add( wrapper + ( fundingSource ?? '' ) );
|
this.renderedSources.add( wrapper + ( fundingSource ?? '' ) );
|
||||||
|
|
||||||
if (
|
if ( window.paypal?.Buttons ) {
|
||||||
typeof paypal !== 'undefined' &&
|
|
||||||
typeof paypal.Buttons !== 'undefined'
|
|
||||||
) {
|
|
||||||
widgetBuilder.registerButtons(
|
widgetBuilder.registerButtons(
|
||||||
[ wrapper, fundingSource ],
|
[ wrapper, fundingSource ],
|
||||||
buttonsOptions()
|
buttonsOptions()
|
||||||
|
@ -239,6 +233,7 @@ class Renderer {
|
||||||
const needShipping =
|
const needShipping =
|
||||||
this.defaultSettings.needShipping ||
|
this.defaultSettings.needShipping ||
|
||||||
this.defaultSettings.context === 'product';
|
this.defaultSettings.context === 'product';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
this.defaultSettings.should_handle_shipping_in_paypal &&
|
this.defaultSettings.should_handle_shipping_in_paypal &&
|
||||||
needShipping
|
needShipping
|
||||||
|
@ -261,6 +256,7 @@ class Renderer {
|
||||||
this.onButtonsInitListeners[ wrapper ] = reset
|
this.onButtonsInitListeners[ wrapper ] = reset
|
||||||
? []
|
? []
|
||||||
: this.onButtonsInitListeners[ wrapper ] || [];
|
: this.onButtonsInitListeners[ wrapper ] || [];
|
||||||
|
|
||||||
this.onButtonsInitListeners[ wrapper ].push( handler );
|
this.onButtonsInitListeners[ wrapper ].push( handler );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,12 +268,11 @@ class Renderer {
|
||||||
|
|
||||||
if ( this.onButtonsInitListeners[ wrapper ] ) {
|
if ( this.onButtonsInitListeners[ wrapper ] ) {
|
||||||
for ( const handler of this.onButtonsInitListeners[ wrapper ] ) {
|
for ( const handler of this.onButtonsInitListeners[ wrapper ] ) {
|
||||||
if ( typeof handler === 'function' ) {
|
if ( typeof handler !== 'function' ) {
|
||||||
handler( {
|
continue;
|
||||||
wrapper,
|
|
||||||
...this.buttonsOptions[ wrapper ],
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handler( { wrapper, ...this.buttonsOptions[ wrapper ] } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,10 +281,11 @@ class Renderer {
|
||||||
if ( ! this.buttonsOptions[ wrapper ] ) {
|
if ( ! this.buttonsOptions[ wrapper ] ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.buttonsOptions[ wrapper ].actions.disable();
|
this.buttonsOptions[ wrapper ].actions.disable();
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
console.log( 'Failed to disable buttons: ' + err );
|
console.warn( 'Failed to disable buttons: ' + err );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,10 +293,11 @@ class Renderer {
|
||||||
if ( ! this.buttonsOptions[ wrapper ] ) {
|
if ( ! this.buttonsOptions[ wrapper ] ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.buttonsOptions[ wrapper ].actions.enable();
|
this.buttonsOptions[ wrapper ].actions.enable();
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
console.log( 'Failed to enable buttons: ' + err );
|
console.warn( 'Failed to enable buttons: ' + err );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue