🚧 Adjust button-manager to new workflow

This commit is contained in:
Philipp Stracker 2024-10-07 12:27:20 +02:00
parent d5e406a563
commit c2d5c8f3c5
No known key found for this signature in database

View file

@ -11,7 +11,7 @@ class ApplePayManager {
this.ApplePayConfig = null;
this.buttons = [];
buttonModuleWatcher.watchContextBootstrap( ( bootstrap ) => {
buttonModuleWatcher.watchContextBootstrap( async ( bootstrap ) => {
this.contextHandler = ContextHandlerFactory.create(
bootstrap.context,
buttonConfig,
@ -29,19 +29,26 @@ class ApplePayManager {
this.buttons.push( button );
if ( this.ApplePayConfig ) {
button.init( this.ApplePayConfig );
}
// Ensure ApplePayConfig is loaded before proceeding.
await this.init();
button.configure( this.ApplePayConfig );
button.init();
} );
}
init() {
( async () => {
await this.config();
for ( const button of this.buttons ) {
button.init( this.ApplePayConfig );
async init() {
try {
if ( ! this.ApplePayConfig ) {
this.ApplePayConfig = await paypal.Applepay().config();
if ( ! this.ApplePayConfig ) {
console.error( 'No ApplePayConfig received during init' );
}
}
} )();
} catch ( error ) {
console.error( 'Error during initialization:', error );
}
}
reinit() {
@ -49,14 +56,6 @@ class ApplePayManager {
button.reinit();
}
}
/**
* Gets Apple Pay configuration of the PayPal merchant.
*/
async config() {
this.ApplePayConfig = await paypal.Applepay().config();
return this.ApplePayConfig;
}
}
export default ApplePayManager;