2023-08-28 17:19:07 +01:00
|
|
|
import buttonModuleWatcher from "../../../ppcp-button/resources/js/modules/ButtonModuleWatcher";
|
2023-08-29 14:19:27 +01:00
|
|
|
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;
|
|
|
|
|
2023-08-29 14:19:27 +01:00
|
|
|
this.buttons = [];
|
2023-08-28 17:19:07 +01:00
|
|
|
|
|
|
|
buttonModuleWatcher.watchContextBootstrap((bootstrap) => {
|
2023-08-29 14:19:27 +01:00
|
|
|
const button = new GooglepayButton(
|
2023-08-28 17:19:07 +01:00
|
|
|
bootstrap.context,
|
2023-08-29 14:19:27 +01:00
|
|
|
bootstrap.handler,
|
2023-08-28 17:19:07 +01:00
|
|
|
buttonConfig,
|
2023-08-29 14:19:27 +01:00
|
|
|
ppcpConfig,
|
2023-08-28 17:19:07 +01:00
|
|
|
);
|
2023-08-22 11:34:52 +01:00
|
|
|
|
2023-08-29 14:19:27 +01:00
|
|
|
this.buttons.push(button);
|
2023-08-22 11:34:52 +01:00
|
|
|
|
2023-08-29 14:19:27 +01:00
|
|
|
if (this.googlePayConfig) {
|
|
|
|
button.init(this.googlePayConfig);
|
2023-08-22 11:34:52 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-29 14:19:27 +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
|
|
|
|
2023-08-29 14:19:27 +01:00
|
|
|
for (const button of this.buttons) {
|
|
|
|
button.init(this.googlePayConfig);
|
|
|
|
}
|
|
|
|
})();
|
2023-08-22 11:34:52 +01:00
|
|
|
}
|
|
|
|
|
2023-10-17 10:47:26 +01:00
|
|
|
reinit() {
|
|
|
|
for (const button of this.buttons) {
|
|
|
|
button.reinit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-22 11:34:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default GooglepayManager;
|