mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
import {loadCustomScript} from "@paypal/paypal-js";
|
|
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
|
import ApplepayManager from "./ApplepayManager";
|
|
|
|
(function ({
|
|
buttonConfig,
|
|
ppcpConfig,
|
|
jQuery
|
|
}) {
|
|
|
|
const bootstrap = function () {
|
|
const manager = new ApplepayManager(buttonConfig, ppcpConfig);
|
|
manager.init();
|
|
};
|
|
|
|
document.addEventListener(
|
|
'DOMContentLoaded',
|
|
() => {
|
|
if (
|
|
(typeof (buttonConfig) === 'undefined') ||
|
|
(typeof (ppcpConfig) === 'undefined')
|
|
) {
|
|
return;
|
|
}
|
|
const isMiniCart = ppcpConfig.mini_cart_buttons_enabled;
|
|
const isButton = jQuery('#' + buttonConfig.button.wrapper).length > 0;
|
|
// If button wrapper is not present then there is no need to load the scripts.
|
|
// minicart loads later?
|
|
if (!isMiniCart && !isButton) {
|
|
return;
|
|
}
|
|
|
|
let bootstrapped = false;
|
|
let paypalLoaded = false;
|
|
let applePayLoaded = false;
|
|
|
|
const tryToBoot = () => {
|
|
if (!bootstrapped && paypalLoaded && applePayLoaded) {
|
|
bootstrapped = true;
|
|
bootstrap();
|
|
}
|
|
}
|
|
|
|
// Load ApplePay SDK
|
|
loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
|
|
applePayLoaded = true;
|
|
tryToBoot();
|
|
});
|
|
|
|
// Load PayPal
|
|
loadPaypalScript(ppcpConfig, () => {
|
|
paypalLoaded = true;
|
|
tryToBoot();
|
|
});
|
|
},
|
|
);
|
|
|
|
})({
|
|
buttonConfig: window.wc_ppcp_applepay,
|
|
ppcpConfig: window.PayPalCommerceGateway,
|
|
jQuery: window.jQuery
|
|
});
|