' +
'
' +
'
' +
'Please wait...' +
'
' +
'
' +
'' +
'
' +
'
' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
' +
'' +
'' +
enableEmailVerification +
'
' +
'
' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
' +
'
' +
'
' +
'');
$jQNoConflict('#memmodal').append(modalForm);
};
$jQNoConflict('.memberships_button').each(function () {
var memButton = createButton($jQNoConflict(this).data());
$jQNoConflict('#checkout_' + $jQNoConflict(this).attr('data-billingid')).append(memButton);
});
$jQNoConflict('.membuttonclick').click(function (e) {
e.preventDefault();
var billingid = $jQNoConflict(this).attr("data-billingid"),
approot = $jQNoConflict(this).attr("data-approot"),
hash = $jQNoConflict(this).attr("data-hash"),
planid = $jQNoConflict(this).attr("data-planid"),
domain = $jQNoConflict(this).attr('data-domain'),
enableEmailVerification = $jQNoConflict(this).attr('data-enable-email-verification'),
subscriptionBox = 0,
customerId = null,
questions = [],
answers = [],
countries = [];
var stripeHandler = null;
var stripe = null;
var stripeSCAFlag = false;
var billingOptionName = '';
createModal({billingid: billingid, planid: planid, approot: approot, domain: domain, enableEmailVerification: enableEmailVerification});
$jQNoConflict.post(approot + '/front_end/purchase/checkSubscription', {
'id': planid,
'bid': billingid,
'hash': hash,
'domain': domain
}, function (response) {
if(response === 'Application uninstalled') {
$jQNoConflict('a[class="btn membuttonclick"]').attr('disabled', 'true');
$jQNoConflict('a[class="btn membuttonclick"]').remove();
$jQNoConflict("body").append('
Membership Uninstalled. Please contact store owner
');
return;
}
if (typeof response.data.stripe_sca_flag !== 'undefined' && response.data.stripe_sca_flag) {
stripeSCAFlag = response.data.stripe_sca_flag;
}
if (response.success) {
$jQNoConflict('#modalPlanName').html(response.data.plan.name + ' - ' + response.data.billing_option_name);
billingOptionName = response.data.billing_option_name;
if (response.data.plan.subscriptionBox == "1") {
subscriptionBox = 1;
$jQNoConflict('#modalSubscriptionBoxInfo').html(response.data.plan.subscriptionBoxInfo);
$jQNoConflict('#shippingCountry').html('
');
countries = response.data.countries;
$jQNoConflict.each(countries, function (key, value) {
$jQNoConflict('#shippingCountry').append('
');
});
}
if (response.data.customFields.length > 0) {
$jQNoConflict('#customFields').html('');
$jQNoConflict.each(response.data.customFields, function (key, value) {
if (value['deprecated'] != 1) {
var el = $jQNoConflict('
');
if (value['type'] == "1") {
var formEl = $jQNoConflict('
');
} else {
var formEl = $jQNoConflict('
');
}
formEl.attr('value_id', value['id']).attr('name', 'n_' + value['id']);
if (value['required'] == 1) {
formEl.addClass('form-inputs answer required');
} else {
formEl.addClass('form-inputs answer');
}
el.append(formEl);
$jQNoConflict('#customFields').append(el);
}
});
}
customerId = $jQNoConflict('.bold_customer_id').text();
$jQNoConflict('#bold-mem-modal-' + billingid).modal('show');
if ($jQNoConflict('.bold_customer_id').length) {
$jQNoConflict('.customerData').hide();
$jQNoConflict('.bold-mem-createaccount-intro').hide();
} else {
$jQNoConflict('.customerData').show();
}
if (subscriptionBox == "1") {
$jQNoConflict('.subscription').show();
} else {
$jQNoConflict('.subscription').hide();
}
if (typeof response.data.lang !== 'undefined') {
$jQNoConflict.each(response.data.lang, function (key, value) {
$jQNoConflict('#lang_' + key + '_' + billingid).text(value != null ? value : '');
});
$jQNoConflict('#boldMemSaveAccountFree' + billingid).text(response.data.lang.join_btn_free);
$jQNoConflict('#boldMemSaveAccountPayPal' + billingid).text(response.data.lang.join_btn_paypal);
$jQNoConflict('#boldMemSaveAccountStripe' + billingid).text(response.data.lang.join_btn_stripe);
}
if (response.data.stripe_pk) {
var stripeBtn = $jQNoConflict('#boldMemSaveAccountStripe' + billingid);
if (stripeSCAFlag) {
stripe = Stripe(response.data.stripe_pk);
} else {
stripeHandler = StripeCheckout.configure({
panelLabel: 'Subscribe',
allowRememberMe: 'false',
key: response.data.stripe_pk
});
}
stripeBtn.attr('data-gateway-loaded', 1);
}
if (response.data.paypal) {
paypalEnabled = true;
$jQNoConflict('#boldMemSaveAccountPayPal' + billingid).attr('data-gateway-loaded', 1);
}
if (response.data.price == 0) {
$jQNoConflict('#boldMemSaveAccountFree' + billingid).show();
$jQNoConflict('#boldMemSaveAccountStripe' + billingid).hide();
$jQNoConflict('#boldMemSaveAccountPayPal' + billingid).hide();
} else if (response.data.price < 50) {
$jQNoConflict('#boldMemSaveAccountFree' + billingid).show();
$jQNoConflict('#boldMemSaveAccountStripe' + billingid).hide();
showGatewayButton($jQNoConflict('#boldMemSaveAccountPayPal' + billingid));
} else {
$jQNoConflict('#boldMemSaveAccountFree' + billingid).hide();
showGatewayButton($jQNoConflict('#boldMemSaveAccountStripe' + billingid));
showGatewayButton($jQNoConflict('#boldMemSaveAccountPayPal' + billingid));
}
} else {
alert(response.error);
}
});
$jQNoConflict('.boldmemsaveaccount').on('click', function (e) {
var enableEnableVerification = $jQNoConflict(this).closest("form").attr('data-enable-email-verification');
if (enableEnableVerification == "1") {
var email = $jQNoConflict(this).closest("form").find('input[name="email"]').val();
var confirmEmail = $jQNoConflict(this).closest("form").find('input[name="validate_email"]').val();
if (email != confirmEmail) {
alert('Emails do not match. Please try again');
e.preventDefault();
}
}
var billingId = $jQNoConflict(this).closest("form").attr('data-billingid');
var planId = $jQNoConflict(this).closest("form").attr('data-planid');
var appRoot = $jQNoConflict(this).closest("form").attr('data-appRoot');
var button = this;
var gateway = $jQNoConflict(this).attr('data-gateway');
var gateway_id = $jQNoConflict(this).attr('data-gateway-id');
var form = $jQNoConflict(this).closest('form');
form.attr('data-gateway', gateway);
form.attr('data-gateway-id', gateway_id);
$jQNoConflict('#formbutton' + billingId).validate({
errorClass: "my-error-class",
submitHandler: function (form) {
var $form = $jQNoConflict(form);
var gateway = $form.attr('data-gateway');
var gateway_id = $form.attr('data-gateway-id');
$jQNoConflict('#customFields').find('.answer').each(function () {
questions.push($jQNoConflict(this).attr('value_id'));
answers.push($jQNoConflict(this).val());
});
var postData = {
'billing_id': billingId,
'plan_id': planId,
'questions': questions,
'answers': answers,
'domain': domain
};
postData.gateway_data = {id: gateway_id};
if ($jQNoConflict('.bold_customer_id').length) {
postData.customer_id = parseInt(customerId);
} else {
postData.first_name = $jQNoConflict('#bold-mem-first-name-' + billingId).val();
postData.last_name = $jQNoConflict('#bold-mem-last-name-' + billingId).val();
postData.email = $jQNoConflict('#bold-mem-email-' + billingId).val();
}
if (subscriptionBox == 1) {
postData.address = {
'address1': $jQNoConflict('#bold-mem-address1-' + billingId).val(),
'address2': $jQNoConflict('#bold-mem-address2-' + billingId).val(),
'province': $jQNoConflict('#formbutton' + billingId + ' #shippingProvince option:selected').val(),
'country': $jQNoConflict('#formbutton' + billingId + ' #shippingCountry option:selected').val(),
'country_name': $jQNoConflict('#formbutton' + billingId + ' #shippingCountry option:selected').text(),
'country_code': $jQNoConflict('#formbutton' + billingId + ' #shippingCountry option:selected').data('code'),
'zip': $jQNoConflict('#bold-mem-zip-' + billingId).val(),
'city': $jQNoConflict('#bold-mem-city-' + billingId).val()
};
}
var postFn = function () {
$jQNoConflict('#boldMemSaveAccountFree' + billingid).prop("disabled", true);
$jQNoConflict('#boldMemSaveAccountStripe' + billingid).prop("disabled", true);
$jQNoConflict('#boldMemSaveAccountPayPal' + billingid).prop("disabled", true);
if (postData.gateway_data.id == 0) {
$jQNoConflict('#boldMemSaveAccountFree' + billingid).attr('value', 'Loading...');
} else if (postData.gateway_data.id == 1) {
$jQNoConflict('#boldMemSaveAccountPayPal' + billingid).attr('value', 'Loading...');
} else if (postData.gateway_data.id == 2) {
$jQNoConflict('#boldMemSaveAccountStripe' + billingid).attr('value', 'Loading...');
}
$jQNoConflict.post(appRoot + '/front_end/purchase', postData,
function (response) {
if (response.error) {
$jQNoConflict('#boldMemSaveAccountStripe' + billingid).prop("disabled", false);
$jQNoConflict('#boldMemSaveAccountPayPal' + billingid).prop("disabled", false);
$jQNoConflict('#bold-mem-email-manual-error').html(response.error);
} else {
$jQNoConflict('#bold-mem-modal-content-' + billingId).hide();
$jQNoConflict('#bold-mem-modal-loading-' + billingId).show();
top.location = response.redirect_url;
}
}
);
};
if (stripeSCAFlag) {
// Calls stripe.confirmCardSetup
// If the card requires authentication Stripe shows a pop-up modal to
// prompt the user to enter authentication details without leaving your page.
var payWithCard = function (stripe, card, clientSecret) {
loading(true);
stripe.confirmCardSetup(clientSecret, {
payment_method: {
card: card
}
}).then(function (result) {
if (result.error) {
showError(result.error.message);
} else {
postData.gateway_data.stripe_token = result.setupIntent.payment_method;
postFn();
}
});
};
// Show the customer the error from Stripe if their card fails to charge
var showError = function (errorMsgText) {
loading(false);
document.querySelector("#stripe-card-error").classList.remove('hidden');
var errorMsg = document.querySelector("#stripe-card-error");
errorMsg.textContent = errorMsgText;
};
var loading = function (isLoading) {
if (isLoading) {
// Disable the button and show a spinner
document.querySelector("button").disabled = true;
document.querySelector("#stripe-spinner").classList.remove("hidden");
document.querySelector("#stripe-button-text").classList.add("hidden");
} else {
document.querySelector("button").disabled = false;
document.querySelector("#stripe-spinner").classList.add("hidden");
document.querySelector("#stripe-button-text").classList.remove("hidden");
}
};
}
if (gateway == 'stripe') {
if (stripeSCAFlag) {
var planAmount = $jQNoConflict('#modalPlanName').text();
if(!email || email == "undefined") {
email = $jQNoConflict(".modal-body").closest("form").find('input[name="email"]').val();
} else {
email = "";
}
var stripeOverlay = '
';
$jQNoConflict("body").append(stripeOverlay);
document.querySelector("#stripe-submit").disabled = true;
$jQNoConflict('#stripe-close').on('click', function (e) {
$jQNoConflict('#stripe-overlay').detach();
});
$jQNoConflict.post(appRoot + '/front_end/purchase/getSetupIntent', postData).then(function (data) {
var stripeElements = stripe.elements();
var style = {
base: {
color: "#32325d",
fontFamily: 'Arial, sans-serif',
fontSmoothing: "antialiased",
fontSize: "16px",
"::placeholder": {}
},
invalid: {
fontFamily: 'Arial, sans-serif',
color: "#fa755a",
}
};
var cardNumberElement = stripeElements.create('cardNumber', {
style: style
});
cardNumberElement.mount('#stripe-card-number-element');
var cardExpiryElement = stripeElements.create('cardExpiry', {
style: style
});
cardExpiryElement.mount('#stripe-card-expiry-element');
var cardCvcElement = stripeElements.create('cardCvc', {
style: style
});
cardCvcElement.mount('#stripe-card-cvc-element');
$jQNoConflict("#stripe-overlay").removeClass("hidden");
var removeErrors = function (event) {
document.querySelector("#stripe-submit").disabled = event.empty;
document.querySelector("#stripe-card-error").classList.add('hidden');
document.querySelector("#stripe-card-error").textContent = event.error ? event.error.message : "";
};
cardNumberElement.addEventListener("change", function (event) {
removeErrors(event);
});
cardExpiryElement.addEventListener("change", function (event) {
removeErrors(event);
});
cardCvcElement.addEventListener("change", function (event) {
removeErrors(event);
});
document.querySelector("#stripe-submit").disabled = false;
var form = document.getElementById("stripe-payment-form");
form.addEventListener("submit", function (event) {
event.preventDefault();
// Complete payment when the submit button is clicked
payWithCard(stripe, cardNumberElement, data.clientSecret);
});
});
} else {
stripeHandler.open({
name: $jQNoConflict(this).attr('data-name'),
email: postData.email,
token: function (token) {
postData.gateway_data.stripe_token = token.id;
postFn();
}
});
}
} else {
// Free and PayPal gateways
postFn();
}
}
});
});
updateProvince = function () {
var cIndex = $jQNoConflict('#shippingCountry option:selected').data('id');
$jQNoConflict('#shippingProvince').html('
');
if (countries[cIndex].provinces.length > 0) {
countries[cIndex].provinces.forEach(function (prCurr, pIndex) {
$jQNoConflict('#shippingProvince').append('
');
});
}
};
function showGatewayButton(button) {
if (button.attr('data-gateway-loaded') == 1) {
button.show();
} else {
button.hide();
}
}
});
});
}
}