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

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-08-22 11:34:52 +01:00
import {loadCustomScript} from "@paypal/paypal-js";
2023-08-22 08:44:32 +01:00
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
2023-08-22 11:34:52 +01:00
import GooglepayManager from "./GooglepayManager";
2023-08-22 08:44:32 +01:00
(function ({
buttonConfig,
ppcpConfig,
jQuery
}) {
const bootstrap = function () {
2023-08-23 11:20:40 +01:00
const manager = new GooglepayManager(buttonConfig, ppcpConfig);
2023-08-22 11:34:52 +01:00
manager.init();
2023-08-22 08:44:32 +01:00
};
document.addEventListener(
'DOMContentLoaded',
() => {
if (
(typeof (buttonConfig) === 'undefined') ||
(typeof (ppcpConfig) === 'undefined')
) {
console.error('PayPal button could not be configured.');
return;
}
let bootstrapped = false;
2023-08-22 11:34:52 +01:00
let paypalLoaded = false;
let googlePayLoaded = false;
const tryToBoot = () => {
if (!bootstrapped && paypalLoaded && googlePayLoaded) {
bootstrapped = true;
bootstrap();
}
}
// Load GooglePay SDK
loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
googlePayLoaded = true;
tryToBoot();
});
2023-08-22 08:44:32 +01:00
2023-08-22 11:34:52 +01:00
// Load PayPal
2023-08-22 08:44:32 +01:00
loadPaypalScript(ppcpConfig, () => {
2023-08-22 11:34:52 +01:00
paypalLoaded = true;
tryToBoot();
2023-08-22 08:44:32 +01:00
});
},
);
})({
buttonConfig: window.wc_ppcp_googlepay,
ppcpConfig: window.PayPalCommerceGateway,
jQuery: window.jQuery
});