Skip to content

Commit

Permalink
Add observer for applepay
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbinaBaraliu committed Dec 4, 2024
1 parent 8d85de0 commit 1cabf45
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions view/frontend/web/js/hide-applepay.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
document.addEventListener('DOMContentLoaded', function() {
const checkPaySupport = function () {
if (!('ApplePaySession' in window)) return false;
if (typeof ApplePaySession === 'undefined') return false;
return true;
document.addEventListener('DOMContentLoaded', function () {
const hideApplePayIfUnsupported = function () {
const checkApplePaySupport = function () {
if (!('ApplePaySession' in window)) return false;
if (typeof ApplePaySession === 'undefined') return false;
return true;
};

const applePaySupported = checkApplePaySupport();
const applePayContainer = document.getElementById('payment-method-option-buckaroo_magento2_applepay');
if (!applePaySupported && applePayContainer) {
applePayContainer.style.display = 'none';
}
};

const applePaySupported = checkPaySupport();
const applePayContainer = document.getElementById('payment-method-option-buckaroo_magento2_applepay');
if (!applePaySupported && applePayContainer) {
applePayContainer.style.display = 'none';
hideApplePayIfUnsupported();

const observer = new MutationObserver(() => {
hideApplePayIfUnsupported();
});

if (document.body) {
observer.observe(document.body, {
childList: true,
subtree: true
});
} else {
console.error("document.body is not available for observation.");
}
});

0 comments on commit 1cabf45

Please sign in to comment.