Fix JS linting

This commit is contained in:
Daniel Dudzic 2024-07-15 11:21:56 +02:00
parent 525fee7edd
commit 8b43a06f9f
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
3 changed files with 638 additions and 545 deletions

View file

@ -1,88 +1,85 @@
import buttonModuleWatcher from "../../../ppcp-button/resources/js/modules/ButtonModuleWatcher";
import GooglepayButton from "./GooglepayButton";
import ContextHandlerFactory from "./Context/ContextHandlerFactory";
import buttonModuleWatcher from '../../../ppcp-button/resources/js/modules/ButtonModuleWatcher';
import GooglepayButton from './GooglepayButton';
import ContextHandlerFactory from './Context/ContextHandlerFactory';
class GooglepayManager {
constructor( buttonConfig, ppcpConfig ) {
this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig;
this.googlePayConfig = null;
this.transactionInfo = null;
this.contextHandler = null;
constructor(buttonConfig, ppcpConfig) {
this.buttons = [];
this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig;
this.googlePayConfig = null;
this.transactionInfo = null;
this.contextHandler = null;
buttonModuleWatcher.watchContextBootstrap( async ( bootstrap ) => {
if ( ! this.contextHandler ) {
this.contextHandler = ContextHandlerFactory.create(
bootstrap.context,
buttonConfig,
ppcpConfig,
bootstrap.handler
);
}
this.buttons = [];
const button = new GooglepayButton(
bootstrap.context,
bootstrap.handler,
buttonConfig,
ppcpConfig,
this.contextHandler
);
buttonModuleWatcher.watchContextBootstrap(async (bootstrap) => {
if (!this.contextHandler) {
this.contextHandler = ContextHandlerFactory.create(
bootstrap.context,
buttonConfig,
ppcpConfig,
bootstrap.handler
);
}
this.buttons.push( button );
const button = new GooglepayButton(
bootstrap.context,
bootstrap.handler,
buttonConfig,
ppcpConfig,
this.contextHandler
);
// Initialize button only if googlePayConfig and transactionInfo are already fetched.
if ( this.googlePayConfig && this.transactionInfo ) {
button.init( this.googlePayConfig, this.transactionInfo );
} else {
await this.init();
if ( this.googlePayConfig && this.transactionInfo ) {
button.init( this.googlePayConfig, this.transactionInfo );
}
}
} );
}
this.buttons.push(button);
async init() {
try {
if ( ! this.googlePayConfig ) {
// Gets GooglePay configuration of the PayPal merchant.
this.googlePayConfig = await paypal.Googlepay().config();
}
// Initialize button only if googlePayConfig and transactionInfo are already fetched.
if (this.googlePayConfig && this.transactionInfo) {
button.init(this.googlePayConfig, this.transactionInfo);
} else {
await this.init();
if (this.googlePayConfig && this.transactionInfo) {
button.init(this.googlePayConfig, this.transactionInfo);
}
}
});
}
if ( ! this.transactionInfo ) {
this.transactionInfo = await this.fetchTransactionInfo();
}
async init() {
try {
if (!this.googlePayConfig) {
// Gets GooglePay configuration of the PayPal merchant.
this.googlePayConfig = await paypal.Googlepay().config();
}
for ( const button of this.buttons ) {
button.init( this.googlePayConfig, this.transactionInfo );
}
} catch ( error ) {
console.error( 'Error during initialization:', error );
}
}
if (!this.transactionInfo) {
this.transactionInfo = await this.fetchTransactionInfo();
}
for (const button of this.buttons) {
button.init(this.googlePayConfig, this.transactionInfo);
}
} catch(error) {
console.error('Error during initialization:', error);
}
}
async fetchTransactionInfo() {
try {
if (!this.contextHandler) {
throw new Error('ContextHandler is not initialized');
}
return await this.contextHandler.transactionInfo();
} catch(error) {
console.error('Error fetching transaction info:', error);
throw error;
}
}
reinit() {
for (const button of this.buttons) {
button.reinit();
}
}
async fetchTransactionInfo() {
try {
if ( ! this.contextHandler ) {
throw new Error( 'ContextHandler is not initialized' );
}
return await this.contextHandler.transactionInfo();
} catch ( error ) {
console.error( 'Error fetching transaction info:', error );
throw error;
}
}
reinit() {
for ( const button of this.buttons ) {
button.reinit();
}
}
}
export default GooglepayManager;