woocommerce-paypal-payments/modules/ppcp-googlepay/resources/js/GooglepayManager.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-08-28 17:19:07 +01:00
import buttonModuleWatcher from "../../../ppcp-button/resources/js/modules/ButtonModuleWatcher";
import GooglepayButton from "./GooglepayButton";
2023-08-22 11:34:52 +01:00
class GooglepayManager {
2023-08-23 11:20:40 +01:00
constructor(buttonConfig, ppcpConfig) {
2023-08-22 11:34:52 +01:00
this.buttonConfig = buttonConfig;
2023-08-23 11:20:40 +01:00
this.ppcpConfig = ppcpConfig;
2023-08-22 11:34:52 +01:00
this.googlePayConfig = null;
this.buttons = [];
2023-08-28 17:19:07 +01:00
buttonModuleWatcher.watchContextBootstrap((bootstrap) => {
const button = new GooglepayButton(
2023-08-28 17:19:07 +01:00
bootstrap.context,
bootstrap.handler,
2023-08-28 17:19:07 +01:00
buttonConfig,
ppcpConfig,
2023-08-28 17:19:07 +01:00
);
2023-08-22 11:34:52 +01:00
this.buttons.push(button);
2023-08-22 11:34:52 +01:00
if (this.googlePayConfig) {
button.init(this.googlePayConfig);
2023-08-22 11:34:52 +01:00
}
});
}
init() {
(async () => {
2023-08-31 17:38:23 +01:00
// Gets GooglePay configuration of the PayPal merchant.
this.googlePayConfig = await paypal.Googlepay().config();
2023-08-29 08:19:11 +01:00
for (const button of this.buttons) {
button.init(this.googlePayConfig);
}
})();
2023-08-22 11:34:52 +01:00
}
reinit() {
for (const button of this.buttons) {
button.reinit();
}
}
2023-08-22 11:34:52 +01:00
}
export default GooglepayManager;