function($ = recurpayScript){
if((window.location.href.indexOf("/products/") > -1) && (window.location.href.indexOf("recurpay_preview=true") > -1)){
recurpay.pdpAPI = recurpay.generalURL + '/api/storefront/v3/plans?' + recurpay.urlParam + '&fetch=force';
}
var accountTemplate = '',
accountSelector = "#recurpay-account-widget",
pdpSelector = ".recurpay-pdp-widget",
subscriptionSelector = "#recurpay-manage-subscriptions",
checkoutSelector = '[href="/checkout"], form[action="/cart"] button[type="submit"][name="checkout"], form[action="/cart"] input[type="submit"][name="checkout"], form[action="/checkout"] input[type="submit"][name="checkout"], form[action="/checkout"] button[type="submit"][name="checkout"], button[type="submit"][name="checkout"],button[name="checkout"], button[name="checkout"].cart__checkout, button.ucd-checkout-btn, #checkout2.flo-checkout-btn',
atcFormSelector = 'form[action*="/cart/add"], form[action*="/cart/add.js"], form[id^="product_form_"], form[data-productid], form[action*="/cart/add"][data-js-product-form], form#AddToCartForm, #addToCartFormId1, form.product-form, #AddToCartForm_id, form[data-cart-submit="data-cart-submit"][data-productid], form.lh-product-form, form.shg-product-atc-btn-wrapper, form.shopify-product-form, product-form.product-form',
atcSelector = '.buy-buttons [type="submit"], [name="add"], [type=\"submit\"],button#AddToCart, button.gf_add-to-cart, button.gp-button-atc, #button-cart,.new-form-atc[data-add-to-cart], button[data-type="addToCart"], .product-buy-buttons--primary[data-text="Add to cart"], product-variant-render button[type="submit"],.x-buy-now-button',
buynowSelector = '.shopify-payment-button,.shopify-payment-button__button',
priceQuantitySelector = '[name=quantity]',
footerManageSubcriptionSelector = ".recurpay-manage-subscription-link-footer",
footerLinkSelector = 'footer, .footer',
appBlockSelector = '[id*="recurpay_app_block_widget"], .shopify-app-block[data-block-handle="recurpay-app-block-widget"]',
appBlockParentSelector = ".product-info, .shop-product-info, .product-single__meta [data-product-blocks], .shopify-block, .product__info-container";
// ACCOUNT PAGE
if(recurpay.pageTemplate == "customers/account" && $(accountSelector).length <= 0){
if($('.card__linklist').length >0){
$('.card__linklist').before('
');
}
else if($('.flits-account-page-title').length >0){
$('.flits-account-page-title').append('');
}
else if($('a[href*="/account/addresses"]').length >0){
$('a[href*="/account/addresses"]').before('');
}
else if ($('.order-history').length >0){
$('.order-history').before('');
}
else if ($('a[href*="/account/logout"]').length >0){
$('a[href*="/account/logout"]').before('');
}
else{
recurpay.logEvent("account_widget","Failed to show account snippet", "critical");
}
}
//LOGIN PAGE
function loginPageSubscriptionLink(){var accountLoginHTML="",footerLinkHTML="",managesubscriptionSelector=".recurpay-manage-subscription-link",signUpFormSelector='form[action*="/account"]';if($(managesubscriptionSelector).length<=0&&$(signUpFormSelector).length>0){$(signUpFormSelector).append("");}if($(footerManageSubcriptionSelector).length<=0&&$(footerLinkSelector).length>0){$(footerLinkSelector).find('.footer__content-bottom .footer__content-bottom-wrapper .footer__copyright').append('');}var account_url="";account_url = recurpay.customer ? recurpay.accountAPI + "&settings=true" : recurpay.generalURL + "/api/storefront/v3/customers/subscriptions/count?" + recurpay.urlParam + "&settings=true";$.ajax({url:account_url,type:'POST',data:{customer_id: recurpay.customer||'',customer_hash: recurpay.secret_potion ||''},async:true,success:function(response){if(response!="ERROR"){if(response.settings!==null&&!$.isEmptyObject(response.settings)&&response.translations.breadcrumb_manage_subscription_link!=undefined){if($(managesubscriptionSelector).length>=0){accountLoginHTML+=""+response.translations.breadcrumb_manage_subscription_link+"";}if($(footerManageSubcriptionSelector).length>=0){footerLinkHTML+=""+response.translations.breadcrumb_manage_subscription_link+"";}}}$(managesubscriptionSelector).html(accountLoginHTML);$(footerManageSubcriptionSelector).html(footerLinkHTML);}});}
loginPageSubscriptionLink();
if($(accountSelector).length && recurpay.customer !== "guest"){
function recurAccount(count){
accountTemplate += ''
accountTemplate += '
'
accountTemplate += '
'+recurpay.accountSettings.translations.breadcrumb_subscription_heading+' ('+count+')
'
if(count !== 0){
accountTemplate += '
'+recurpay.accountSettings.translations.breadcrumb_subscription_description+'
'
accountTemplate += '
'
}
else{
accountTemplate += '
'+recurpay.accountSettings.translations.breadcrumb_subscription_placeholder_for_no_subscriptions+'
'
accountTemplate += '
'
}
accountTemplate += '
'
return accountTemplate;
}
$.ajax({
url: recurpay.accountAPI+"&settings=true",
type: 'POST',
data:{
customer_id: recurpay.customer || '',
customer_hash: recurpay.secret_potion || ''
},
async:true,
success: function(response){
var accountHTML = '';
if(response != "ERROR"){
if(response.settings !== null && !$.isEmptyObject(response.settings)){
recurpay.accountSettings = response.settings;
document.documentElement.style.setProperty('--recurpay_primary_color', recurpay.accountSettings.snippet_color_codes.account_brand_color);
document.documentElement.style.setProperty('--recurpay_button_text_color', recurpay.accountSettings.snippet_color_codes.account_button_text_color);
document.documentElement.style.setProperty('--recurpay_button_bg_color', recurpay.accountSettings.snippet_color_codes.account_button_color);
}
accountHTML = recurAccount(response.count);
}
else {
accountHTML = recurAccount(0);
}
if($(accountSelector).length){
$(accountSelector).html(accountHTML);
}
},
error: function(jqXhr, textStatus, errorThrown){
console.log( errorThrown );
}
});
$(document).on('click', subscriptionSelector, function(e){
e.preventDefault();
$.ajax({
url: recurpay.manageAccountAPI,
type: 'POST',
data:{
customer_id: recurpay.customer,
customer_hash: recurpay.secret_potion || ''
},
success: function(response){
var redirect_url = response.account.url;
if(redirect_url !== "" && redirect_url !== null && redirect_url !== undefined){
setTimeout(() => { window.location.href = redirect_url; }, 100);
}
else{
console.log('redirect url error');
}
},
error: function(response){
console.log('redirect url error');
}
})
});
}
// VARIANT SELECTOR
function formatPriceMoney(price){var multiple_price=price*100;var formatted_price=recurpay.recurMoney.formatPrice(multiple_price);return formatted_price;}
$(atcFormSelector).closest(".product__meta").find("button.product__chip").on("click",function(){var $this=$(this);setTimeout(function(){recurpay.product.selectedVariant=$this.parents(atcFormSelector).find('select[name="id"]').val();if(recurpay.product.selectedVariant!=undefined&&recurpay.product.selectedVariant!=null&&recurpay.product.selectedVariant!=""){recurDiscountedPrice(recurpay.product.selectedVariant);recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);}},100);});$(atcFormSelector).find(".combobox, .wetheme-dropdown__wrapper ul[id^='SingleOptionSelector-'] li, .option-values-radio .popover-list-item .form-element-radio, .single-option-selector .bcpo-image-parent, .regular-select-item, .bcpo-dd.single-option-selector ul.inner li, #clickyboxes-SingleOptionSelector-0 a, button.product__chip, .form-swatch-item, .product-variant__container .product-variant__label, .options-selection__option-value, .popout-list__option--product, .option-swatch .custom-swatch, ul.select-dropdown li, .swatch-element, .swatch_pr_item, .basel-swatch, .swatchBox label, .swatchBox span").on("click",function(){var $this=$(this);setTimeout(function(){recurpay.product.selectedVariant=$this.parents(atcFormSelector).find('select[name="id"], input[name="id"][type="radio"]:checked').val();if(recurpay.product.selectedVariant!=undefined&&recurpay.product.selectedVariant!=null&&recurpay.product.selectedVariant!=""){recurDiscountedPrice(recurpay.product.selectedVariant);recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);}},100);});$(atcFormSelector).closest(".product-selection").find("select.single-option-selector").on("change",function(){var $this=$(this);setTimeout(function(){recurpay.product.selectedVariant=$this.parents(atcFormSelector).find('select[name="id"]').val();if(recurpay.product.selectedVariant!=undefined&&recurpay.product.selectedVariant!=null&&recurpay.product.selectedVariant!=""){recurDiscountedPrice(recurpay.product.selectedVariant);recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);}},100);});$(atcFormSelector).find(".product-single__swatch__input").on("change",function(){var $this=$(this);setTimeout(function(){recurpay.product.selectedVariant=$this.parents(atcFormSelector).find('select[name="id"]').val();if(recurpay.product.selectedVariant!=undefined&&recurpay.product.selectedVariant!=null&&recurpay.product.selectedVariant!=""){recurDiscountedPrice(recurpay.product.selectedVariant);recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);}},100);});$(atcFormSelector).find('input#SelectedId, select.js-variant-select, input[name="id"], select[name="id"], select.single-option-selector, .zpa-single-option-selector, .select.options-selection__input-select, .form-options input.option-value-input, .variant-input input[type="radio"], .product-form__option-select, .option-selectors .selector-wrapper select, select.single-option-list-type, .product-options .option-input, select.input-reset, select.js-product-variant, select[data-single-option-selector], input[data-single-option-selector], select.single-option-selector-product-template, .single-option-selector[type="radio"], .single-option-selector-product-template[type="radio"], .variant-option').on("change",function(){var $this=$(this);setTimeout(function(){recurpay.product.selectedVariant=$this.parents(atcFormSelector).find('input[name="id"], select[name="id"], input#SelectedId').val();if(recurpay.product.selectedVariant!=undefined&&recurpay.product.selectedVariant!=null&&recurpay.product.selectedVariant!=""){recurDiscountedPrice(recurpay.product.selectedVariant);recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);}},100);});
$(document).find(".quantity-breaks input[name='quantity']").on("change",function(){let $this=$(this);setTimeout(function(){recurpay.product.selectedVariant=$this.parents(".product__info-container").find(atcFormSelector).find('input.product-variant-id,input[name="id"],select[name="id"],input#SelectedId').val();if(recurpay.product.selectedVariant!=undefined&&recurpay.product.selectedVariant!=null&&recurpay.product.selectedVariant!=""){recurDiscountedPrice(recurpay.product.selectedVariant);recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);}},100)});
$(document).find("form.variant-picker__form .variant-option input[type='radio']").on("change",function(){let $this=$(this);setTimeout(function(){recurpay.product.selectedVariant=$this.attr("data-variant-id");if(recurpay.product.selectedVariant!=undefined&&recurpay.product.selectedVariant!=null&&recurpay.product.selectedVariant!=""){recurDiscountedPrice(recurpay.product.selectedVariant);recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);}},100)});
var getLastUrl=location.href;new MutationObserver(()=>{var getUrl=location.href;if(getUrl!==getLastUrl){getLastUrl=getUrl;onUrlChange();}}).observe(document,{subtree:true,childList:true});function onUrlChange(){var getSearchParams=new URLSearchParams(window.location.search);if(getSearchParams.has('variant')){recurpay.product.selectedVariant=getSearchParams.get('variant');recurDiscountedPrice(recurpay.product.selectedVariant);recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);}}
function fetchVariants(){if(recurpay.getProductHandle()!==false){$.ajax({url:"/products/"+recurpay.getProductHandle()+".json",type:"GET",success:function(response){recurpay.productDatas[0].product.variants=response.product.variants;recurDiscountedPrice(recurpay.product.selectedVariant);recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);},error:function(jqXhr,textStatus,errorThrown){console.log(errorThrown);}});}}
recurpay.handlePlanOnVariant=function(variant){let excludedPlans=[];var getVariantObj=recurpay.calculatePrice(variant);var getProductId=parseInt(getVariantObj.product_id);let variantId=variant;recurpay.globalPlanObjectArray.forEach(plan=>{plan.products.forEach(product=>{if(product.excluded_variants&&product.excluded_variants.length>0){product.excluded_variants.forEach(variant=>{if(variant.id==variantId){excludedPlans.push(plan.id)}})}})});let $pdpWidgetSelector=$('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]');let isExcluded=excludedPlans.length>0;let shownOptionCount=0;let previousSelectedPlanId=$pdpWidgetSelector.find(".recurpay__frequency_select").find("option:selected").attr("data-plan")||null;let encodedOptions=$pdpWidgetSelector.find(".recurpay__frequency_select").attr('data-original-options');if(encodedOptions){let originalOptions=decodeURIComponent(encodedOptions);$pdpWidgetSelector.find(".recurpay__frequency_select").html(originalOptions)}$pdpWidgetSelector.find(".recurpay__frequency_select option").each(function(){let $this=$(this);var getPlanId=$this.attr("data-plan");if(isExcluded&&excludedPlans.includes(parseInt(getPlanId))){$this.remove()}else{shownOptionCount++}});if(shownOptionCount===0){$pdpWidgetSelector.hide();if($pdpWidgetSelector.parents(atcFormSelector).find(atcSelector).hasClass("recurpay-hide")){$pdpWidgetSelector.parents(atcFormSelector).find(atcSelector).removeClass("recurpay-hide")}if($pdpWidgetSelector.parents(atcFormSelector).find(buynowSelector).hasClass("recurpay-hide")){$pdpWidgetSelector.parents(atcFormSelector).find(buynowSelector).removeClass("recurpay-hide")}$(document).find(".recurpay_plan_name").attr("name","");$(document).find(".recurpay_plan_id").attr("name","");$(document).find(".recurpay_purchase_data").attr("name","");$(document).find(".recurpay_selling_plan_id").attr("name","")}else{$pdpWidgetSelector.show();if($(document).find("[name='recurpay__group_main']:checked").val()=='subscription'){$pdpWidgetSelector.parents(atcFormSelector).find(atcSelector).addClass("recurpay-hide");$pdpWidgetSelector.parents(atcFormSelector).find(buynowSelector).addClass("recurpay-hide");$(document).find(".recurpay_plan_name").attr("name","properties[Plan]");$(document).find(".recurpay_plan_id").attr("name","properties[_PlanId]");$(document).find(".recurpay_purchase_data").attr("name","properties[_PurchaseData]");$(document).find(".recurpay_selling_plan_id").attr("name","selling_plan")}let $select=$pdpWidgetSelector.find(".recurpay__frequency_select");let $matchedOption=previousSelectedPlanId?$select.find(`option[data-plan="${previousSelectedPlanId}"]`):null;if(!$matchedOption||!$matchedOption.length){$matchedOption=$select.find('option[data-recommended-frequency="true"]');if(!$matchedOption.length){$matchedOption=$select.find("option").first()}}if($matchedOption&&$matchedOption.length){$matchedOption.prop("selected",true);$select[0].dispatchEvent(new Event("change",{bubbles:true}))}}}
function recurDiscountedPrice(variant){
// For Multiplying price with quantity
const showPriceWithQuantity = recurpay.multiply_price_with_quantity;
const showPriceInFrequencyDropdown = recurpay.show_price_in_freq_dropdown;
let productQuantityToMultiply = 1;
if(showPriceWithQuantity) {
var $formOnPage = $(atcFormSelector);
let $quantityElement;
const descriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
let selectedForm = $formOnPage.filter(function(){
return $(this).find('.recurpay-pdp-widget .recurpay__widget').length;
}).first();
if(!selectedForm.length){
selectedForm = $formOnPage.first();
}
selectedForm.each(function(index, form){
if(form.elements){
const childElement = $.each(form.elements, function(index, formItem) {
if(this.name == 'quantity'){
$quantityElement = $(this);
if($quantityElement) {
productQuantityToMultiply = $quantityElement.val();
// Define a new descriptor for the 'value' property
try{
Object.defineProperty($quantityElement[0], 'value', {
get(){
return descriptor.get.call(this);
},
set(value){
if(this.value !== value){
descriptor.set.call(this, value);
var updatedVariant = $(form).find('[name="id"]').val();
if(updatedVariant){
recurDiscountedPrice(updatedVariant)
recurpay.handlePlanOnVariant(updatedVariant)
}
else{
recurDiscountedPrice(variant)
recurpay.handlePlanOnVariant(variant)
}
}
}
});
}
catch(e){}
}
}
});
}
else if(form.querySelector('input[name="quantity"]')){
let formQuantityElement = form.querySelector('input[name="quantity"]');
$quantityElement = $(formQuantityElement);
productQuantityToMultiply = $quantityElement.val();
}
})
}
let $selectedQty = $(document).find(".quantity-breaks input[name='quantity']:checked");
if($selectedQty.length) {
productQuantityToMultiply = $selectedQty.val();
}
var getVariantObj = recurpay.calculatePrice(variant);
var getVariantPrice = getVariantObj.variant_price * (productQuantityToMultiply || 1);
var getProductId = parseInt(getVariantObj.product_id);
var showSavings = true;
$('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').find(".recurpay__frequency_select option").each(function(){
var $this = $(this);
var getDiscount = $(this).attr("data-plan-discount");
var getPlanName = $(this).attr("data-plan-name");
var getPlanShipment = $(this).attr("data-plan-shipment");
if(getPlanShipment == null || getPlanShipment == undefined || getPlanShipment == "null"){
getPlanShipment = 1;
}
if(getDiscount == null || getDiscount == undefined || getDiscount == "null"){
getDiscount = 0;
}
var discountedPrice = getVariantPrice - (getVariantPrice * getDiscount / 100);
var getSavings = getVariantPrice * getPlanShipment - discountedPrice*getPlanShipment;
if(parseFloat(getVariantPrice) !== parseFloat(discountedPrice)){
(!(showPriceInFrequencyDropdown)) ? $this.html(""+getPlanName+"") : $this.html(""+getPlanName+" ("+formatPriceMoney(discountedPrice*getPlanShipment)+")")
if($this.is(':selected')){
$('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').find(".recurpay__widget_container[data-type='subscription-purchase']").find(".recurpay__group_compare_price").html(""+formatPriceMoney(getVariantPrice*getPlanShipment)+"");
}
}
else{
(!(showPriceInFrequencyDropdown)) ? $this.html(""+getPlanName+"") : $this.html(""+getPlanName+" ("+formatPriceMoney(discountedPrice*getPlanShipment)+")")
if($this.is(':selected')){
$('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').find(".recurpay__widget_container[data-type='subscription-purchase']").find(".recurpay__group_compare_price").html("");
}
}
if($this.is(':selected')){
if(getDiscount <=0){
showSavings = false;
}
$('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').find(".recurpay__widget_container[data-type='subscription-purchase']").find(".recurpay__saving_amount").html(""+formatPriceMoney(getSavings)+"");
$('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').find(".recurpay__widget_container[data-type='subscription-purchase']").find(".recurpay__group_selling_price").html(""+formatPriceMoney(discountedPrice*getPlanShipment)+"");
$('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').find(".recurpay__widget_container[data-type='subscription-purchase']").find(".recurpay__offer_saving_message_amount_text").html(parseFloat(getDiscount).toFixed(2).replace(/\.0+$/,''));
let recommendedCheck = $this.attr("data-recommended-frequency");
if(recommendedCheck == "true" && $('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').find(".recurpay__frequency_select option").length > 1){$this.parents(".recurpay__group_frequency").addClass("recommended_frequency");}else{$this.parents(".recurpay__group_frequency").removeClass("recommended_frequency");}
if((recurpay.settings.sell_only_as_subscription == true || recurpay.product.onlySubscription == "true") && $('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').parents(".product__info-container").length){
const $container = $('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').parents(".product__info-container");
if($container.find(".price__container .price__sale .price-item.price-item--sale").length) {
$container.find(".price__container .price__sale .price-item.price-item--sale").html(""+formatPriceMoney(discountedPrice*getPlanShipment)+"");
}
if($container.find(".price__container .price__regular .price-item").length) {
$container.find(".price__container .price__regular .price-item").html(""+formatPriceMoney(discountedPrice*getPlanShipment)+"");
}
}
}
$('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').find(".recurpay__widget_container[data-type='onetime-purchase']").find(".recurpay__group_selling_price").html(""+formatPriceMoney(getVariantPrice)+"");
$('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]').find(".recurpay__widget_container[data-type='onetime-purchase']").find(".recurpay__offer_saving_message_amount_text").html(parseFloat(getDiscount).toFixed(2).replace(/\.0+$/,''));
});
promotionalOffer($('.recurpay-pdp-widget[data-product-id="'+getProductId+'"]'));
}
function offerSavings(selector){var selectedOption=$(selector).find('[name="recurpay__group_main"]').val();var getDiscountVal=$(selector).find(".recurpay__frequency_select option:selected").attr("data-plan-discount");if(getDiscountVal==null||getDiscountVal==undefined||getDiscountVal=="null"){getDiscountVal=0;}if(parseFloat(getDiscountVal)>0){if($(selector).find('[name="recurpay__group_main"]:checked').val()=="subscription"){$('.recurpay__offer_onetime').hide();$('.recurpay__offer_subscription').css("display","flex");}else{$('.recurpay__offer_onetime').css("display","flex");$('.recurpay__offer_subscription').hide();}if(recurpay.settings.translations.premium_one_time_saving_icon==""&&recurpay.settings.translations.premium_one_time_saving_msg==""&&recurpay.settings.translations.premium_one_time_saving_label==""&&recurpay.settings.translations.premium_one_time_discount_label==""){$('.recurpay__offer_onetime').hide();}if(recurpay.settings.translations.premium_subscription_saving_icon==""&&recurpay.settings.translations.premium_subscription_saving_msg==""&&recurpay.settings.translations.premium_subscription_saving_label==""&&recurpay.settings.translations.premium_subscription_discount_label==""){$('.recurpay__offer_subscription').hide();}}else{$('.recurpay__offer_wrapper').hide();}}
// PRODUCT PAGE
function recurPDP(data){var prepaidCount=0,regularCount=0,prepaidDiscount=[],maxPrepaidDiscount="",getPlanDesc="",pdpTemplate="",GetPlans="";GetPlansLength=data.plans.length;$.each(data.plans,function(key,plan){var DiscountPercentageHtml="",DescriptionHtml="",PlanHtml="",PlanDiscount=0,PlanType="regular";if(plan.type){PlanType=plan.type;if(PlanType=="prepaid"){prepaidCount+=prepaidCount+1;prepaidDiscount.push(plan.pricing_policy[0].discount.value);}else{regularCount+=regularCount+1;}}if(plan.pricing_policy[0].discount.type=="percentage"&&plan.pricing_policy[0].discount.value!=0){PlanDiscount=plan.pricing_policy[0].discount.value;DiscountPercentageHtml='('+PlanDiscount+"% Off)";}if(plan.description){DescriptionHtml=''+plan.description+"
";}if(recurpay.checkout=="shopify"){if((plan.recommended&&plan.recommended==true)){PlanHtml+='";}else{PlanHtml+='";}}else{if((plan.recommended&&plan.recommended==true)){PlanHtml+='";}else{PlanHtml+='";}}GetPlans+=PlanHtml;getPlanDesc+=DescriptionHtml;});if(regularCount>0&&prepaidCount>0){maxPrepaidDiscount=Math.max.apply(Math,prepaidDiscount);}if(recurpay.subscriptionFirst==true){pdpTemplate+='';}else{pdpTemplate+='
";pdpTemplate+='
';pdpTemplate+='
';pdpTemplate+='
';if(recurpay.checkout=="shopify"){pdpTemplate+='
';}pdpTemplate=pdpTemplate.split("[[SAVING_AMOUNT]]").join("
");pdpTemplate=pdpTemplate.split("[[DISCOUNT_PERCENTAGE]]").join("
");return pdpTemplate;}
function updateGeneralSettings(primary_background,primary_foreground,secondary_background){let settings_url=recurpay.generalURL+'/storefront/api/2024-07/widgets/configurations?'+recurpay.urlParam;$.ajax({url:settings_url,type:"POST",data:{subscription_brand_color:primary_background,subscription_button_color:primary_background,subscription_button_text_color:primary_foreground,subscription_secondary_color:secondary_background,cart_upsell_brand_color:primary_background,cart_upsell_button_color:primary_background,cart_upsell_button_text_color:primary_foreground,cart_upsell_secondary_color:secondary_background},success:function(response){console.log(response);},error:function(error){console.log(error);}});}
if($(document).find(appBlockSelector).length > 0){
if($(document).find('.recurpay-pdp-widget').length <= 0){
if(window.location.href.indexOf("/products/") > -1 && $(document).find('.recurpay-pdp-widget').length <= 0){
$(document).find(appBlockSelector).append('
');
}
else{
$(document).find(appBlockSelector).each(function (){
let $appBlock = $(this);
let $productContainer = "";
if(window.location.href.indexOf("/collections/") > -1){$productContainer = $appBlock.closest("li.product-grid__item");}else{$productContainer = $appBlock.closest(".product__info-container, .product-info, .shop-product-info, .product-single__meta [data-product-blocks]");}
let $form = $productContainer.find(atcFormSelector);
let product_id = $form.find("input[name='product-id']").val();
let default_variant_id = $form.find("input[name='id']").val();
$appBlock.append(`
`);
});
}
}
}
else if($(pdpSelector).length <= 0){
if(window.location.href.indexOf("/products/") > -1 && $(document).find(appBlockSelector).length <= 0){
if($(atcFormSelector).find(atcSelector).filter(':visible').length){
if($(atcFormSelector).find(atcSelector).filter(':visible').first().parent().css('display') == 'flex' && $(atcFormSelector).find(atcSelector).filter(':visible').first().parent().css('flex-direction') == 'row'){
$(atcFormSelector).find(atcSelector).filter(':visible').first().parent().before('
');
}
else if($(atcFormSelector).find(atcSelector).filter(':visible').first().parent().css('display') == 'grid' || $(atcFormSelector).find(atcSelector).filter(':visible').first().parent().css('display') == 'inline-grid'){
$(atcFormSelector).find(atcSelector).filter(':visible').first().parent().before('
');
}
else{
if($(atcFormSelector).parents('.product__info-container').find(atcSelector).length){
$(atcFormSelector).parents('.product__info-container').find(atcSelector).filter(':visible').first().before('
');
}
else{
$(atcFormSelector).find(atcSelector).filter(':visible').first().before('
');
}
}
if($(pdpSelector).parent().css('position') == 'fixed' || $(pdpSelector).parent().css('position') == 'sticky' || $(pdpSelector).parent().css('position') == 'absolute' ){
$(pdpSelector).parent().addClass("recurpay-z-index");
}
}
else if($(atcFormSelector).find(atcSelector).length){
if($(atcFormSelector).find(atcSelector).first().parent().css('display') == 'flex' && $(atcFormSelector).find(atcSelector).filter(':visible').first().parent().css('flex-direction') == 'row'){
$(atcFormSelector).find(atcSelector).first().parent().before('
');
}
else{
$(atcFormSelector).find(atcSelector).first().before('
');
}
if($(pdpSelector).parent().css('position') == 'fixed' || $(pdpSelector).parent().css('position') == 'sticky' || $(pdpSelector).parent().css('position') == 'absolute' ){
$(pdpSelector).parent().addClass("recurpay-z-index");
}
}
else{
$(atcFormSelector).append('
')
}
}
}
if($(pdpSelector).length){
recurpay.allProducts = [];
for(i=0; i<$(pdpSelector).length; i++){
if($(pdpSelector).eq(i).attr("data-product-id") != undefined && $(pdpSelector).eq(i).attr("data-product-available") != undefined ){
recurpay.allProducts.push($(pdpSelector).eq(i).attr("data-product-id"));
}
}
$.ajax({
url: recurpay.pdpAPI,
type: 'POST',
async:true,
data: {"products": recurpay.allProducts,"settings": true},
success: function(response) {
if(response != "ERROR") {
if(response.plans.length > 0){
recurpay.productDatas = response.plans;
if(response.settings.default_purchase_option !== undefined && response.settings.default_purchase_option !== null && response.settings.default_purchase_option == 'onetime'){
recurpay.subscriptionFirst = false;
}
if(response.settings.default_purchase_redirection !== undefined){
recurpay.action = response.settings.default_purchase_redirection;
}
if(response.settings.translations !== null && !$.isEmptyObject(response.settings.translations)){
recurpay.settings = response.settings;
let brandPrimaryBg = recurpay.shop_brand_primary_background_color;
let brandPrimaryFg = recurpay.shop_brand_primary_foreground_color;
let brandSecondaryBg = recurpay.shop_brand_secondary_background_color;
if(recurpay.settings.snippet_color_codes.is_default_widget_configuration && (brandPrimaryBg || brandSecondaryBg)){
document.documentElement.style.setProperty('--recurpay_primary_color', brandPrimaryBg);
document.documentElement.style.setProperty('--recurpay_secondary_color', brandSecondaryBg);
document.documentElement.style.setProperty('--recurpay_button_text_color', brandPrimaryFg);
document.documentElement.style.setProperty('--recurpay_button_bg_color', brandPrimaryBg);
document.documentElement.style.setProperty('--recurpay_savings_bg_color', recurpay.hexToRgbA(brandPrimaryBg));
updateGeneralSettings(brandPrimaryBg, brandPrimaryFg, brandSecondaryBg);
}
else{
document.documentElement.style.setProperty('--recurpay_primary_color', recurpay.settings.snippet_color_codes.subscription_brand_color);
document.documentElement.style.setProperty('--recurpay_secondary_color', recurpay.settings.snippet_color_codes.subscription_secondary_color);
document.documentElement.style.setProperty('--recurpay_button_text_color', recurpay.settings.snippet_color_codes.subscription_button_text_color);
document.documentElement.style.setProperty('--recurpay_button_bg_color', recurpay.settings.snippet_color_codes.subscription_button_color);
document.documentElement.style.setProperty('--recurpay_savings_bg_color', recurpay.hexToRgbA(recurpay.settings.snippet_color_codes.subscription_brand_color));
}
}
$(response.plans).each(function(){
var pdpHTML = '';
var $this = $(this);
if($this[0].product.plans.length >0){
pdpHTML = recurPDP($this[0].product);
recurpay.globalPlanObjectArray = $this[0].product.plans;
fetchVariants();
var getElem = $('.recurpay-pdp-widget[data-product-id="'+$this[0].product.id+'"]');
if($(getElem).length && $(getElem).attr("data-product-available") == "true"){
$(getElem).html(pdpHTML);
if(response.settings.default_purchase_option !== undefined && response.settings.default_purchase_option !== null && response.settings.default_purchase_option == 'onetime'){
offerSavings($(getElem));
}
if(response.store.created_at != undefined && response.store.created_at != null && response.store.created_at != ""){
const createdDate = new Date(response.store.created_at);
const releaseDate = new Date('2024-07-16T00:00:00.000Z');
const createdDateString = createdDate.toISOString().split('T')[0];
const releaseDateString = releaseDate.toISOString().split('T')[0];
if(createdDateString < releaseDateString){
$(footerManageSubcriptionSelector).hide();
}
}
if($(getElem).attr("data-only-subscription") == "true"){
$(getElem).find(".recurpay__widget[data-recurpay-widget]").addClass("recurpay_only_subscription_widget");
}
if((window.location.href.indexOf("/products/") > -1) && (window.location.href.indexOf("snippet_status=false") > -1)){
$(getElem).before("
You are previewing subscriptions currently and the option below is not visible to customers on your live store. Click here if you are ready to show it your customers now.")
}
if($(getElem).is(":hidden") || $(getElem).width() < 220){
recurpay.logEvent("product_widget","Product snippet added but needs a reverification", "warning");
}
}
var params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
});
if(params.variant !== undefined && params.variant !== null){
var variant_id = parseInt(params.variant);
let variant_data = [];
variant_data.push(...$this[0].product.variants.filter(function(searchId) {
return parseInt(searchId.id) == variant_id;
}));
if(variant_data.length >=1){
recurpay.product.selectedVariant = params.variant
recurDiscountedPrice(recurpay.product.selectedVariant);
recurpay.handlePlanOnVariant(recurpay.product.selectedVariant);
}
else{
recurpay.product.selectedVariant = $this[0].product.variants[0].id;
recurDiscountedPrice($this[0].product.variants[0].id);
recurpay.handlePlanOnVariant($this[0].product.variants[0].id);
}
}
else{
if(recurpay.product.availableVariant !== "" && recurpay.product.availableVariant !== undefined){
recurpay.product.selectedVariant = recurpay.product.availableVariant;
recurDiscountedPrice(recurpay.product.availableVariant);
recurpay.handlePlanOnVariant(recurpay.product.availableVariant);
}
else{
recurpay.product.selectedVariant = $this[0].product.variants[0].id;
recurDiscountedPrice($this[0].product.variants[0].id);
recurpay.handlePlanOnVariant($this[0].product.variants[0].id);
}
}
}
});
if(response.settings.sell_only_as_subscription !== undefined && response.settings.sell_only_as_subscription !== null){
if(response.settings.sell_only_as_subscription == true){
updateSelectors(true);
}
else{
updateSelectors();
}
}
}
}
}
});
if(window.location.href.indexOf("/products/") > -1){
var offersModalHTML = "";
offersModalHTML += '
'
offersModalHTML += '
'
offersModalHTML += ''
offersModalHTML += '
'
offersModalHTML += '
'
offersModalHTML += '
'
offersModalHTML += '
'
offersModalHTML += '
'
if($('body').length){
$('body').append(offersModalHTML);
}
else if($('html').length){
$('html').append(offersModalHTML);
}
}
}
else{
if((window.location.href.indexOf("/products/") > -1) && (window.location.href.indexOf("recurpay_preview=true") > -1)){
var domain_array = recurpay.shopDomainURL.split('.');
var domain_string = domain_array[0];
var recurpay_domain = 'https://' + domain_string + '.recurpay.com';
var modalHTML = "";
modalHTML += '
'
modalHTML += '
'
modalHTML += '
'
modalHTML += '
'
modalHTML += ''
modalHTML += '
'
modalHTML += '
'
modalHTML += '
Looks like the subscription option is not visible on your store due to some conflict with theme. Talk to us on Live Chat to get it resolved instantly '
modalHTML += '
'
modalHTML += '
'
if($('[data-recurpay-visibility-modal]').length <= 0){
if($('body').length){
$('body').append(modalHTML);
}
else if($('html').length){
$('html').append(modalHTML);
}
}
}
if((window.location.href.indexOf("/products/") > -1)){
recurpay.logEvent("product_widget","Failed to show product snippet", "critical");
}
}
function ordinalSuffix(n){return["st","nd","rd"][((n+90)%100-10)%10-1]||"th"}
function promotionalOffer(promoSelector){var getQty=1,getVariant="",offerParams=[],getProductId=parseInt($(promoSelector).attr("data-product-id")),getVariantSelector=$(promoSelector).parents(atcFormSelector).find('[name="id"]'),getQtySelector=$(promoSelector).parents(atcFormSelector).find('[name="quantity"]'),getPlanId=parseInt($(promoSelector).find('[name="recurpay-input"] option:selected').attr("data-plan")),getDeliveryInterval=$(promoSelector).find('[name="recurpay-input"] option:selected').attr("data-delivery-interval"),getDeliveryFrequency=parseInt($(promoSelector).find('[name="recurpay-input"] option:selected').attr("data-delivery-frequency"));""!=recurpay.settings.translations.promotion_popup_heading_label&&$(".recurpay-preview-preview-title").html(recurpay.settings.translations.promotion_popup_heading_label),getQtySelector.length&&(getQty=parseInt(getQtySelector.val())),getVariantSelector.length?getVariant=parseInt(getVariantSelector.val()):getVariant=$(promoSelector).attr("data-default-variant"),offerParams.push({variant_id:getVariant,product_id:getProductId,quantity:getQty,plan:{id:getPlanId,delivery_policy:{interval:getDeliveryInterval,frequency:getDeliveryFrequency}}}),$.ajax({url:recurpay.offersAPI,type:"POST",data:{product_set:offerParams},async:!0,success:function(response){if(!0===response.success){$(document).find(".offer-applied-div").show();if(response.data.applicable_offers.length>0){var multipleOffer=!1,listCount=1,botOfferListHtml="",botOfferArray=[];for(index=0;index
"):0!=i&&""!=order.message&&(botOfferListHtml+='")}),$(document).find(".bot-offer-wrapper").html(botOfferListHtml)}else $(document).find(".offer-applied-div").hide(),$(document).find(".recurpay-preview-modal-container").fadeOut()}else $(document).find(".offer-applied-div").hide(),$(document).find(".recurpay-preview-modal-container").fadeOut()},error:function(error){$(document).find(".offer-applied-div").hide(),$(document).find(".recurpay-preview-modal-container").fadeOut()}})}
function recurProperties(elem){var getParent=$(elem).parents(pdpSelector);if($(getParent).find("[name='recurpay__group_main'][value='subscription']").is(":checked")){var planName=$(getParent).find('[name="recurpay-input"] option:selected').attr("data-plan-name"),planId=$(getParent).find('[name="recurpay-input"] option:selected').attr("data-plan");if(elem.closest(appBlockSelector).length>0){if(elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_plan_name").length<=0){elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).append(``);}else{elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_plan_name").attr("name","properties[_Plan]").val(planName);}if(elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_plan_id").length<=0){elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).append(``);}else{elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_plan_id").attr("name","properties[_PlanId]").val(planId);}}else{$(getParent).find(".recurpay_plan_name").attr("name","properties[_Plan]").val(planName);$(getParent).find(".recurpay_plan_id").attr("name","properties[_PlanId]").val(planId);}if(parseInt(recurpay.subscriptionInfluence&&recurpay.subscriptionInfluenceCount)>=1){if(elem.closest(appBlockSelector).length>0){if(elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_purchase_data").length<=0){elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).append(``);}else{elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_purchase_data").attr("name","properties[_PurchaseData]").val(recurpay.subscriptionInfluenceCount);}}else{$(getParent).find(".recurpay_purchase_data").attr("name","properties[_PurchaseData]").val(recurpay.subscriptionInfluenceCount);}}$(getParent).find(".recurpay__description[data-description-id]").hide();$(getParent).find('.recurpay__description[data-description-id="'+planId+'"]').show();if(recurpay.checkout=="shopify"){var sellingPlanId=$(getParent).find('[name="recurpay-input"] option:selected').attr("data-selling-plan");if(elem.closest(appBlockSelector).length>0){if(elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_selling_plan_id").length<=0){elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).append(``);}else{elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_selling_plan_id").attr("name","selling_plan").val(sellingPlanId);}}else{$(getParent).find(".recurpay_selling_plan_id").attr("name","selling_plan").val(sellingPlanId);}if(window._RestockRocket&&typeof window._RestockRocket.getSellingPlan==="function"){$('.restock-rocket-form-input[name="selling_plan"]').attr("name","");$(".restock-rocket-preorder-description").hide();}}}else{if(elem.closest(appBlockSelector).length>0){elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_plan_name").attr("name","");elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_plan_id").attr("name","");elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_purchase_data").attr("name","");}else{$(getParent).find(".recurpay_plan_name").attr("name","");$(getParent).find(".recurpay_plan_id").attr("name","");$(getParent).find(".recurpay_purchase_data").attr("name","");}if(recurpay.checkout=="shopify"){if(elem.closest(appBlockSelector).length>0){elem.closest(appBlockSelector).parents(appBlockParentSelector).find(atcFormSelector).find(".recurpay_selling_plan_id").attr("name","");}else{$(getParent).find(".recurpay_selling_plan_id").attr("name","");}if(window._RestockRocket&&typeof window._RestockRocket.getSellingPlan==="function"){var getPreorderPlan=window._RestockRocket.getSellingPlan();$(".restock-rocket-form-input").attr("name","selling_plan");$(".restock-rocket-form-input").val(getPreorderPlan.shopify_selling_plan_id);$(".restock-rocket-preorder-description").show();}}}offerSavings(getParent);}
function addSubscription(btn){
let $appBlock = $(btn).closest(appBlockSelector);
let isInsideAppBlock = $appBlock.length > 0 && $(pdpSelector).closest(appBlockSelector).length > 0;
let $form = null;
if($appBlock.parents(appBlockParentSelector).length && $appBlock.parents(appBlockParentSelector).find(atcSelector).length){
$form = isInsideAppBlock ? $appBlock.parents(appBlockParentSelector).find(atcSelector).parents(atcFormSelector) : $(btn).parents(atcFormSelector);
}
else if($appBlock.closest(".product-grid__item").length && $appBlock.closest(".product-grid__item").find(atcSelector).length){
$form = isInsideAppBlock ? $appBlock.closest(".product-grid__item").find(atcSelector).parents(atcFormSelector) : $(btn).parents(atcFormSelector);
}
else{
$form = isInsideAppBlock ? $(atcSelector).parents(atcFormSelector) : $(btn).parents(atcFormSelector);
}
let $variantSelector = $form.find('[name="id"]');
let $quantitySelector = $form.find('[name="quantity"]');
let $inputSelect = isInsideAppBlock ? $appBlock.find(pdpSelector).find('[name="recurpay-input"] option:selected') : $form.find(pdpSelector).find('[name="recurpay-input"] option:selected');
let subscriptionPlanId = $inputSelect.attr('data-plan') || '';
let subscriptionPlanName = $inputSelect.attr('data-plan-name') || '';
let subscriptionPlanType = $inputSelect.attr('data-plan-type') || '';
let planVariant = $variantSelector.length > 0 ? parseInt($variantSelector.val()) : parseInt(recurpay.product.availableVariant);
let planQuantity = $quantitySelector.length > 0 ? parseInt($quantitySelector.val()) : 1;
let planParams = {};
if(recurpay.checkout == "shopify"){
var sellingPlanId = isInsideAppBlock ? $appBlock.find(pdpSelector).find('[name="recurpay-input"] option:selected').attr('data-selling-plan') : $form.find(pdpSelector).find('[name="recurpay-input"] option:selected').attr('data-selling-plan');
planParams = {
id: planVariant,
quantity: planQuantity,
selling_plan: sellingPlanId,
properties: {
'_Plan': subscriptionPlanName,
'_PlanId': subscriptionPlanId
}
}
}
else{
planParams = {
id: planVariant,
quantity: planQuantity,
properties: {
'_Plan': subscriptionPlanName,
'_PlanId': subscriptionPlanId
}
}
}
if(recurpay.checkout == "recurpay" && !recurpay.prepaidMixedCart && subscriptionPlanType == "prepaid"){
$.getJSON('/cart', function(response) {
response.items = [];
response.items.push(planParams);
recurpay.recurCart(response);
});
}
else{
if (recurpay.action == "default" && $(atcFormSelector).find(atcSelector).length){
$form.find(atcSelector).click();
}
else{
$.ajax({
type: 'POST',
url: '/cart/add.js',
dataType: 'json',
data: planParams,
success: function() {
if (recurpay.checkout == "recurpay" && recurpay.action == "checkout"){
$.getJSON('/cart', function(response) {
recurpay.recurCart(response);
});
}
else if(recurpay.action == "cart"){
document.location.href = '/cart';
}
else{
document.location.href = '/checkout';
}
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
$('[data-recurpay-error]')
.html(err.description)
.show().delay(3000).fadeOut();
}
});
}
}
}
function loadRecurpayScripts(){$.ajax({url:recurpay.scriptsAPI,type:'GET',async:true,success:function(htmlContent){if(!$.trim(htmlContent))return;var $tempDiv=$('').html(htmlContent);$tempDiv.find('style').each(function(){$('head').append($('