woocommerce-paypal-payments/modules/ppcp-googlepay/resources/js/GooglepayManager.js
Pedro Silva 84e4c2c40a
Fix GooglePay mini-cart button loading
Fix GooglePay shipping callback
Fix GooglePay button on cart updates
2023-10-17 10:47:26 +01:00

49 lines
1.2 KiB
JavaScript

import buttonModuleWatcher from "../../../ppcp-button/resources/js/modules/ButtonModuleWatcher";
import GooglepayButton from "./GooglepayButton";
class GooglepayManager {
constructor(buttonConfig, ppcpConfig) {
this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig;
this.googlePayConfig = null;
this.buttons = [];
buttonModuleWatcher.watchContextBootstrap((bootstrap) => {
const button = new GooglepayButton(
bootstrap.context,
bootstrap.handler,
buttonConfig,
ppcpConfig,
);
this.buttons.push(button);
if (this.googlePayConfig) {
button.init(this.googlePayConfig);
}
});
}
init() {
(async () => {
// Gets GooglePay configuration of the PayPal merchant.
this.googlePayConfig = await paypal.Googlepay().config();
for (const button of this.buttons) {
button.init(this.googlePayConfig);
}
})();
}
reinit() {
for (const button of this.buttons) {
button.reinit();
}
}
}
export default GooglepayManager;