<%=image_tag(“https://agentadd.s3.amazonaws.com/uploads/document/document/96/Ezyagent_Logo_Teal_LargeSize_TM.png”,style: “height: 40px;”) %>
<%= f.hidden_field :stripe_payment_method_id, class: “form-control” %>
<%= f.hidden_field :step_no, value: @step_no, class: “form-control” %>
<%= f.hidden_field :pay_status, value: “active_trial”, class: “form-control” %>
<%= render “step_header”%>
” ) %>
No contracts or commitments. Cancel your
account anytime with a single click from your dashboard.
<%= render “devise/shared/links” %>
<%=image_tag(“https://agentadd.s3.amazonaws.com/uploads/document/document/96/Ezyagent_Logo_Teal_LargeSize_TM.png”,style: “height: 40px;”) %>
<% end %>
$("#company").select2({
tags: true,
placeholder: "Select Company..."
});
var currentTab = 0;
var element = document.getElementsByClassName("personal-tab");
showPersonalTab(currentTab);
function showPersonalTab(n) {
element[n].style.display = "block";
if (n == 0) {
document.getElementById("prevPersonalBtn").style.display = "none";
$("#safe-icon").addClass("hide")
} else {
document.getElementById("prevPersonalBtn").style.display = "inline";
}
if (n == (element.length - 1)) {
document.getElementById("nextPersonalBtn").innerHTML = "Start Now!";
document.getElementById("prevPersonalBtn").style.display = "none";
$("#safe-icon").removeClass("hide")
} else {
document.getElementById("nextPersonalBtn").innerHTML = "Next";
$("#nextPersonalBtn").attr("disabled", false);
}
}
function onPressPrevious() {
element[currentTab].style.display = "none";
element[currentTab].className.replace("active", "");
currentTab -= 1;
if(currentTab > 0) {
element[currentTab].className += " active";
}
showPersonalTab(currentTab);
}
async function onPressNext() {
// Exit the function if any field in the current tab is invalid:
if (currentTab == element.length) {
//...the form gets submitted:
return submitSteps();
}
if (currentTab == 0 || currentTab === 1) {
return personalValidateForm() && twoStepAuth();
}
// if(currentTab === 1) {
// return twoStepAuth();
// }
if (currentTab == 2) {
const isValid = await billingValidation()
return isValid && submitSteps();
}
showPersonalTab(currentTab);
}
function doNext() {
element[currentTab].style.display = "none";
element[currentTab].className.replace("active", "");
currentTab = currentTab + 1;
element[currentTab].className += " finish";
element[currentTab].className += " active";
showPersonalTab(currentTab);
}
function twoStepAuth() {
verification_code = currentTab== 0 ? "" : getVerificationCode();
const data = {
phone_number: $("#user_phone_number").val(),
verification_code: verification_code,
step: currentTab
}
$.ajax({
url: "/number_verification",
dataType: "json",
type: "post",
beforeSend: function (xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))
},
xhrFields: {
withCredentials: true
},
data: data,
success: function(response) {
console.log('data response::::', response);
if (!response.error) {
if(currentTab === 0){
const phone = response.phone_number
const last4digit = phone.substring(phone.length - 4, phone.length);
$("#verification-text-label").html("To continue, please enter the 6-digit verification
code sent to your phone ending in "+ last4digit+".");
return doNext();
}
if (response.status === "approved") {
return doNext();
} else {
errorMessage("Verification code is incorrect.")
}
} else {
errorMessage("please enter a valid phone number")
}
},
error: function(error) {
errorMessage(error.error)
}
});
};
function errorMessage(error){
$('#notification').removeClass('hidden');
$('#notification').html("
")
setTimeout(() => {
$('#notification').addClass('hidden');
}, 5000);
}
function submitSteps() {
var result = stripe.createPaymentMethod({
type: 'card',
card: card
}).then(function (result) {
if (result.error) {
displayError.textContent = result.error.message;
} else {
$("#user_stripe_payment_method_id").val(result.paymentMethod.id);
document.getElementById("new_user").submit()
$("#nextPersonalBtn").attr("disabled", "disabled");
}
currentTab = currentTab - n;
localStorage.setItem("currentTab", currentTab);
showPersonalTab(currentTab);
});
}