mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add ButtonModuleWatcher
Adjustments for APM support
This commit is contained in:
parent
e7e5ebde4e
commit
93afeeba68
6 changed files with 59 additions and 14 deletions
|
@ -19,6 +19,7 @@ import FreeTrialHandler from "./modules/ActionHandler/FreeTrialHandler";
|
|||
import FormSaver from './modules/Helper/FormSaver';
|
||||
import FormValidator from "./modules/Helper/FormValidator";
|
||||
import {loadPaypalScript} from "./modules/Helper/ScriptLoading";
|
||||
import buttonModuleWatcher from "./modules/ButtonModuleWatcher";
|
||||
|
||||
// TODO: could be a good idea to have a separate spinner for each gateway,
|
||||
// but I think we care mainly about the script loading, so one spinner should be enough.
|
||||
|
@ -60,6 +61,11 @@ const bootstrap = () => {
|
|||
}
|
||||
});
|
||||
|
||||
const hasMessages = () => {
|
||||
return PayPalCommerceGateway.messages.is_hidden === false
|
||||
&& document.querySelector(PayPalCommerceGateway.messages.wrapper);
|
||||
}
|
||||
|
||||
const onSmartButtonClick = async (data, actions) => {
|
||||
window.ppcpFundingSource = data.fundingSource;
|
||||
const requiredFields = jQuery('form.woocommerce-checkout .validate-required:visible :input');
|
||||
|
@ -146,6 +152,7 @@ const bootstrap = () => {
|
|||
);
|
||||
|
||||
miniCartBootstrap.init();
|
||||
buttonModuleWatcher.registerContextBootstrap('mini-cart', miniCartBootstrap);
|
||||
}
|
||||
|
||||
if (
|
||||
|
@ -163,6 +170,7 @@ const bootstrap = () => {
|
|||
);
|
||||
|
||||
singleProductBootstrap.init();
|
||||
buttonModuleWatcher.registerContextBootstrap('product', singleProductBootstrap);
|
||||
}
|
||||
|
||||
if (context === 'cart') {
|
||||
|
@ -174,6 +182,7 @@ const bootstrap = () => {
|
|||
);
|
||||
|
||||
cartBootstrap.init();
|
||||
buttonModuleWatcher.registerContextBootstrap('cart', cartBootstrap);
|
||||
}
|
||||
|
||||
if (context === 'checkout') {
|
||||
|
@ -186,6 +195,7 @@ const bootstrap = () => {
|
|||
);
|
||||
|
||||
checkoutBootstap.init();
|
||||
buttonModuleWatcher.registerContextBootstrap('checkout', checkoutBootstap);
|
||||
}
|
||||
|
||||
if (context === 'pay-now' ) {
|
||||
|
@ -197,15 +207,11 @@ const bootstrap = () => {
|
|||
errorHandler,
|
||||
);
|
||||
payNowBootstrap.init();
|
||||
buttonModuleWatcher.registerContextBootstrap('pay-now', payNowBootstrap);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const hasMessages = () => {
|
||||
return PayPalCommerceGateway.messages.is_hidden === false
|
||||
&& document.querySelector(PayPalCommerceGateway.messages.wrapper);
|
||||
}
|
||||
|
||||
document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
class ButtonModuleWatcher {
|
||||
|
||||
constructor() {
|
||||
this.contextBootstrapRegistry = {};
|
||||
this.contextBootstrapWatchers = [];
|
||||
}
|
||||
|
||||
watchContextBootstrap(callable) {
|
||||
this.contextBootstrapWatchers.push(callable);
|
||||
Object.values(this.contextBootstrapRegistry).forEach(callable);
|
||||
}
|
||||
|
||||
registerContextBootstrap(context, handler) {
|
||||
this.contextBootstrapRegistry[context] = {
|
||||
context: context,
|
||||
handler: handler
|
||||
}
|
||||
|
||||
// Call registered watchers
|
||||
for (const callable of this.contextBootstrapWatchers) {
|
||||
callable(this.contextBootstrapRegistry[context]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
window.ppcpResources = window.ppcpResources || {};
|
||||
const buttonModuleWatcher = window.ppcpResources['ButtonModuleWatcher'] = window.ppcpResources['ButtonModuleWatcher'] || new ButtonModuleWatcher();
|
||||
|
||||
export default buttonModuleWatcher;
|
|
@ -1,5 +1,4 @@
|
|||
import {loadScript} from "@paypal/paypal-js";
|
||||
import widgetBuilder from "./Renderer/WidgetBuilder";
|
||||
|
||||
const storageKey = 'ppcp-data-client-id';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue