(function($){
'use strict';
document.addEventListener('DOMContentLoaded', function(){
$('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').hide();
$(document.body).on('updated_checkout', function (){
$.ajax({
type: 'POST',
url: primer_3ds_ajax_obj.ajaxurl,
data: {action: 'custom_checkout_button'},
success: function (response){
let responseHtml=$(response.slice(0, -1));
let voucherMainDivs=responseHtml.filter('div[id^="custom-checkout-voucher-data-"]');
let voucherElements=voucherMainDivs.get();
voucherElements.forEach(function(element){
let voucherId=element.id.replace('custom-checkout-voucher-data-', '');
let showVoucherButton=document.getElementById(`show-voucher-modal-${voucherId}`);
let voucherModal=document.getElementById(`voucher-modal-${voucherId}`);
if(showVoucherButton&&voucherModal){
let voucher_data=null;
let voucher=document.getElementById(`voucher-button-${voucherId}`);
let preventEnter=function(event){
if(event.key==='Enter'){
event.preventDefault();
voucher.click();
}};
showVoucherButton.addEventListener('click', function (){
let customer_vat=document.getElementById('billing_vat');
if(customer_vat?.value){
document.getElementById(`voucher-vat-${voucherId}`).value=customer_vat.value;
}
let forms=document.getElementsByName('checkout');
if(forms.length > 0){
let form=forms[0];
form.addEventListener('keypress', preventEnter);
}
openModal();
});
document.getElementById(`close-modal-${voucherId}`).addEventListener('click', function (){
let forms=document.getElementsByName('checkout');
if(forms.length > 0){
let form=forms[0];
form.removeEventListener('keypress', preventEnter);
}
closeModal();
});
const openModal=function(){
$(`#voucher-modal-${voucherId}`).fadeIn();
};
const closeModal=function(){
$(`#voucher-modal-${voucherId}`).fadeOut();
};
$(document).mouseup(function(e){
var modalContent=$(`.voucher-modal-content-${voucherId}`);
if(!modalContent.is(e.target)&&modalContent.has(e.target).length===0){
closeModal();
}});
voucher.addEventListener('click', function (){
let voucher_code=document.getElementById(`voucher-code-${voucherId}`);
let voucher_vat=document.getElementById(`voucher-vat-${voucherId}`);
let buttonText=document.getElementById(`button-text-${voucherId}`);
let loader=document.getElementById(`voucher-loader-${voucherId}`);
if(!voucher_code?.value||!voucher_vat?.value||voucher_vat?.value.trim().length!==9){
alert("Παρακαλώ ελέγξτε τα πεδία και ξαναπροσπαθήστε.");
return;
}
buttonText.style.display='none';
voucher.disabled=true;
loader.style.display='inline';
jQuery.ajax({
type: "post",
url: primer_3ds_ajax_obj.ajaxurl,
data: {
action: "check_voucher_send_otp",
voucher_code: voucher_code.value.trim().replace(/ +/g, ""),
voucher_vat: voucher_vat.value.trim().replace(/ +/g, ""),
voucher_modal_id: voucherId
},
success: function (response){
console.log(response)
if(response.success){
if(response?.code==="02.01"){
alert(response.message)
}
const yearField=document.getElementById(`voucher-year-field-${voucherId}`);
document.getElementById(`year-field-${voucherId}`).style.display='flex';
document.getElementById(`otp-description-${voucherId}`).style.display='inline';
document.getElementById(`otp-field-${voucherId}`).style.display='flex';
document.getElementById(`voucher-description-${voucherId}`).style.display='none';
document.getElementById(`vat-field-${voucherId}`).style.display='none';
document.getElementById(`code-field-${voucherId}`).style.display='none';
document.getElementById(`voucher-otp-description-${voucherId}`).innerHTML=`Ο έλεγχος εγκυρότητας ήταν επιτυχής για την επιταγή ${voucher_code.value.trim().replace(/ +/g, "")} αξίας ${response.voucher_data.voucher_value.toFixed(2).replace('.', ',')} €`;
document.getElementById(`voucher-button-${voucherId}`).style.display='none';
document.getElementById(`otp-button-${voucherId}`).style.display='inline';
voucher_data=response.voucher_data;
if(response?.voucher_data&&response?.year_field==="2"&&response.voucher_data.call_for_applications_id.startsWith('01.')&&response.voucher_data.voucher_value >=625){
yearField.disabled=false;
yearField.selectedIndex=1;
yearField.value='2';
yearField.disabled=true;
}}else{
alert(response.data);
}
buttonText.style.display='inline';
loader.style.display='none';
voucher.disabled=false;
},
error: function (error){
console.log(error);
buttonText.style.display='inline';
loader.style.display='none';
voucher.disabled=false;
},
});
});
let otp_button=document.getElementById(`otp-button-${voucherId}`);
otp_button.addEventListener('click', function (){
let voucher_code=document.getElementById(`voucher-code-${voucherId}`);
let otp_code=document.getElementById(`voucher-otp-${voucherId}`);
let buttonText=document.getElementById(`otp-button-text-${voucherId}`);
let loader=document.getElementById(`otp-loader-${voucherId}`);
let year_field=document.getElementById(`voucher-year-field-${voucherId}`);
if(!voucher_code?.value||!otp_code?.value||otp_code?.value.trim().length!==6){
alert("Παρακαλώ ελέγξτε τα πεδία και ξαναπροσπαθήστε. O κωδικός OTP πρέπει να είναι εξαψήφιος αριθμός.");
return;
}
if(year_field?.value){
voucher_data.year_field=year_field.value;
}else{
voucher_data.year_field="1";
}
buttonText.style.display='none';
loader.style.display='inline';
jQuery.ajax({
type: "post",
url: primer_3ds_ajax_obj.ajaxurl,
data: {
action: "send_otp_pre_auth",
voucher_code: voucher_code.value.trim().replace(/ +/g, ""),
otp_code: otp_code.value.trim().replace(/ +/g, ""),
voucher_data: voucher_data,
voucher_modal_id: voucherId
},
success: function (response){
console.log(response)
if(response.success){
closeModal();
jQuery('body').trigger('update_checkout');
let homeUrl=window.location.origin;
window.location.replace(homeUrl + '/checkout-2/');
}else{
alert(response.data);
}
buttonText.style.display='inline';
loader.style.display='none';
},
error: function (error){
console.log(error);
buttonText.style.display='inline';
loader.style.display='none';
},
});
});
}
let cancel_voucher_button=document.getElementById(`cancel-voucher-${voucherId}`);
if(cancel_voucher_button){
cancel_voucher_button.addEventListener('click', function (){
let confirmation=window.confirm("Είστε σίγουροι οτί θέλετε να ακυρώσετε την επιταγή?");
if(confirmation){
let voucher_code=document.getElementById(`used-voucher-code-${voucherId}`);
let buttonText=document.getElementById(`cancel-button-text-${voucherId}`);
let loader=document.getElementById(`cancel-loader-${voucherId}`);
if(!voucher_code){
alert("Κάτι πήγε λάθος. Παρακαλώ ξαναπροσπαθήστε.");
return;
}
buttonText.style.display='none';
loader.style.display='inline';
jQuery.ajax({
type: "post",
url: primer_3ds_ajax_obj.ajaxurl,
data: {
action: "cancel_voucher",
voucher_code: voucher_code.innerHTML.trim().replace(/ +/g, ""),
voucher_modal_id: voucherId
},
success: function (response){
if(response.success){
window.location.reload();
}else{
alert(response.data);
}
buttonText.style.display='inline';
loader.style.display='none';
},
error: function (error){
console.log(error);
buttonText.style.display='inline';
loader.style.display='none';
},
});
}});
}});
}});
});
const modal=document.getElementById("modal");
if(modal){
modal.style.display='block';
}
let timesCalled=0;
let finalize=0;
const form=document.getElementById('tdsMmethodForm');
const acsElement=document.getElementById("showAcs");
if(!form&&acsElement&&acsElement.src!==null){
acsElement.style.display="flex";
acsElement.addEventListener('load', function (){
if(acsElement.contentDocument){
console.log("start looking for cres pers from start");
console.log(acsElement.contentDocument);
acsElement.style.display="none";
makeAjaxRequestForFinal();
}});
}
function extractOrderIdFromURL(){
const url=window.location.href;
const matches=url.match(/\/order-pay\/(\d+)\//);
if(matches&&matches.length > 1){
return matches[1];
}
return null;
}
if(form){
function makeAjaxRequest(){
const order_id=extractOrderIdFromURL();
if(order_id){
jQuery.ajax({
type: "post",
url: primer_3ds_ajax_obj.ajaxurl,
data: {action: "continue_3ds_method", order_id: order_id, timesCalled: timesCalled},
success: function (response){
console.log(response)
if(response.type==="success"){
console.log("Success! Stopping the loop.");
if(response.action==="do_transaction"){
console.log("Success! Proceed Transaction.");
jQuery.ajax({
type: "post",
url: primer_3ds_ajax_obj.ajaxurl,
data: {action: "process_payment_with_token", order_id: order_id, transaction_form_data: response.data},
success: function (response_second){
console.log(response_second)
if(response_second.type==="redirect"){
console.log("redirecting")
window.location.href=response_second.redirect;
}else{
window.history.back();
}},
error: function (error){
console.log(error);
},
});
}}else if(response.type==="showAcs"){
if(modal){
const acsElement=document.getElementById("showAcs");
acsElement.src='data:text/html;charset=utf-8,' + encodeURIComponent(response.acsData);
acsElement.style.display="flex";
acsElement.addEventListener('load', function (){
if(acsElement.contentDocument){
console.log("start looking for cres pers");
console.log(acsElement.contentDocument);
acsElement.style.display="none";
makeAjaxRequestForFinal();
}});
}else{
window.history.back();
}}else if(response.type==="redirect"){
console.log("redirecting")
window.location.href=response.redirect;
}else{
console.log("relooping")
timesCalled++;
setTimeout(makeAjaxRequest, 700);
}},
error: function (error){
setTimeout(makeAjaxRequest, 700);
},
});
}else{
console.log("no order");
}}
const startTime=Date.now();
const duration=10 * 1000;
function startAjaxLoop(){
const currentTime=Date.now();
if(currentTime - startTime < duration){
makeAjaxRequest();
}else{
console.log("Loop completed after 10 seconds.");
}}
startAjaxLoop();
}
function makeAjaxRequestForFinal(){
const order_id=extractOrderIdFromURL();
if(order_id&&finalize===0){
finalize=1;
jQuery.ajax({
type: "post",
url: primer_3ds_ajax_obj.ajaxurl,
data: {action: "finalize_3ds_method", order_id: order_id},
success: function (response){
console.log(response)
if(response.type==="success"){
console.log("Success! Stopping the loop.");
if(response.action==="do_transaction"){
console.log("Success! Proceed Transaction.");
jQuery.ajax({
type: "post",
url: primer_3ds_ajax_obj.ajaxurl,
data: {action: "process_payment_with_token", order_id: order_id, transaction_form_data: response.data},
success: function (response_second){
console.log(response_second)
if(response_second.type==="redirect"){
console.log("redirecting")
window.location.href=response_second.redirect;
}else{
window.history.back();
}},
error: function (error){
console.log(error);
},
});
}}else if(response.type==="redirect"){
console.log("redirecting final")
window.location.href=response.redirect;
}else{
console.log("relooping final")
finalize=0;
setTimeout(makeAjaxRequestForFinal, 700);
}},
error: function (error){
finalize=0;
setTimeout(makeAjaxRequestForFinal, 700);
},
});
}else{
console.log("no order");
}}
});
})(jQuery);
(function (){
'use strict';
var $;
var Tooltipck=function (options){
if(!(this instanceof Tooltipck)) return new Tooltipck(options);
if(typeof jQuery!=='undefined'){
$=jQuery;
}
if(typeof $==='undefined'){
console.log('Tooltip CK error:jQuery instance not found !');
return;
}
var t=this;
var defaults={
fxTransition: 'linear',
fxType: 'both',
fxDuration: 500,
tipPosition: 'right',
delayIn: 0,
delayOut: 500,
isMobile: 0,
opacity: 0.9,
offsetx: 0,
offsety: 0
};
options=options||{};
options=$.extend(defaults, options);
var tooltip;
$('.tooltipck').each(function(i, tooltip){
tooltip=$(tooltip);
if(tooltip.attr('data-done')=='1') return;
tooltip=$.extend(tooltip, options);
tooltip.css('display', 'inline-block');
tooltip.height=tooltip.height();
tooltip.width=tooltip.width();
tooltip.css('display', '');
tooltip.attr('data-position', options.tipPosition);
tooltip.tip=$('> .tooltipck-tip', tooltip);
$(document.body).append(tooltip.tip);
tooltip.tipWidth=parseInt(tooltip.tip.attr('data-width'));
tooltip.tipHeight=tooltip.tip.outerHeight();
tooltip.tip.css({
'opacity': '0',
'width': '0',
'height': '0'
});
getTooltipParams();
tooltip.attr('data-done', '1');
if(options.isMobile==1){
tooltip.click(function(){
if(tooltip.data('status')!='open'&&tooltip.data('status')!='opened'){
showTip(tooltip);
hideTipOutsideClick();
}else{
hideTip(tooltip);
}});
tooltip.tip.click(function(){
if(tooltip.data('status')=='opened'){
hideTip(tooltip);
}});
}else{
tooltip.mouseover(function(){
showTip(tooltip);
});
tooltip.mouseleave(function(){
hideTip(tooltip);
});
}
function hideTipOutsideClick(){
$(window).on('click', function(event){
if(tooltip.data('status')=='open'
&&
tooltip.has(event.target).length==0 
&&
!tooltip.is(event.target)
){
hideTip(tooltip);
}else{
}});
}
function getTipPosition(){
var prop1 ,val1, prop2, val2;
switch(tooltip.tipPosition){
case 'right':
default:
prop1='left';
val1=(tooltip.pointer.offset().left + parseInt(tooltip.offsetx)) + 'px';
prop2='top';
val2=(tooltip.pointer.offset().top + parseInt(tooltip.offsety)) + 'px';
break;
case 'left':
prop1='left';
val1=(tooltip.pointer.offset().left + parseInt(tooltip.offsetx) - tooltip.tipWidth - tooltip.width) + 'px';
prop2='top';
val2=(tooltip.pointer.offset().top + parseInt(tooltip.offsety)) + 'px';
break;
case 'top':
prop1='left';
val1=(tooltip.pointer.offset().left + parseInt(tooltip.offsetx) - (tooltip.tipWidth / 2) - (tooltip.width / 2)) + 'px';
prop2='top';
val2=(tooltip.pointer.offset().top + parseInt(tooltip.offsety) - tooltip.tipHeight - tooltip.height) + 'px';
break;
case 'bottom':
prop1='left';
val1=(tooltip.pointer.offset().left + parseInt(tooltip.offsetx) - (tooltip.tipWidth / 2) - (tooltip.width / 2)) + 'px';
prop2='top';
val2=(tooltip.pointer.offset().top + tooltip.height + parseInt(tooltip.offsety)) + 'px';
break;
}
return Array(prop1, val1, prop2, val2);
}
function checkWithinBounds(){
var boundTop=$(document).scrollTop();
var boundBottom=boundTop + $(window).height();
var boundLeft=$(document).scrollLeft();
var boundRight=boundLeft + $(window).width();
if(tooltip.tipPosition=='right'){
var tipPositionRight=tooltip.pointer.offset().left + parseInt(tooltip.tip.css('marginLeft')) + tooltip.tipWidth;
var hOffset=boundRight - tipPositionRight;
if(hOffset < 0){
tooltip.tip.css('marginLeft', '+=' + hOffset + 'px');
}}
if(tooltip.tipPosition!='top'){
if(tooltip.tipPosition=='bottom'){
var tipPositionBottom=tooltip.pointer.offset().top + tooltip.tipHeight + parseInt(tooltip.tip.css('marginTop')) + tooltip.height;
}else{
var tipPositionBottom=tooltip.pointer.offset().top + tooltip.tipHeight + parseInt(tooltip.tip.css('marginTop'));
}
var vOffset=boundBottom - tipPositionBottom;
if(vOffset < 0){
tooltip.tip.css('marginTop', '+=' + vOffset + 'px');
}}
}
function checkWithinBoundsAfterAnimation(){
var boundTop=$(document).scrollTop();
var left=parseInt(tooltip.tip.css('left'));
var marginLeft=parseInt(tooltip.tip.css('marginLeft'));
var top=parseInt(tooltip.tip.position().top);
var marginTop=parseInt(tooltip.tip.css('marginTop'));
tooltip.tip.css('max-width', '');
tooltip.tip.css('max-height', '');
if((tooltip.tip.width() + 10) > $(window).width()){
tooltip.tip.css({
'marginLeft': '0px'
,'left': '5px'
,'max-width': $(window).width() - 10 + 'px'
});
}
if((tooltip.tip.height() + 10) > $(window).height()){
tooltip.tip.css({
'marginTop': '0px'
,'top': '5px'
,'max-height': $(window).height() - 10 + 'px'
});
}
if(left + marginLeft < 0){
tooltip.tip.css({
'left': '5px'
,'marginLeft': '0'
});
}
if(top + marginTop < boundTop){
tooltip.tip.css({
'top': boundTop + 'px'
,'marginTop': '0'
});
}}
function showTip(el){
clearTimeout(el.timeout);
el.timeout=setTimeout(function(){
openTip(el);
}, options.delayIn);
}
function hideTip(el){
clearTimeout(el.timeout);
el.timeout=setTimeout(function(){
if(tooltip.hasClass('tooltipck-paused')) return;
$(el).data('status', 'hide')
closeTip(el);
}, tooltip.delayOut);
}
function openTip(el){
var tip=$(el.tip);
el.data('status', 'open');
if(el.data('status')=='opened')
return;
tip.addClass('tooltipck-hover');
tooltip.pointer=tooltip.find('.tooltipck-pointer');
tooltip.checkedPositions=[];
while (tooltip.checkedPositions.length){ tooltip.checkedPositions.pop(); }
tooltip.tipPosition=tooltip.attr('data-position');
var tipPositionCss=getTipPosition();
tip.css({
'top': '',
'bottom': '',
'left': '',
'right': '',
'marginLeft': '',
'marginTop': '',
});
tip.css(tipPositionCss[0], tipPositionCss[1]);
tip.css(tipPositionCss[2], tipPositionCss[3]);
checkWithinBounds();
$('.tooltipck').removeClass('tooltipck-active');
tooltip.addClass('tooltipck-active');
switch(options.fxType){
case 'both':
default:
tip.css('display' ,'inline-block');
tip.animate({
'opacity':options.opacity,
'height':el.tipHeight,
'width':el.tipWidth,
}, {
duration: parseInt(tooltip.fxDuration),
transition:  options.fxTransition,
complete: function(){
el.data('status', 'opened');
tip.css('height' ,'auto');
checkWithinBoundsAfterAnimation();
}});
break;
case 'horizontal':
tip.css('height', el.tipHeight);
tip.css('display' ,'inline-block');
tip.animate({
'opacity':options.opacity,
'width':el.tipWidth,
}, {
duration: parseInt(tooltip.fxDuration),
transition:  options.fxTransition,
complete: function(){
el.data('status', 'opened');
tip.css('height' ,'auto');
checkWithinBoundsAfterAnimation();
}});
break;
case 'vertical':
tip.css('width', el.tipWidth);
tip.css('display' ,'inline-block');
tip.animate({
'opacity':options.opacity,
'height':el.tipHeight,
}, {
duration: parseInt(tooltip.fxDuration),
transition:  options.fxTransition,
complete: function(){
el.data('status', 'opened');
checkWithinBoundsAfterAnimation();
}});
break;
case 'fade':
tip.css('height', el.tipHeight);
tip.css('width', el.tipWidth);
tip.css('display', 'inline-block');
tip.animate({
'opacity':options.opacity
}, {
duration: parseInt(tooltip.fxDuration),
transition:  options.fxTransition,
complete: function(){
el.data('status', 'opened');
tip.css('height' ,'auto');
checkWithinBoundsAfterAnimation();
}});
break;
}
if(options.isMobile==1){
}else{
tip.mouseover(function(){
tooltip.addClass('tooltipck-paused');
}).mouseleave(function(){
tooltip.removeClass('tooltipck-paused').trigger('mouseleave');
});
}}
function closeTip(el){
var tip=$(el.tip);
el.data('status', 'close');
tip.stop(true, true);
tip.css({
'opacity': '0',
'width': '0',
'height': '0',
'display':'none'
});
tooltip.removeClass('tooltipck-active');
tip.removeClass('tooltipck-hover');
el.data('status', 'closed');
}
function getTooltipParams(){
if(tooltip.attr('rel')){
var params=tooltip.attr('rel').split('|');
for (var i=0; i < params.length; i++){
var param=params[i];
if(param.indexOf('time=')!=-1)
tooltip.fxDuration=parseInt(param.replace("time=", ""));
if(param.indexOf('delayOut=')!=-1)
tooltip.delayOut=parseInt(param.replace("delayOut=", ""));
if(param.indexOf('offsetx=')!=-1)
tooltip.offsetx=parseInt(param.replace("offsetx=", ""));
if(param.indexOf('offsety=')!=-1)
tooltip.offsety=parseInt(param.replace("offsety=", ""));
if(param.indexOf('position=')!=-1)
tooltip.tipPosition=param.replace("position=", "");
if(param.indexOf('mood=')!=-1)
tooltip.fxDuration=param.replace("mood=", "");
if(param.indexOf('tipd=')!=-1)
tooltip.delayOut=param.replace("tipd=", "");
}}
}
$(window).on('resize', function(){ repositionTooltip(tooltip); });
function repositionTooltip(tooltip){
if(tooltip.data('status')!='open'||options.isMobile!='1') return;
tooltip.tipPosition=options.tipPosition;
var tipPositionCss=getTipPosition();
var tip=tooltip.tip;
tip.css(tipPositionCss[0], tipPositionCss[1]);
tip.css(tipPositionCss[2], tipPositionCss[3]);
tip.css(tipPositionCss[4], tipPositionCss[5]);
tip.css(tipPositionCss[6], tipPositionCss[7]);
}});
};
window.Tooltipck=Tooltipck;
})();