woocommerce-paypal-payments/modules/ppcp-applepay/resources/js/ApplepayManagerBlockEditor.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

import ApplePayButton from './ApplepayButton';
import ContextHandlerFactory from './Context/ContextHandlerFactory';
class ApplePayManagerBlockEditor {
constructor( namespace, buttonConfig, ppcpConfig ) {
this.namespace = namespace;
2024-07-12 12:58:34 +02:00
this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig;
/*
* On the front-end, the init method is called when a new button context was detected
* via `buttonModuleWatcher`. In the block editor, we do not need to wait for the
* context, but can initialize the button in the next event loop.
*/
setTimeout( () => this.init() );
2024-07-12 12:58:34 +02:00
}
async init() {
2024-07-12 12:58:34 +02:00
try {
this.applePayConfig = await window[ this.namespace ]
.Applepay()
.config();
this.contextHandler = ContextHandlerFactory.create(
this.ppcpConfig.context,
this.buttonConfig,
this.ppcpConfig,
null
);
2024-07-12 12:58:34 +02:00
const button = ApplePayButton.createButton(
2024-07-12 12:58:34 +02:00
this.ppcpConfig.context,
null,
this.buttonConfig,
this.ppcpConfig,
this.contextHandler
2024-07-12 12:58:34 +02:00
);
button.configure( this.applePayConfig );
button.init();
2024-07-12 12:58:34 +02:00
} catch ( error ) {
console.error( 'Failed to initialize Apple Pay:', error );
}
}
2024-04-23 15:00:05 +02:00
}
export default ApplePayManagerBlockEditor;