var edd_scripts;
jQuery(document).ready(function($){
$('.edd_subscription_cancel').on('click',function(e){
if(confirm(edd_recurring_vars.confirm_cancel) ){
return true;
}
return false;
});
$('.edd_download_purchase_form').each(function(){
var form=$(this);
if(form.find('.edd-cp-container').length&&form.find('.edd_price_options').length){
var terms=form.find('.eddr-custom-terms-notice');
var signup_fee=form.find('.eddr-custom-signup-fee-notice');
terms.prev().append(terms);
signup_fee.prev().append(signup_fee);
terms.show();
signup_fee.show();
}else if(form.find('.edd-cp-container').length){
form.find('.edd_cp_price').keyup(function(){
form.find('.eddr-terms-notice,.eddr-signup-fee-notice').hide();
form.find('.eddr-custom-terms-notice,.eddr-custom-signup-fee-notice').show();
});
}});
$('#edd_purchase_form').on('focusout', '#edd-email', function(){
if('undefined'==edd_scripts){
return;
}
if(! edd_recurring_vars.has_trial){
return;
}
var email=$(this).val();
var product_ids=[];
$('body').find('.edd_cart_item').each(function(){
product_ids.push($(this).data('download-id') );
});
$.ajax({
type: "POST",
data: {
action: 'edd_recurring_check_repeat_trial',
email: email,
downloads: product_ids
},
dataType: "json",
url: edd_scripts.ajaxurl,
xhrFields: {
withCredentials: true
},
success: function (response){
if(response.message){
$('<div class="edd_errors"><p class="edd_error">' + response.message + '</p></div>').insertBefore('#edd_purchase_submit');
}}
}).fail(function (response){
if(window.console&&window.console.log){
console.log(response);
}}).done(function (response){
});
});
$(document.body).on('edd_discount_applied', updateNotices);
$(document.body).on('edd_discount_removed', updateNotices);
function updateNotices(e, data){
let trial=$('.edd_recurring_total_after_trial');
if(trial.length&&data.recurring_total){
trial.text(data.recurring_total);
}
if(data.recurring_sl){
for(var key in data.recurring_sl){
if(data.recurring_sl.hasOwnProperty(key) ){
let amount=$('.' + key);
if(amount.length){
amount.text(data.recurring_sl[ key ]);
}}
}}
}
$(document.body).on('edd_taxes_recalculated', function(e, response){
if(!edd_recurring_vars.has_trial){
return;
}
let selector=$('.edd_recurring_trial_total_note');
if(selector&&$('.edd_recurring_total_after_trial').length){
selector.text(edd_recurring_vars.trial_message);
}});
if(edd_recurring_vars.has_trial){
setTrialTotal();
$(document.body).on('edd_discount_applied', setTrialTotal);
$(document.body).on('edd_discount_removed', setTrialTotal);
$(document.body).on('edd_taxes_recalculated', setTrialTotal);
}
function setTrialTotal(e, data){
$('.edd_cart_amount').html(edd_recurring_vars.total);
if('undefined'!==typeof data&&data.response&&data.response.total){
$('body').find('.edd_recurring_total_after_trial').each(function (){
$(this).html(data.response.total);
});
}}
});