'
var upcomingOrderProductTitle = '
' + contractItem?.node?.title + (contractItem?.node?.variantTitle ? (' - ' + contractItem?.node?.variantTitle): '') + (contractItem?.node?.quantity > 1 ? 'X' + contractItem?.node?.quantity + '' : '') + '
'
jQuery('#orderImage_' + orderItem.idsplit("/").pop()).append(upcomingOrderImage);
jQuery('#orderTitle_' + orderItem.idsplit("/").pop()).append(upcomingOrderProductTitle);
if (contractItem.node?.variantTitle == null) {
jQuery('.appstle_variantTitle_' + contractItem.node?.productIdsplit('/')[4]).hide();
}
});
})
}
// Upcoming Order API CALL HERE
if (subItem.node?.status == "ACTIVE" && !isPrepaidplan) {
var upcomingOrderUrl;
if (customerId != null) {
upcomingOrderUrl = "https://subscription-admin.appstlecom/api/subscription-billing-attempts/top-orders?contractId=" + contractId + "&customerId=" + customerId + "&shop=" + shopName
}
else {
upcomingOrderUrl = "https://subscription-admin.appstlecom/api/subscription-billing-attempts/top-orders?contractId=" + contractId + "&customerUid=" + token + "&shop=" + shopName
}
jQuery.ajax({
type: "GET",
url: upcomingOrderUrl,
dataType: "json",
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (result, status, xhr) {
if (result?.length > 0) {
result.map((orderItem) => {
var upcomingOrder =
'
'
var upcomingOrderOld = '
'
jQuery('#orderAcc_' + subItem.node.node.idsplit('/')[4]).append(upcomingOrder);
subItem.node.node.lines?.edges?.forEach(contractItem => {
if (contractItem.node?.productId != null) {
var upcomingOrderImage = '
'
var upcomingOrderProductTitle = '
' + contractItem?.node?.title + (contractItem?.node?.variantTitle ? (' - ' + contractItem?.node?.variantTitle): '') + (contractItem?.node?.quantity > 1 ? 'X' + contractItem?.node?.quantity + '' : '') + '
'
jQuery('#orderImage_' + orderItem?.id).append(upcomingOrderImage);
jQuery('#orderTitle_' + orderItem?.id).append(upcomingOrderProductTitle);
if (contractItem.node.node.variantTitle == null) {
jQuery('.appstle_variantTitle_' + contractItem.node?.productId?.split('/')[4]).hide();
}
}
else {
var upcomingOrderImage =
'
'
+ '
'
+ '' + contractItem.node?.title + 'has been removed'
+ '
'
+ '
'
jQuery('#orderImage_' + orderItem.id).append(upcomingOrderImage)
}
});
})
}
},
error: function (xhr, status, error) {
console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
}
})
}
}
},
error: function (xhr, status, error) {
console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
}
});
});
jQuery(".appstle_preloader").fadeOut(2000, function () {
jQuery(".appstle_myProduct").fadeIn(1000);
jQuery(".appstle_myProduct").css('visibility', 'visible');
if (getDeviceType() !== "mobile") {
jQuery('.appttle_single_item_contract').each(function(index, el) {
var contractId = jQuery(el).attr('data-contract-id');
var imageHeight = jQuery('.appstle_subscription_contract_content_wrapper_' + contractId).height();
jQuery('.apptle_subscription_contract_image_wrapper_' + contractId).parent().css('height', imageHeight);})
}
});
}
else {
jQuery(".appstle_preloader").fadeOut(2000, function () {
jQuery(".appstle_myProduct").append("
" + noSubscriptionMessage + "
").fadeIn(1000);
jQuery(".appstle_myProduct").css('visibility', 'visible');
});
}
attachListener();
}
function skipBillingOrder(id) {
if (id != null && id != undefined) {
jQuery('.appstle_skiporder_' + id).html('Processing.')
jQuery.ajax({
type: "PUT",
url: "https://subscription-admin.appstlecom/api/subscription-billing-attempts/skip-order/" + id + "?shop=" + Shopify.shop,
dataType: "json",
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (result, status, xhr) {
window.rental.reload();
},
error: function (xhr, status, error) {
console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
}
});
} else {
alert("Order Id is not Found")
}
}
function updatePaymentDetails(id) {
if (id != null && id != undefined) {
jQuery('.apptle_paymentBtnUpdate_' + id).html('Processing.');
jQuery.ajax({
type: "PUT",
url: "https://subscription-admin.appstlecom/api/subscription-contracts-update-payment-method?contractId=" + id + "&shop=" + Shopify.shop,
dataType: "json",
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (result, status, xhr) {
jQuery(".apptle_paymentSuccessMessage_" + id).show();
jQuery('.apptle_paymentBtnUpdate_' + id).html(successText);
setTimeout(function() {jQuery('.appstle_paymentBtnUpdate_' + id).html(updatePaymentBtnText);},5000)
},
error: function (xhr, status, error) {
console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
jQuery(".apptle_paymentSuccessMessage_" + id).show();
jQuery('.apptle_paymentBtnUpdate_' + id).html(successText);
setTimeout(function() {jQuery('.appstle_paymentBtnUpdate_' + id).html(updatePaymentBtnText);},5000)
},
});
}
else {
alert("Contract Id is not Found")
}
}
function cancelSubscription(id) {
if (id != null && id != undefined) {
jQuery('.apptle_cancelBtnText_' + id).html('Processing.')
jQuery.ajax({
type: "DELETE",
url: "https://subscription-admin.appstlecom/api/subscription-contracts/" + id + "?shop=" + Shopify.shop,
dataType: "json",
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (result, status, xhr) {
subscriptionInit();
},
error: function (xhr, status, error) {
console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
}
});
} else {
alert("Product Id is not Found")
}
}
function showFrequencyForm(contractId) {
// jQuery("#orderFrequencyform_" + contractId).show();
jQuery(".apptle_orderFrequencyformDiv_" + contractId).slideDown();
jQuery('.editBtnFrequency_' + contractId).hide();
}
function showChangeOrderDateForm(contractId){
// jQuery("#orderDateform_" + contractId).show();
jQuery(".appstle_orderDateformDiv_" + contractId).slideDown();
jQuery('.editBtnOrderDate_' + contractId).hide();
}
function hideOrderDateForm(contractId){
// jQuery("#orderDateform_" + contractId).hide();
jQuery(".appstle_orderDateformDiv_" + contractId).slideUp();
jQuery('.editBtnOrderDate_' + contractId).show();
}
function hideFrequencyForm(contractId) {
jQuery(".apptle_orderFrequencyformDiv_" + contractId).slideUp();
// jQuery("#orderFrequencyform_" + contractId).hide();
jQuery('.editBtnFrequency_' + contractId).show();
}
function updateOrderDate(contractId) {
var nextBillingDate = document.forms["orderDateform_" + contractId].changeOrderDatevalue;
if (nextBillingDate != null && nextBillingDate != undefined) {
// jQuery("#orderDateform_" + contractId).hide();
jQuery(".appstle_orderDateformDiv_" + contractId).slideUp();
jQuery("#orderDateloadingText_" + contractId).show();
jQuery.ajax({
type: "PUT",
url: "https://subscription-admin.appstlecom/api/subscription-contracts-update-billing-date?contractId=" + contractId + "&nextBillingDate=" + new Date(nextBillingDate).toISOString() + "&shop=" + Shopify.shop,
dataType: "json",
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (result, status, xhr) {
subscriptionInit()
},
error: function (xhr, status, error) {
console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
}
});
// jQuery("#orderloadingText_"+contractId).hide();
} else {
alert("Please Provide Frequency Count or Frequency Interval")
}
}
function updateFrequency(contractId) {
var frequencyCount = document.forms["orderFrequencyform_" + contractId]?.frequencyCount?.value;
var frequencyInterval = document.forms["orderFrequencyform_" + contractId]?.frequency Interval?.value;
if (frequencyCount <= 0)
alert("Frequency Count must be greater than 1")
if (frequencyCount != null && frequencyCount != undefined && frequencyCount >= 0 && frequencyInterval != null && frequencyInterval != undefined) {
// jQuery("#orderFrequencyform_" + contractId).hide();
jQuery(".apptle_orderFrequencyformDiv_" + contractId).slideUp();
jQuery("#orderloadingText_" + contractId).show();
jQuery.ajax({
type: "PUT",
url: "https://subscription-admin.appstlecom/api/subscription-contracts-update-billing-interval?contractId=" + contractId + "&interval=" + frequencyInterval + "&intervalCount=" + frequencyCount + "&shop=" + Shopify.shop,
dataType: "json",
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (result, status, xhr) {
subscriptionInit();
},
error: function (xhr, status, error) {
console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
}
});
// jQuery("#orderloadingText_"+contractId).hide();
} else {
alert("Please Provide Frequency Count or Frequency Interval")
}
}
function attachListener() {
jQuery('.appstle_product-search-button').on('click', function() {
var contractId = jQuery(this).attr('data-contract-id');
var selectedProduct = jQuery('select[data-contract-id=' + contractId + ']');
if (!selectedProduct.val()) {
alert('Please Select a product to add.')
return;
}
jQuery(".appstle_myProduct").fadeOut(500, function () {
jQuery(".appstle_preloader").fadeIn(250);
});
var addLine_settings = {
"async": true,
"crossDomain": true,
"url": 'https://subscription-admin.appstlecom/api/subscription-contracts-add-line-item?contractId=' + contractId + '&price=' + selectedProduct.attr('data-variant-price') + '&quantity=1&shop=' + shopName + '&variantId=' + selectedProduct.attr('data-variant-id'),
"method": "PUT",
"headers": {
"cache-control": "no-cache",
}
}
jQuery.ajax(addLine_settings).done(function (response) {
subscriptionInit();
})
})
jQuery('.appstle_select_wrapper select').on('change', function() {
var currentValue= jQuery(this).val();
var selectedVariantPrice = jQuery(this).find('option[value="' + currentValue + '"]').attr('data-variant-price');
var formid = jQuery(this).attr('data-edit');
jQuery('#' + formid).attr('data-price', selectedVariantPrice);
})
jQuery('.appttle_editButton').on('click', function() {
var formid = jQuery(this).attr('data-edit');
jQuery('#' + formid).find('appstle_edit_wrapper').slideDown();
jQuery('#' + formid).find('appstle_editDeleteGroup').hide();
jQuery('#' + formid).find('appstle_buttonGroup').show();
})
jQuery('.apptle_cancelButton').on('click', function() {
var formid = jQuery(this).attr('data-edit');
jQuery('#' + formid).find('appstle_edit_wrapper').slideUp();
jQuery('#' + formid).find('appstle_editDeleteGroup').show();
jQuery('#' + formid).find('appstle_buttonGroup').hide();
})
jQuery('.apptle_deleteButton').on('click', function() {
var formid = jQuery(this).attr('data-edit');
var lineId = jQuery('#' + formid).attr('data-line-id');
let prepaidPlanFlag = jQuery('#' + formid).attr('data-isPrepaid');
var contractId = jQuery('#' + formid).attr('data-contract-id');
var shop = jQuery('#' + formid).attr('data-shop'); delete Popup Confirm(prepaidPlanFlag); // Showing Delete confirm Modal // On click of confirm Code will execute jQuery('.appstle_delete_model_yesbtn').on('click', function() {
hideDeleteConfirmPopup(); // Hide the Confirm Model
jQuery(".appstle_myProduct").fadeOut(500, function () {
jQuery(".appstle_preloader").fadeIn(250);
});
var settings = {
"async": true,
"crossDomain": true,
"url": 'https://subscription-admin.appstlecom/api/subscription-contracts-remove-line-item?contractId=' + contractId + '&lineId=' + lineId + '&shop=' + shop,
"method": "PUT",
"headers": {
"cache-control": "no-cache",
"postman-token": "06eaf057-9152-2ff9-616b-c8f3f319e47f"
}
}
jQuery.ajax(settings).done(function (response) {
subscriptionInit();
});
})
})
jQuery('.appttle_updateButton').on('click', function() {
var formid = jQuery(this).attr('data-edit');
var lineId = jQuery('#' + formid).attr('data-line-id');
var contractId = jQuery('#' + formid).attr('data-contract-id');
var shop = jQuery('#' + formid).attr('data-shop');
var price = jQuery('#' + formid).attr('data-price');
var formData = jQuery('#' + formid + ' form').serialize();
var inputElementValue = jQuery('#' + formid).find('input')[0].value;
if (validateNumber(inputElementValue)) {
jQuery(".appstle_myProduct").fadeOut(500, function () {
jQuery(".appstle_preloader").fadeIn(250);
});
jQuery('#' + formid).find('appttle_input_error').hide();
var settings = {
"async": true,
"crossDomain": true,
"url": 'https://subscription-admin.appstlecom/api/subscription-contracts-update-line-item?contractId=' + contractId + '&price=' + price + '&lineId=' + lineId + '&shop=' + shop + '&' + formData,
"method": "PUT",
"headers": {
"cache-control": "no-cache",
"postman-token": "06eaf057-9152-2ff9-616b-c8f3f319e47f"
}
}
jQuery.ajax(settings).done(function (response) {
subscriptionInit();
});
} else {
jQuery('#' + formid).find('appttle_input_error').show();
}
});
addVariant();
addSelect2InHead();
addIconCssInHead();
}
function addVariant() {
var elementsWithProductId = Array.prototype.slicecall(jQuery('[data-product-id]'))
const addVariantItem = async () => {
if (elementsWithProductId.length > 0) {
var item = elementsWithProductId.shift();
var settings = {
"async": true,
"crossDomain": true,
"url": 'https://subscription-admin.appstlecom/api/data/product?productId=' + jQuery(item).attr('data-product-id') + '&shop=' + shopName,
"method": "GET",
"headers": {
"cache-control": "no-cache",
"postman-token": "06eaf057-9152-2ff9-616b-c8f3f319e47f"
}
}
jQuery.ajax(settings).done(function (response) {
var variants = response?.variants;
jQuery(variants).each(function (index, variant) {
var option = jQuery('
', {
value: variant.admin_graphql_api_id,
text: variant.title,
selected: ((variant?.admin_graphql_api_id == jQuery(item).attr("data-variant-id")) ? true: false),
})
option.attr('data-variant-price', variant.price);
option.appendTo(jQuery(item).find('select'));
});
if (variants.length <= 1) {
jQuery(item).find('appstle_select_wrapper').hide();
}
addVariantItem();
});
}
}
addVariantItem();
}
function addLineItem(items, contractId) {
var selectedItems = items;
jQuery(".appstle_myProduct").fadeOut(500, function () {
jQuery(".appstle_preloader").fadeIn(250);
});
var addline = function() {
if (selectedItems.length > 0) {
var item = selectedItems.shift();
var settings = {
"async": true,
"crossDomain": true,
"url": 'https://subscription-admin.appstlecom/api/data/product?productId=' + item + '&shop=' + shopName,
"method": "GET",
"headers": {
"cache-control": "no-cache",
}
}
jQuery.ajax(settings).done(function (response) {
var firstVariant = response?.variants[0]
var addLine_settings = {
"async": true,
"crossDomain": true,
"url": 'https://subscription-admin.appstlecom/api/subscription-contracts-add-line-item?contractId=' + contractId + '&price=' + firstVariant?.price + '&quantity=1&shop=' + shopName + '&variantId=' + firstVariant?.admin_graphql_api_id,
"method": "PUT",
"headers": {
"cache-control": "no-cache",
}
}
jQuery.ajax(addLine_settings).done(function (response) {
addline();
})
});
} else {
subscriptionInit();
}
}
addline();
}
function validateNumber(value) {
var type = typeof value;
if (type === 'undefined') {
return true;
} else if (!value.trim()) {
return false;
} else if (isNaN(value)) {
return false;
} else if (parseInt(value) < 1) {
return false;
} else {
return true;
}
};
function addSelect2InHead() {
jQuery('head').append('