mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
🐛 Fix bug with undefined log() method
This commit is contained in:
parent
a14276bf52
commit
cbf9bff808
1 changed files with 29 additions and 16 deletions
|
@ -43,8 +43,10 @@ const CONTEXT = {
|
|||
BlockCart: 'cart-block',
|
||||
BlockCheckout: 'checkout-block',
|
||||
Preview: 'preview',
|
||||
|
||||
// Block editor contexts.
|
||||
Blocks: [ 'cart-block', 'checkout-block' ],
|
||||
|
||||
// Custom gateway contexts.
|
||||
Gateways: [ 'checkout', 'pay-now' ],
|
||||
};
|
||||
|
@ -89,6 +91,8 @@ class ApplePayButton {
|
|||
initialPaymentRequest = null;
|
||||
|
||||
constructor( context, externalHandler, buttonConfig, ppcpConfig ) {
|
||||
this._initDebug( !! buttonConfig?.is_debug );
|
||||
|
||||
apmButtonsInit( ppcpConfig );
|
||||
|
||||
this.context = context;
|
||||
|
@ -103,25 +107,34 @@ class ApplePayButton {
|
|||
);
|
||||
|
||||
this.refreshContextData();
|
||||
}
|
||||
|
||||
this.log = () => {};
|
||||
/**
|
||||
* NOOP log function to avoid errors when debugging is disabled.
|
||||
*/
|
||||
log() {}
|
||||
|
||||
// Debug helpers
|
||||
if ( this.buttonConfig.is_debug ) {
|
||||
document.ppcpApplepayButtons = document.ppcpApplepayButtons || {};
|
||||
document.ppcpApplepayButtons[ this.context ] = this;
|
||||
|
||||
this.log = function () {
|
||||
console.log(
|
||||
`[ApplePayButton | ${ this.context }]`,
|
||||
...arguments
|
||||
);
|
||||
};
|
||||
|
||||
jQuery( document ).on( 'ppcp-applepay-debug', () => {
|
||||
this.log( this );
|
||||
} );
|
||||
/**
|
||||
* Enables debugging tools, when the button's is_debug flag is set.
|
||||
*
|
||||
* @param {boolean} enableDebugging If debugging features should be enabled for this instance.
|
||||
* @private
|
||||
*/
|
||||
_initDebug( enableDebugging ) {
|
||||
if ( ! enableDebugging || this.#isInitialized ) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.ppcpApplepayButtons = document.ppcpApplepayButtons || {};
|
||||
document.ppcpApplepayButtons[ this.context ] = this;
|
||||
|
||||
this.log = ( ...args ) => {
|
||||
console.log( `[ApplePayButton | ${ this.context }]`, ...args );
|
||||
};
|
||||
|
||||
jQuery( document ).on( 'ppcp-applepay-debug', () => {
|
||||
this.log( this );
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue