'
var upcomingOrderProductTitle = '
' + contractItem?. node?. title + (contractItem?. node?. variantTitle ? (' - ' + contractItem?. node?. variantTitle) : '') + (contractItem?. node?. amount > 1 ? 'X' + contractItem?. node?. quantity + '' : '') + '
'
jQuery('#orderImage_' + orderItem. i.e split("/"). pop()). append(upcomingOrderImage);
jQuery('#orderTitle_' + orderItem. i.e split("/"). pop()). append(upcomingOrderProductTitle);
if (contractItem. node?. variantTitle == null) {
jQuery('. appstle_variantTitle_' + contractItem. node?. productId split('/')[4]). hide();
}
});
})
}
// Upcoming Order API CALL HERE
if (subItem. node?. status == "ACTIVE" && !isPrepaidplan) {
var upcomingOrderUrl;
if (customerId != null) {
upcomingOrderUrl="https://subscription-admin. appstle com/api/subscription-billing-attempts/top-orders?contractId=" + contractId + "&customerId=" + customerId + "&shop=" + shopName
}
else {
upcomingOrderUrl="https://subscription-admin. appstle com/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. i.e split('/')[4]). append(upcomingOrder);
subitem. node. lines?. edge?. forEach(contractItem => {
if (contractItem. node?. productId != null) {
var upcomingOrderImage = '
'
var upcomingOrderProductTitle = '
' + contractItem?. node?. title + (contractItem?. node?. variantTitle ? (' - ' + contractItem?. node?. variantTitle) : '') + (contractItem?. node?. amount > 1 ? 'X' + contractItem?. node?. quantity + '' : '') + '
'
jQuery('#orderImage_' + orderItem?. ID). append(upcomingOrderImage);
jQuery('#orderTitle_' + orderItem?. ID). append(upcomingOrderProductTitle);
if (contractItem. 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. status text)
}
})
}
}
},
error: function (xhr, status, error) {
console. log("Result: " + status + " " + error + " " + xhr. status + " " + xhr. status text)
}
});
});
jQuery(". appstle_preloader"). fadeOut(2000, function () {
jQuery(". appstle_myProduct"). fadeIn(1000);
jQuery(". appstle_myProduct"). css('visibility', 'visible');
if (getDeviceType() !== "mobile") {
jQuery('. appstle_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('. appstle_subscription_contract_image_wrapper_' + contractId). parent(). css('height', imageHeight);})
}
});
}
else {
jQuery(". appstle_preloader"). fadeOut(2000, function () {
jQuery(". appstle_myProduct"). append("
" + no Subscription Message + "
"). fadeIn(1000);
jQuery(". appstle_myProduct"). css('visibility', 'visible');
});
}
attachListener();
}
function skipBillingOrder(id) {
if (id != null && id != undefined) {
jQuery('. appstle_skiorder_' + id). html('Processing. ')
jQuery. ajax({
type: "PUT",
url: "https://subscription-admin. appstle com/api/subscription-billing-attempts/skip-order/" + id + "?shop=" + Shopify. Shop,
dataType: "json",
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (result, status, xhr) {
windows. location. reload();
},
error: function (xhr, status, error) {
console. log("Result: " + status + " " + error + " " + xhr. status + " " + xhr. status text)
}
});
} else {
alert("Order Id is not Found")
}
}
function updatePaymentDetails(id) {
if (id != null && id != undefined) {
jQuery('. appstle_paymentBtnUpdate_' + id). html('Processing. ');
jQuery. ajax({
type: "PUT",
url: "https://subscription-admin. appstle com/api/subscription-contracts-update-payment-method?contractId=" + id + "&shop=" + Shopify. Shop,
dataType: "json",
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (result, status, xhr) {
jQuery(". appstle_paymentSuccessMessage_" + id). show();
jQuery('. appstle_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. status text)
jQuery(". appstle_paymentSuccessMessage_" + id). show();
jQuery('. appstle_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('. appstle_cancelBtnText_' + id). html('Processing. ')
jQuery. ajax({
type: "DELETE",
url: "https://subscription-admin. appstle com/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. status text)
}
});
} else {
alert("Product Id is not Found")
}
}
function showFrequencyForm(contractId) {
// jQuery("#orderFrequencyform_" + contractId). show();
jQuery(". appstle_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(". appstle_orderFrequencyformDiv_" + contractId). slideUp();
// jQuery("#orderFrequencyform_" + contractId). hide();
jQuery('. editBtnFrequency_' + contractId). show();
}
function updateOrderDate(contractId) {
var nextBillingDate = document. forms["orderDateform_" + contractId]. changeOrderDate value;
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. appstle com/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. status text)
}
});
// 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(". appstle_orderFrequencyformDiv_" + contractId). slideUp();
jQuery("#orderloadingText_" + contractId). show();
jQuery. ajax({
type: "PUT",
url: "https://subscription-admin. appstle com/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. status text)
}
});
// 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. appstle com/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). value();
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('. appstle_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('. appstle_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('. appstle_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 PopupConfirm(prepaidPlanFlag); // Showing Delete confirm Modal // On click of confirm Code will execute jQuery('. appstle_delete_model_yesbtn'). on('click', function() { hide Delete Confirm Popup(); // Hide the Confirm Modal jQuery(". appstle_myProduct"). fadeOut(500, function () {
jQuery(". appstle_preloader"). fadeIn(250);
});
var settings = {
"async": true,
"crossDomain": true,
"url": 'https://subscription-admin. appstle com/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('. appstle_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(' appstle_input_error'). hide();
var settings = {
"async": true,
"crossDomain": true,
"url": 'https://subscription-admin. appstle com/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(' appstle_input_error'). show();
}
});
addVariant();
addSelect2InHead();
addIconCssInHead();
}
function addVariant() {
var elementsWithProductId = Array. prototype. slice call(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. appstle com/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. appstle com/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. appstle com/api/subscription-contracts-add-line-item?contractId=' + contractId + '&price=' + firstVariant?. price + 'quantity=1 shop=' + shopName + '& variantS=' + first variant?. 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 = type of 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('
')
checkSelect2Initialised()
}
function addIconCssInHead() {
jQuery('head'). append('
')
}
function checkSelect2Initialised() {
try {
initiateSelect2()
} catch(err) {
setTimeout(checkSelect2Initialised,2000)
}
}
function initiateSelect2() {
jQuery(". appstle_product-search-select"). each(function(index, selectEl) {
jQuery(selectEl). on('select2:select', function (e) {
var data = e. params. data;
var selectTargetEl = jQuery(e. target)
selectTargetEl. attr('data-variant-price', data. price);
selectTargetEl. attr('data-variant-id', data. ID);
});
var lastSearchTerm = "";
var next = false;
varcursor = null;
jQuery(selectEl). select2({
ajax: {
url: "https://subscription-admin. appstle com/api/data/v2/product-variants",
dataType: 'json',
delay: 250,
data: function (params) {
if (params. term !== lastSearchTerm) {
next = false;
cursor = null;
}
lastSearchTerm = params. term;
return {
search: params. term, // search term
cursor: cursor,
next: next,
shop: shopName
};
},
"async": true,
"crossDomain": true,
"headers": {
"cache-control": "no-cache",
"postman-token": "06eaf057-9152-2ff9-616b-c8f3f319e47f"
},
processResults: function (data, params) {
next = data. products pageInfo. hasNextPage;
cursor = data. products edges[data. products edge length - 1]. cursor;
// Remove draft products
var listData = data. products edge filter(function(line) {
return line?. node?. status === 'ACTIVE'
})
// Append variants to list
var resultsData = []
listData = listData. forEach(function(line) {
if (line?. node?. total Variants === 1) {
var item = {}
item. title = line?. node?. title;
item. price = line?. node?. variant?. edges[0]?. node?. price;
item. id = lines?. node?. variant?. edges[0]?. node?. ID;
item. imgSrc = line?. node?. featuredImage?. transformedSrc;
item. currencyCode = line?. node?. priceRangeV2?. maxVariantPrice?. currencyCode;
resultsData = [. resultsData, item];
} else {
line?. node?. variant?. edge forEach(function(variantLine) {
var item = {}
item. title = variantLine?. node?. displayName;
item. price = variantLine?. node?. price;
item. id = variantLine?. node?. ID;
item. imgSrc = line?. node?. featuredImage?. transformedSrc;
item. currencyCode = line?. node?. priceRangeV2?. maxVariantPrice?. currencyCode;
resultsData = [. resultsData, item];
})
}
})
// listData = listData. map(function(line) {
// })
// listData = listData. map(function(line) {
// return {
// id: line?. node?. ID
// title: line?. node?. title,
// imgSrc: line?. node?. featuredImage?. transformedSrc
// }
// })
return {
results: resultsData,
pagination: {
more: data. products pageInfo. hasNextPage
}
};
},
cache: true
},
minimumInputLength: 0,
templateResult: formatRepo,
templateSelection: formatRepoSelection
});
})
}
function contractDetailsFromContractId(contractId) {
jQuery. ajax({
type: "GET",
url: 'https://subscription-admin. appstle com/api/subscription-contracts/contract-external/' + contractId + '?shop=' +shopName,
dataType: "json",
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (result, status, xhr) {
return result
console. log("My Contact Data" + result); }, error: function (xhr, status, error) { console. log("Result: " + status + " " + error + " " + xhr. status + " " + xhr. status text)
}
});
}
function formatRepo (product) {
var container = jQuery(
"
" +
"
" +
"
" +
"
" + product?. title + "
" +
"
" + product?. price + " " + product?. currencyCode + "
" +
"
" +
"
"
);
return containers;
}
function formatRepoSelection (product) {
return product. title;
}
function addStyle() {
var css = _RSConfig?. css;
jQuery(''). appendTo(jQuery('head'));
}
function shopifyLoaded() {
if (window. hasOwnProperty('Shopify')) {
windows. shopName = Shopify. Shop;
windows. customerId = __st. cid;
if (customerId == null) {
customerId = urlParams. get('customerId');
}
subscriptionInit();
addStyle();
} else {
setTimeout(shopifyLoaded, 2000)
}
}
function toggleChangeAddressForm(contractId) {
jQuery('. appstle_ShippingAcc_' + contractId). find(' editBtnAddress_' + contractId). toggle();
jQuery('. appstle_ShippingAcc_' + contractId). find(' appstle_address_viewOnly'). slideToggle();
jQuery('. appstle_ShippingAcc_' + contractId). find(' appstle_address_editForm'). slideToggle();
}
function updateShippingAddress(contractId) {
jQuery('. appstle_ShippingAcc_' + contractId). find(' appstle_edit_shipping_update-button span'). hide();
jQuery('. appstle_ShippingAcc_' + contractId). find(' appstle_edit_shipping_update button appstle_loaderTiny'). show();
var formdata = jQuery('. appstle_ShippingAcc_' + contractId). find('shape'). serializeArray();
var data = {};
jQuery(formdata). each(function(index, obj){
data[obj. name] = obj. value;
});
data['name'] = data['firstName'] + ' ' + data['lastName'];
var settings = {
"url": "https://subscription-admin. appstle com/api/subscription-contracts-update-shipping-address?contractId=" + contractId + "&shop=" + shopName,
"method": "PUT",
"timeout": 0,
"headers": {
"Content Type": "application/json"
},
"data": JSON. stringify(data),
};
jQuery. ajax(settings). done(function (response) {
jQuery(". appstle_myProduct"). fadeOut(500, function () {
jQuery(". appstle_preloader"). fadeIn(250);
subscriptionInit();
});
});
}
function pauseSubscription(contractId) {
jQuery('. appstle_subscription_contract_content_wrapper_' + contractId). find(' appstle_pause_subscription_button appstle_icon_wrapper'). hide();
jQuery('. appstle_subscription_contract_content_wrapper_' + contractId). find(' appstle_pause_subscription_button appstle_loaderTiny'). show();
var settings = {
"url": "https://subscription-admin. appstle com/api/subscription-contracts-update-status?contractId=" + contractId + "&status=PAUSED&shop=" + shopName,
"method": "PUT",
"timeout": 0,
};
jQuery. ajax(settings). done(function (response) {
jQuery(". appstle_myProduct"). fadeOut(500, function () {
jQuery(". appstle_preloader"). fadeIn(250);
subscriptionInit();
});
});
}
function resumeSubscription(contractId) {
jQuery('. appstle_subscription_contract_content_wrapper_' + contractId). find(' appstle_resume_subscription_button appstle_icon_wrapper'). hide();
jQuery('. appstle_subscription_contract_content_wrapper_' + contractId). find(' appstle_resume_subscription_button appstle_loaderTiny'). show();
var settings = {
"url": "https://subscription-admin. appstle com/api/subscription-contracts-update-status?contractId=" + contractId + "&status=ACTIVE&shop=" + shopName,
"method": "PUT",
"timeout": 0,
};
jQuery. ajax(settings). done(function (response) {
jQuery(". appstle_myProduct"). fadeOut(500, function () {
jQuery(". appstle_preloader"). fadeIn(250);
subscriptionInit();
});
});
}
jQuery(document). ready(function () {
shopifyLoaded();
});
// ]]>