mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
✨ Apply new namespaced script loading
This commit is contained in:
parent
ac98924f52
commit
0d72641ded
4 changed files with 79 additions and 51 deletions
|
@ -1,32 +1,43 @@
|
|||
/* global paypal */
|
||||
|
||||
import ApplePayButton from './ApplepayButton';
|
||||
import ContextHandlerFactory from './Context/ContextHandlerFactory';
|
||||
|
||||
class ApplePayManagerBlockEditor {
|
||||
constructor( buttonConfig, ppcpConfig ) {
|
||||
constructor( namespace, buttonConfig, ppcpConfig ) {
|
||||
this.namespace = namespace;
|
||||
this.buttonConfig = buttonConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
this.applePayConfig = null;
|
||||
|
||||
/*
|
||||
* 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() );
|
||||
}
|
||||
|
||||
init() {
|
||||
( async () => {
|
||||
await this.config();
|
||||
} )();
|
||||
}
|
||||
|
||||
async config() {
|
||||
async init() {
|
||||
try {
|
||||
this.applePayConfig = await ppcpBlocksEditorPaypalApplepay.Applepay().config();
|
||||
this.applePayConfig = await window[ this.namespace ]
|
||||
.Applepay()
|
||||
.config();
|
||||
|
||||
const button = new ApplePayButton(
|
||||
this.contextHandler = ContextHandlerFactory.create(
|
||||
this.ppcpConfig.context,
|
||||
this.buttonConfig,
|
||||
this.ppcpConfig,
|
||||
null
|
||||
);
|
||||
|
||||
const button = ApplePayButton.createButton(
|
||||
this.ppcpConfig.context,
|
||||
null,
|
||||
this.buttonConfig,
|
||||
this.ppcpConfig
|
||||
this.ppcpConfig,
|
||||
this.contextHandler
|
||||
);
|
||||
|
||||
button.init( this.applePayConfig );
|
||||
button.configure( this.applePayConfig );
|
||||
button.init();
|
||||
} catch ( error ) {
|
||||
console.error( 'Failed to initialize Apple Pay:', error );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue