mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +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',
|
BlockCart: 'cart-block',
|
||||||
BlockCheckout: 'checkout-block',
|
BlockCheckout: 'checkout-block',
|
||||||
Preview: 'preview',
|
Preview: 'preview',
|
||||||
|
|
||||||
// Block editor contexts.
|
// Block editor contexts.
|
||||||
Blocks: [ 'cart-block', 'checkout-block' ],
|
Blocks: [ 'cart-block', 'checkout-block' ],
|
||||||
|
|
||||||
// Custom gateway contexts.
|
// Custom gateway contexts.
|
||||||
Gateways: [ 'checkout', 'pay-now' ],
|
Gateways: [ 'checkout', 'pay-now' ],
|
||||||
};
|
};
|
||||||
|
@ -89,6 +91,8 @@ class ApplePayButton {
|
||||||
initialPaymentRequest = null;
|
initialPaymentRequest = null;
|
||||||
|
|
||||||
constructor( context, externalHandler, buttonConfig, ppcpConfig ) {
|
constructor( context, externalHandler, buttonConfig, ppcpConfig ) {
|
||||||
|
this._initDebug( !! buttonConfig?.is_debug );
|
||||||
|
|
||||||
apmButtonsInit( ppcpConfig );
|
apmButtonsInit( ppcpConfig );
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -103,25 +107,34 @@ class ApplePayButton {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.refreshContextData();
|
this.refreshContextData();
|
||||||
|
}
|
||||||
|
|
||||||
this.log = () => {};
|
/**
|
||||||
|
* NOOP log function to avoid errors when debugging is disabled.
|
||||||
|
*/
|
||||||
|
log() {}
|
||||||
|
|
||||||
// Debug helpers
|
/**
|
||||||
if ( this.buttonConfig.is_debug ) {
|
* Enables debugging tools, when the button's is_debug flag is set.
|
||||||
document.ppcpApplepayButtons = document.ppcpApplepayButtons || {};
|
*
|
||||||
document.ppcpApplepayButtons[ this.context ] = this;
|
* @param {boolean} enableDebugging If debugging features should be enabled for this instance.
|
||||||
|
* @private
|
||||||
this.log = function () {
|
*/
|
||||||
console.log(
|
_initDebug( enableDebugging ) {
|
||||||
`[ApplePayButton | ${ this.context }]`,
|
if ( ! enableDebugging || this.#isInitialized ) {
|
||||||
...arguments
|
return;
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
jQuery( document ).on( 'ppcp-applepay-debug', () => {
|
|
||||||
this.log( this );
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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