JezK
Edit File: js_subscriptions.min.js
var tdSubscriptions={}; (function(c,h){tdSubscriptions={init:function(){if(window.tdsVue&&"undefined"!==typeof window.tdsVue.router&&(new SubscriptionVue,jQuery("#tds-settings").length)){SubscriptionVue.use(Vuex);var k=new Vuex.Store({state:{globalCurrHasPayPalPayment:"",globalCurrHasPayPalDecimal:"",globalPayPalStatus:"",globalCurrPayPalDecPlansFail:0,globalCurrHasStripePayment:"",globalCurrHasStripeDecimal:"",globalStripeStatus:"",globalCurrStripeDecPlansFail:0,globalFormatDate:"",globalCustomFormatDate:"",globalPlans:!1}, mutations:{setGlobalCurrHasPayPalPayment:function(a,b){a.globalCurrHasPayPalPayment=b;a.globalCurrPayPalDecPlansFail=0;a.globalPayPalStatus&&a.globalCurrHasPayPalPayment&&(a.globalCurrHasPayPalDecimal||!1===a.globalPlans||a.globalPlans.forEach(function(d){0===parseInt(d.is_free,10)&&-1!==d.price.indexOf(".")&&a.globalCurrPayPalDecPlansFail++}))},setGlobalCurrHasPayPalDecimal:function(a,b){a.globalCurrHasPayPalDecimal=b;a.globalCurrPayPalDecPlansFail=0;a.globalPayPalStatus&&a.globalCurrHasPayPalPayment&& (a.globalCurrHasPayPalDecimal||!1===a.globalPlans||a.globalPlans.forEach(function(d){0===parseInt(d.is_free,10)&&-1!==d.price.indexOf(".")&&a.globalCurrPayPalDecPlansFail++}))},setGlobalPayPalStatus:function(a,b){a.globalPayPalStatus=b;a.globalCurrPayPalDecPlansFail=0;a.globalPayPalStatus&&a.globalCurrHasPayPalPayment&&(a.globalCurrHasPayPalDecimal||!1===a.globalPlans||a.globalPlans.forEach(function(d){0===parseInt(d.is_free,10)&&-1!==d.price.indexOf(".")&&a.globalCurrPayPalDecPlansFail++}))},setGlobalCurrPayPalDecPlansFail:function(a, b){a.globalCurrPayPalDecPlansFail=b},setGlobalCurrHasStripePayment:function(a,b){a.globalCurrHasStripePayment=b;a.globalCurrStripeDecPlansFail=0;a.globalStripeStatus&&a.globalCurrHasStripePayment&&(a.globalCurrHasStripeDecimal||!1===a.globalPlans||a.globalPlans.forEach(function(d){0===parseInt(d.is_free,10)&&-1!==d.price.indexOf(".")&&a.globalCurrStripeDecPlansFail++}))},setGlobalCurrHasStripeDecimal:function(a,b){a.globalCurrHasStripeDecimal=b;a.globalCurrStripeDecPlansFail=0;a.globalStripeStatus&& a.globalCurrHasStripePayment&&(a.globalCurrHasStripeDecimal||!1===a.globalPlans||a.globalPlans.forEach(function(d){0===parseInt(d.is_free,10)&&-1!==d.price.indexOf(".")&&a.globalCurrStripeDecPlansFail++}))},setGlobalStripeStatus:function(a,b){a.globalStripeStatus=b;a.globalCurrStripeDecPlansFail=0;a.globalStripeStatus&&a.globalCurrHasStripePayment&&(a.globalCurrHasStripeDecimal||!1===a.globalPlans||a.globalPlans.forEach(function(d){0===parseInt(d.is_free,10)&&-1!==d.price.indexOf(".")&&a.globalCurrStripeDecPlansFail++}))}, setGlobalCurrStripeDecPlansFail:function(a,b){a.globalCurrStripeDecPlansFail=b},setGlobalFormatDate:function(a,b){a.globalFormatDate=b},setGlobalCustomFormatDate:function(a,b){a.globalCustomFormatDate=b},setGlobalPlans:function(a,b){a.globalPlans=b;a.globalCurrPayPalDecPlansFail=0;a.globalPayPalStatus&&a.globalCurrHasPayPalPayment&&!a.globalCurrHasPayPalDecimal&&!1!==a.globalPlans&&a.globalPlans.forEach(function(d){0===parseInt(d.is_free,10)&&-1!==d.price.indexOf(".")&&a.globalCurrPayPalDecPlansFail++}); a.globalCurrStripeDecPlansFail=0;a.globalStripeStatus&&a.globalCurrHasStripePayment&&!a.globalCurrHasStripeDecimal&&!1!==a.globalPlans&&a.globalPlans.forEach(function(d){0===parseInt(d.is_free,10)&&-1!==d.price.indexOf(".")&&a.globalCurrStripeDecPlansFail++})}}});new SubscriptionVue({el:"#tds-settings",router:window.tdsVue.router,store:k})}window.tdtVue&&"undefined"!==typeof window.tdtVue.router&&jQuery("#tdt-settings").length&&new SubscriptionVue({el:"#tdt-settings",router:window.tdtVue.router}); jQuery(document).on("click",".tds-save-settings",function(a){a.preventDefault();var b=c(".tds-paypal-settings");a=b.find(".tds-paypal-client-id:first");b=b.find(".tds-paypal-key:first");a=a.val().trim();b=b.val().trim();var d=c(".tds-check-results:first");c.ajax({timeout:1E4,type:"POST",url:tdSubscriptions.get_rest_endpoint("tds_subscription/save_settings","uuid="+tdSubscriptions.get_unique_id()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",window.tds_js_globals.wpRestNonce)},cache:!0,data:{clientId:a, key:b},dataType:"json",success:function(a,g,d){console.log(a);window.location.reload()},error:function(a,g,b){console.log("tds save settings - Error callback - textStatus: "+g+" errorThrown: "+b);"undefined"!==typeof XMLHttpRequest.responseText&&d.html(XMLHttpRequest.responseText)}})}).on("click",".tds-synchronize-products",function(a){a.preventDefault();a=c(".tds-paypal-settings");var b=a.find(".tds-paypal-token:first"),d=a.find(".tds-settings-results:first"),e=c(".tds-check-results:first");d.html(""); c.ajax({timeout:1E4,type:"POST",url:tdSubscriptions.get_rest_endpoint("tds_subscription/paypal_synchronize_products","uuid="+tdSubscriptions.get_unique_id()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",window.tds_js_globals.wpRestNonce)},cache:!0,dataType:"json",success:function(a,c,f){console.log(a);"undefined"!==typeof a.error?b.val(a.error):"undefined"!==typeof a.response&&d.html(a.response)},error:function(a,d,b){console.log("tds save settings - Error callback - textStatus: "+d+" errorThrown: "+ b);"undefined"!==typeof XMLHttpRequest.responseText&&e.html(XMLHttpRequest.responseText)}})}).on("click",".tds-synchronize-plans",function(a){a.preventDefault();c(this);a=c(".tds-paypal-settings");var b=a.find(".tds-paypal-token:first"),d=a.find(".tds-settings-results:first"),e=c(".tds-check-results:first");d.html("");c.ajax({timeout:1E4,type:"POST",url:tdSubscriptions.get_rest_endpoint("tds_subscription/paypal_synchronize_plans","uuid="+tdSubscriptions.get_unique_id()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce", window.tds_js_globals.wpRestNonce)},cache:!0,dataType:"json",success:function(a,c,e){console.log(a);"undefined"!==typeof a.error?b.val(a.error):"undefined"!==typeof a.response&&d.html(a.response)},error:function(a,d,b){console.log("tds save settings - Error callback - textStatus: "+d+" errorThrown: "+b);"undefined"!==typeof XMLHttpRequest.responseText&&e.html(XMLHttpRequest.responseText)}})}).on("click",".tds-check-plan",function(a){a.preventDefault();a=c(this);var b=c("#post_ID").val(),d=c(".tds-check-results:first"), e=a.parent().find(".spinner:first");e.addClass("is-active");d.html("");c.ajax({timeout:1E4,type:"POST",url:tdSubscriptions.get_rest_endpoint("tds_subscription/paypal_check_plan","uuid="+tdSubscriptions.get_unique_id()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",window.tds_js_globals.wpRestNonce)},cache:!0,dataType:"json",data:{planId:b},success:function(a,b,f){e.removeClass("is-active");console.log(a);"undefined"!==typeof a.error?d.val(a.error):"undefined"!==typeof a.response&&(d.html(a.response), a=JSON.parse(a.response),f=b="UNKNOWN","undefined"!==typeof a.status&&(b=a.status),"undefined"!==typeof a.product_id&&(f=a.product_id.replace("TDS-","")),c(".tds-label-check-status").html(b),c(".tds-label-check-product").html(f))},error:function(a,b,c){console.log("tds save settings - Error callback - textStatus: "+b+" errorThrown: "+c);"undefined"!==typeof XMLHttpRequest.responseText&&d.html(XMLHttpRequest.responseText)}})}).on("click",".tds-check-subscription",function(a){a.preventDefault();a=c(this); var b=c("#post_ID").val(),d=c(".tds-check-results:first"),e=a.parent().find(".spinner:first");e.addClass("is-active");d.html("");c.ajax({timeout:1E4,type:"POST",url:tdSubscriptions.get_rest_endpoint("tds_subscription/payment_check_subscription","uuid="+tdSubscriptions.get_unique_id()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",window.tds_js_globals.wpRestNonce)},cache:!0,dataType:"json",data:{localSubscriptionId:b},success:function(a,b,f){console.log(a);e.removeClass("is-active");"undefined"!== typeof a.error?d.val(a.error):"undefined"!==typeof a.response&&(d.html(a.response),a=JSON.parse(a.response),f=b="UNKNOWN","undefined"!==typeof a.status&&(b=a.status),"undefined"!==typeof a.plan_id&&(f=a.plan_id),c(".tds-label-check-status").html(b),c(".tds-label-check-plan").html(f))},error:function(a,b,c){console.log("tds save settings - Error callback - textStatus: "+b+" errorThrown: "+c);"undefined"!==typeof XMLHttpRequest.responseText&&d.html(XMLHttpRequest.responseText)}})}).on("click",".tds-check-product", function(a){a.preventDefault();a=c(this);var b=c("#post_ID").val(),d=c(".tds-check-results:first"),e=a.parent().find(".spinner:first");e.addClass("is-active");d.html("");c.ajax({timeout:1E4,type:"POST",url:tdSubscriptions.get_rest_endpoint("tds_subscription/paypal_check_product","uuid="+tdSubscriptions.get_unique_id()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",window.tds_js_globals.wpRestNonce)},cache:!0,dataType:"json",data:{productId:b},success:function(a,b,f){console.log(a);e.removeClass("is-active"); "undefined"!==typeof a.error?d.val(a.error):"undefined"!==typeof a.response&&(d.html(a.response),a=JSON.parse(a.response),b="UNKNOWN","undefined"!==typeof a.type&&(b=a.type),c(".tds-label-check-type").html(b))},error:function(a,b,c){console.log("tds save settings - Error callback - textStatus: "+b+" errorThrown: "+c);"undefined"!==typeof XMLHttpRequest.responseText&&d.html(XMLHttpRequest.responseText)}})}).on("click",".tds-sync-product",function(a){a.preventDefault();var b=c(this);a=c("#post_ID").val(); var d=c(".tds-check-results:first"),e=c('input[name="td_post_theme_settings[tds_payment_product_id]"]'),g=b.parent().find(".spinner:first");b="paypal_create_product";g.addClass("is-active");d.html("");e.length&&(b="paypal_sync_product");c.ajax({timeout:1E4,type:"POST",url:tdSubscriptions.get_rest_endpoint("tds_subscription/"+b,"uuid="+tdSubscriptions.get_unique_id()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",window.tds_js_globals.wpRestNonce)},cache:!0,dataType:"json",data:{productId:a}, success:function(a,b,d){console.log(a);g.removeClass("is-active");window.location.reload()},error:function(a,b,c){console.log("tds save settings - Error callback - textStatus: "+b+" errorThrown: "+c);"undefined"!==typeof XMLHttpRequest.responseText&&d.html(XMLHttpRequest.responseText)}})}).on("click",".tds-sync-plan",function(a){a.preventDefault();var b=c(this);a=c("#post_ID").val();var d=c(".tds-check-results:first"),e=c('input[name="td_post_theme_settings[tds_payment_plan_id]"]'),g=b.parent().find(".spinner:first"); b="paypal_create_plan";g.addClass("is-active");d.html("");e.length&&(b="paypal_sync_plan");c.ajax({timeout:1E4,type:"POST",url:tdSubscriptions.get_rest_endpoint("tds_subscription/"+b,"uuid="+tdSubscriptions.get_unique_id()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",window.tds_js_globals.wpRestNonce)},cache:!0,dataType:"json",data:{planId:a},success:function(a,b,c){console.log(a);"undefined"!==typeof a.error?d.val(a.error):"undefined"!==typeof a.response&&d.html(a.response);g.removeClass("is-active")}, error:function(a,b,c){console.log("tds save settings - Error callback - textStatus: "+b+" errorThrown: "+c);"undefined"!==typeof XMLHttpRequest.responseText&&d.html(XMLHttpRequest.responseText)}})}).on("click",".tds-sync-subscription",function(a){a.preventDefault();a=c(this);var b=c("#post_ID").val(),d=c(".tds-check-results:first"),e=a.parent().find(".spinner:first");e.addClass("is-active");d.html("");c.ajax({timeout:1E4,type:"POST",url:tdSubscriptions.get_rest_endpoint("tds_subscription/payment_sync_subscription", "uuid="+tdSubscriptions.get_unique_id()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",window.tds_js_globals.wpRestNonce)},cache:!0,dataType:"json",data:{localSubscriptionId:b},success:function(a,b,d){e.removeClass("is-active");console.log(a);window.location.reload()},error:function(a,b,c){console.log("tds save settings - Error callback - textStatus: "+b+" errorThrown: "+c);"undefined"!==typeof a.responseText&&d.html(a.responseText)}})}).on("change","#tds-locker-type",function(){var a=jQuery(this), b=jQuery(".td-op-meta-box-row-cf .td-meta-box-col-title, .td-meta-box-col-title-cf"),d=jQuery(".tds-paid-subscription-settings");"#tds-input-placeholder #tds-locker-cf-1-state #tds-locker-cf-1-req #tds-locker-cf-1-name #tds-locker-cf-2-state #tds-locker-cf-2-req #tds-locker-cf-2-name #tds-locker-cf-3-state #tds-locker-cf-3-req #tds-locker-cf-3-name #tds-input-color #tds-input-color-h #tds-input-bg-color #tds-input-bg-color-h #tds-input-border-color #tds-input-border-color-h #tds-tds_input-font_size #tds-access-settings".split(" ").forEach(function(c){c= jQuery(c);if(c.length&&(c=c.closest(".td-meta-box-row"),c.length))switch(a.val()){case "paid_subscription":d.removeClass("td-op-disabled");c.addClass("td-op-disabled");b.addClass("td-op-disabled");break;default:d.addClass("td-op-disabled"),c.removeClass("td-op-disabled"),b.removeClass("td-op-disabled")}})}).on("change","#tds-locker-credits-unlock",function(){var a=jQuery(this),b=jQuery(".td-meta-box-col-title-cl");"#tds-locker-credits-title #tds-locker-credits-message #tds-locker-credits-btn-text #tds-locker-credits-redr-url #tds-locker-credits-enable #tds-locker-credits-sep-text #tds-tds_lc_sep-font_size".split(" ").forEach(function(d){d= jQuery(d);d.length&&(d=d.closest(".td-meta-box-row"),d.length&&(a.is(":checked")?(d.removeClass("td-op-disabled"),b.removeClass("td-op-disabled")):(d.addClass("td-op-disabled"),b.addClass("td-op-disabled"))))})});jQuery("#tds-locker-type").trigger("change")},get_rest_endpoint:function(c,a){return h.isEmpty(window.tds_js_globals.permalinkStructure)?window.tds_js_globals.wpRestUrl+c+"&"+a:window.tds_js_globals.wpRestUrl+c+"?"+a},get_unique_id:function(){function c(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)} return c()+c()+"-"+c()+"-"+c()+"-"+c()+"-"+c()+c()+c()}};tdSubscriptions.init()})(jQuery,_);