changes to mimic google implementation

This commit is contained in:
carmenmaymo 2023-08-31 12:48:01 +02:00
parent 4797d53ad5
commit 63ab1e383d
No known key found for this signature in database
GPG key ID: 6023F686B0F3102E
20 changed files with 724 additions and 216 deletions

View file

@ -0,0 +1,63 @@
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')
) {
console.error('PayPal button could not be configured.');
return;
}
console.log(buttonConfig.button.wrapper)
// If button wrapper is not present then there is no need to load the scripts.
if (!jQuery(buttonConfig.button.wrapper).length) {
return;
}
let bootstrapped = false;
let paypalLoaded = false;
let applePayLoaded = false;
/* const tryToBoot = () => {
if (!bootstrapped && paypalLoaded && applePayLoaded) {
console.log('Trying to bootstrap')
bootstrapped = true;
bootstrap();
}
}*/
// Load ApplePay SDK
/*loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
console.log('ApplePay SDK loaded', buttonConfig.sdk_url)
applePayLoaded = true;
//tryToBoot();
});*/
// Load PayPal
loadPaypalScript(ppcpConfig, () => {
paypalLoaded = true;
//tryToBoot();
});
},
);
})({
buttonConfig: window.wc_ppcp_applepay,
ppcpConfig: window.PayPalCommerceGateway,
jQuery: window.jQuery
});