(function ($){
"use strict";
$(function (){
jQuery('body').on('click', '.gopay_select', function (){
jQuery(this).children('.gopay_select_input').prop('checked', true);
});
});
}(jQuery));
jQuery('body').on('updated_checkout', function (){
if(gopay_localize.applePay!=='safari'){
return;
}
const applePayDebug={
userAgent: navigator.userAgent,
platform: navigator.platform,
hasApplePaySession: !!window.ApplePaySession,
canMakePayments: null,
error: null
};
function log(msg, data=null){
}
function hideApplePay(reason){
log('Apple Pay SKRYTO – důvod:', reason);
const li=document.querySelector('li.payment_method_gopay-inline-apple_pay'
);
if(li){
li.style.display='none';
const radio=li.querySelector('input[type="radio"]');
if(radio&&radio.checked){
radio.checked=false;
const firstOther=document.querySelector('input[name="payment_method"]:not([value="gopay-inline-apple_pay"])'
);
if(firstOther){
firstOther.checked=true;
jQuery(firstOther).trigger('change');
}}
}
document.querySelectorAll('.gopay_select').forEach(function (el){
const input=el.querySelector('input[value="APPLE_PAY"]');
if(input){
el.style.display='none';
}});
window.applePayDebugInfo=applePayDebug;
}
let canUseApplePay=false;
if(!window.ApplePaySession){
applePayDebug.error='ApplePaySession není dostupná';
hideApplePay('ApplePaySession neexistuje (ne Safari / ne macOS)');
return;
}
try {
canUseApplePay=ApplePaySession.canMakePayments();
applePayDebug.canMakePayments=canUseApplePay;
log('ApplePaySession.canMakePayments()', canUseApplePay);
} catch (e){
applePayDebug.error=e.message;
log('CHYBA při volání canMakePayments()', e);
hideApplePay('Výjimka při canMakePayments()');
return;
}
if(!canUseApplePay){
hideApplePay('Zařízení / účet nemůže platit Apple Pay');
}else{
log('Apple Pay POVOLENO');
}});