mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
♻️ Make internal attributes private
This commit is contained in:
parent
0d72641ded
commit
35473df661
2 changed files with 41 additions and 30 deletions
|
@ -3,50 +3,55 @@ import ApplePayButton from './ApplepayButton';
|
||||||
import ContextHandlerFactory from './Context/ContextHandlerFactory';
|
import ContextHandlerFactory from './Context/ContextHandlerFactory';
|
||||||
|
|
||||||
class ApplePayManager {
|
class ApplePayManager {
|
||||||
|
#namespace = '';
|
||||||
|
#buttonConfig = null;
|
||||||
|
#ppcpConfig = null;
|
||||||
|
#applePayConfig = null;
|
||||||
|
#contextHandler = null;
|
||||||
|
#buttons = [];
|
||||||
|
|
||||||
constructor( namespace, buttonConfig, ppcpConfig ) {
|
constructor( namespace, buttonConfig, ppcpConfig ) {
|
||||||
this.namespace = namespace;
|
this.#namespace = namespace;
|
||||||
this.buttonConfig = buttonConfig;
|
this.#buttonConfig = buttonConfig;
|
||||||
this.ppcpConfig = ppcpConfig;
|
this.#ppcpConfig = ppcpConfig;
|
||||||
this.ApplePayConfig = null;
|
|
||||||
this.buttons = [];
|
|
||||||
|
|
||||||
this.onContextBootstrap = this.onContextBootstrap.bind( this );
|
this.onContextBootstrap = this.onContextBootstrap.bind( this );
|
||||||
buttonModuleWatcher.watchContextBootstrap( this.onContextBootstrap );
|
buttonModuleWatcher.watchContextBootstrap( this.onContextBootstrap );
|
||||||
}
|
}
|
||||||
|
|
||||||
async onContextBootstrap( bootstrap ) {
|
async onContextBootstrap( bootstrap ) {
|
||||||
this.contextHandler = ContextHandlerFactory.create(
|
this.#contextHandler = ContextHandlerFactory.create(
|
||||||
bootstrap.context,
|
bootstrap.context,
|
||||||
this.buttonConfig,
|
this.#buttonConfig,
|
||||||
this.ppcpConfig,
|
this.#ppcpConfig,
|
||||||
bootstrap.handler
|
bootstrap.handler
|
||||||
);
|
);
|
||||||
|
|
||||||
const button = ApplePayButton.createButton(
|
const button = ApplePayButton.createButton(
|
||||||
bootstrap.context,
|
bootstrap.context,
|
||||||
bootstrap.handler,
|
bootstrap.handler,
|
||||||
this.buttonConfig,
|
this.#buttonConfig,
|
||||||
this.ppcpConfig,
|
this.#ppcpConfig,
|
||||||
this.contextHandler
|
this.#contextHandler
|
||||||
);
|
);
|
||||||
|
|
||||||
this.buttons.push( button );
|
this.#buttons.push( button );
|
||||||
|
|
||||||
// Ensure ApplePayConfig is loaded before proceeding.
|
// Ensure ApplePayConfig is loaded before proceeding.
|
||||||
await this.init();
|
await this.init();
|
||||||
|
|
||||||
button.configure( this.applePayConfig );
|
button.configure( this.#applePayConfig );
|
||||||
button.init();
|
button.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
try {
|
try {
|
||||||
if ( ! this.applePayConfig ) {
|
if ( ! this.#applePayConfig ) {
|
||||||
this.applePayConfig = await window[ this.namespace ]
|
this.#applePayConfig = await window[ this.#namespace ]
|
||||||
.Applepay()
|
.Applepay()
|
||||||
.config();
|
.config();
|
||||||
|
|
||||||
if ( ! this.applePayConfig ) {
|
if ( ! this.#applePayConfig ) {
|
||||||
console.error( 'No ApplePayConfig received during init' );
|
console.error( 'No ApplePayConfig received during init' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +61,7 @@ class ApplePayManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
reinit() {
|
reinit() {
|
||||||
for ( const button of this.buttons ) {
|
for ( const button of this.#buttons ) {
|
||||||
button.reinit();
|
button.reinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,16 @@ import ApplePayButton from './ApplepayButton';
|
||||||
import ContextHandlerFactory from './Context/ContextHandlerFactory';
|
import ContextHandlerFactory from './Context/ContextHandlerFactory';
|
||||||
|
|
||||||
class ApplePayManagerBlockEditor {
|
class ApplePayManagerBlockEditor {
|
||||||
|
#namespace = '';
|
||||||
|
#buttonConfig = null;
|
||||||
|
#ppcpConfig = null;
|
||||||
|
#applePayConfig = null;
|
||||||
|
#contextHandler = null;
|
||||||
|
|
||||||
constructor( namespace, buttonConfig, ppcpConfig ) {
|
constructor( namespace, buttonConfig, ppcpConfig ) {
|
||||||
this.namespace = namespace;
|
this.#namespace = namespace;
|
||||||
this.buttonConfig = buttonConfig;
|
this.#buttonConfig = buttonConfig;
|
||||||
this.ppcpConfig = ppcpConfig;
|
this.#ppcpConfig = ppcpConfig;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* On the front-end, the init method is called when a new button context was detected
|
* On the front-end, the init method is called when a new button context was detected
|
||||||
|
@ -17,26 +23,26 @@ class ApplePayManagerBlockEditor {
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
try {
|
try {
|
||||||
this.applePayConfig = await window[ this.namespace ]
|
this.#applePayConfig = await window[ this.#namespace ]
|
||||||
.Applepay()
|
.Applepay()
|
||||||
.config();
|
.config();
|
||||||
|
|
||||||
this.contextHandler = ContextHandlerFactory.create(
|
this.#contextHandler = ContextHandlerFactory.create(
|
||||||
this.ppcpConfig.context,
|
this.#ppcpConfig.context,
|
||||||
this.buttonConfig,
|
this.#buttonConfig,
|
||||||
this.ppcpConfig,
|
this.#ppcpConfig,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
const button = ApplePayButton.createButton(
|
const button = ApplePayButton.createButton(
|
||||||
this.ppcpConfig.context,
|
this.#ppcpConfig.context,
|
||||||
null,
|
null,
|
||||||
this.buttonConfig,
|
this.#buttonConfig,
|
||||||
this.ppcpConfig,
|
this.#ppcpConfig,
|
||||||
this.contextHandler
|
this.#contextHandler
|
||||||
);
|
);
|
||||||
|
|
||||||
button.configure( this.applePayConfig );
|
button.configure( this.#applePayConfig );
|
||||||
button.init();
|
button.init();
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error( 'Failed to initialize Apple Pay:', error );
|
console.error( 'Failed to initialize Apple Pay:', error );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue