Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by jvargas on 6/8/2016.
- */
- console.log(123);
- var collapseOne = $('#collapseOne');
- var collapseTwo = $('#collapseTwo');
- var collapseThree = $('#collapseThree');
- $(document).ready(function () {
- $('#card_number').mask('0#');
- $('#CVV').mask('0000');
- $("#zip").mask("00000");
- $("#billing_phone").mask("0#");
- var el = document.querySelector("#card-expiration")
- VMasker(el).maskPattern("99/99");
- $('[data-payment-collapse]').hide();
- checkShippingView();
- doPayPal();
- var $payment_form_instance = $('#payment_form'),
- payment_form = $payment_form_instance.parsley();
- payment_form.subscribe('parsley:form:success', function (e) {
- var card_number = $('#card_number');
- var card_number_val = card_number.val();
- var card_val = card_number_val.substr(card_number_val.length - 4);
- var card_result = card_number.validateCreditCard();
- if (card_result.card_type === null){
- var card_type_name = ""
- }else{
- card_type_name = card_result.card_type.name;
- }
- $("[data-payment-type]").html('<span id="card_number" class="'+card_type_name+'"></span> <span class="yomama">**** **** **** **** '+card_val+'</span>');
- var panel = $('[data-payment-panel]');
- panel.addClass("completed-step");
- $("#payment-panel-complete").show();
- $('[data-payment-collapse]').show();
- $('[data-payment-complete]').show();
- collapseOne.collapse('hide');
- collapseTwo.collapse('show');
- //mobile specific
- if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
- $("body").animate({"scrollTop": "0px"}, 1000);
- }
- $('#nav-steps a[href="#shipping"]').tab('show');
- fbq('track', 'AddPaymentInfo');
- });
- payment_form.subscribe('parsley:form:error', function (e) {
- console.log("error!")
- return false;
- });
- $("#billing-continue").on("click", function () {
- payment_form.validate();
- });
- var $shipping_form_instance = $('#shipping_form'),
- shipping_form = $shipping_form_instance.parsley();
- shipping_form.subscribe('parsley:form:success', function (e) {
- console.log("success");
- addShipAddress();
- $("#shipping-address-review").show();
- var panel = $('[data-shipping-panel]');
- $('[data-shipping-complete]').show();
- panel.addClass("completed-step");
- $('[data-shipping-collapse]').show();
- collapseTwo.collapse('hide');
- collapseThree.collapse('show');
- //mobile specific
- if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
- $("body").animate({"scrollTop": "0px"}, 1000);
- }
- $('#nav-steps a[href="#review"]').tab('show');
- });
- shipping_form.subscribe('parsley:form:error', function (e) {
- console.log("error!")
- return false;
- });
- $("#shipping-continue").on("click", function () {
- shipping_form.validate();
- });
- $(function () {
- $('[data-toggle="popover"]').popover({
- "trigger" : "hover"
- })
- })
- });
- (function ($) {
- $('.spinner .btn:first-of-type').on('click', function () {
- $('.spinner input').val(parseInt($('.spinner input').val(), 10) + 1);
- });
- $('.spinner .btn:last-of-type').on('click', function () {
- $('.spinner input').val(parseInt($('.spinner input').val(), 10) - 1);
- });
- })(jQuery);
- function addShipAddress() {
- var ship_to_address_full_name = $("input[name='ship_to_full_name']").val();
- var ship_to_address = $("input[name='ship_to_address']").val();
- var ship_to_address2 = $("input[name='ship_to_address2']").val();
- var ship_to_city = $("input[name='ship_to_city']").val();
- var ship_to_state = $("select[name='ship_to_state']").val();
- var ship_to_zip = $("input[name='ship_to_zip']").val();
- $('[data-shipping-full-name]').html(ship_to_address_full_name);
- $('[data-address]').html(ship_to_address+' '+ship_to_address2);
- $('[data-city]').html(ship_to_city);
- $('[data-state]').html(ship_to_state);
- $('[data-zip]').html(ship_to_zip);
- }
- function checkShippingView(){
- var ship_to_address = $("input[name='ship_to_address']").val();
- if(ship_to_address == '') {
- $("#shipping-address-review").hide();
- $("[data-shipping-collapse]").hide();
- }else{
- addShipAddress();
- $("#shipping-address-review").show();
- $("[data-shipping-collapse]").show();
- }
- }
- function doPayPal() {
- if(paymentId != ''){
- var panel = $('[data-payment-panel]');
- panel.addClass("completed-step");
- $("#payment-panel-complete").show();
- $('[data-payment-collapse]').show();
- $('[data-payment-complete]').show();
- $("[data-payment-type]").html("<img src='https://www.victorytailgate.com/checkout-mobile/img/paypal.png'>");
- collapseThree.collapse("show");
- $('#nav-steps a[href="#review"]').tab('show');
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/paypal-confirm.php",
- data: {"paymentId": paymentId, "PayerID": payerID},
- type: 'GET',
- dataType: "JSON",
- success: function (result) {
- $.each(result[0], function (k, v) {
- //console.log(k);
- //console.log(v);
- $("input[name='" + k + "'],select[name='" + k + "']").val(v);
- });
- checkShippingView();
- getZip();
- }
- });
- }
- }
- $('#collapseOne').on('hidden.bs.collapse', function () {
- $('html, body').animate({scrollTop: $('#headingTwo').offset().top -10}, 'slow');
- });
- $('#collapseTwo').on('hidden.bs.collapse', function () {
- $('html, body').animate({scrollTop: $('#headingThree').offset().top -10}, 'slow');
- });
- $('#collapseOne').on('shown.bs.collapse', function () {
- $('html, body').animate({scrollTop: $('#headingOne').offset().top -10}, 'slow');
- });
- $('#collapseTwo').on('shown.bs.collapse', function () {
- $('html, body').animate({scrollTop: $('#headingTwo').offset().top -10}, 'slow');
- });
- $('#collapseOne').on('show.bs.collapse', function () {
- var panel = $('[data-payment-panel]');
- panel.removeClass("completed-step");
- $('#collapseTwo').collapse("hide");
- $('#collapseThree').collapse("hide");
- $("#payment-panel-complete").hide();
- $('[data-payment-collapse]').hide();
- $('[data-shipping-collapse]').hide();
- $('[data-payment-complete]').hide();
- });
- $('#collapseTwo').on('hide.bs.collapse', function () {
- var panel = $('[data-shipping-panel]');
- panel.addClass("completed-step");
- });
- $('#collapseTwo').on('show.bs.collapse', function () {
- var panel = $('[data-shipping-panel]');
- panel.removeClass("completed-step");
- $('[data-shipping-complete]').hide();
- $("[data-shipping-collapse]").hide();
- $("#shipping-address-review").hide();
- collapseOne.collapse("hide");
- collapseThree.collapse("hide");
- $("#full-name").focus();
- });
- $('#collapseThree').on('show.bs.collapse', function () {
- var panel = $('[data-review-panel]');
- panel.removeClass("completed-step");
- });
- $('#collapseThree').on('hide.bs.collapse', function () {
- var panel = $('[data-review-panel]');
- panel.addClass("completed-step");
- });
- //do ajax request for removal of clear cart
- $('body').on('click', '#clear-cart', function () {
- //process ajax request
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/clear-cart-legacy.php",
- type: 'POST',
- dataType: "JSON",
- data: '',
- success: function (results) {
- if (results.status == "success") {
- window.location.href = '/shopping-cart.php';
- }
- else {
- alert(results.message);
- }
- }
- });
- return false;
- });
- function getCartTotals() {
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/get-cart-totals-legacy.php",
- data: '',
- type: 'POST',
- dataType: "JSON",
- success: function (result) {
- $.each(result, function (k, v) {
- $('[data-' + k + ']').html("$" + v);
- });
- }
- });
- }
- $('#zip').keyup(function () {
- if ($('#zip').val().length == 5) {
- getZip();
- getCartTotals();
- }
- });
- function getZip(){
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/get-tax-rate.php",
- data: {"ship_to_zip": $('#zip').val()},
- type: 'POST',
- dataType: "JSON",
- success: function () {
- getCartTotals();
- }
- });
- }
- $('body').on('click', '#shipping-continue', function () {
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/get-tax-rate.php",
- data: {"ship_to_zip": $('#zip').val()},
- type: 'POST',
- dataType: "JSON",
- success: function () {
- }
- });
- getCartTotals();
- });
- $('body').on('change', '#state', function () {
- //process ajax request
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/shipstate-legacy.php",
- type: 'POST',
- dataType: "JSON",
- data: {"ship_to_state": $(this).val()},
- success: function (results) {
- }
- });
- getCartTotals();
- return false;
- });
- $('body').on('click', '#paypal_process', function () {
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/process-paypal-legacy.php",
- type: 'POST',
- dataType: "JSON",
- data: '',
- error: function () {
- $("#error").html("<p>Page Not Found!!</p>");
- },
- beforeSend: function () {
- $("#paypal_process").html('<i class="fa fa-spinner fa-spin"></i> Processing');
- $("#paypal_process").addClass("disabled");
- },
- success: function (results) {
- if (results.status == 'success') {
- window.location = results.message;
- //$("#paypal_process").html('Continue With PayPal');
- }
- else {
- $("#message").html('<div class="alert alert-danger">'+results.message+'</div>');
- $("#paypal_process").html('Continue With PayPal');
- $("#paypal_process").removeClass("disabled");
- }
- }
- });
- return false;
- });
- $('body').on('click', '#paypal_auth', function () {
- $("#message").html('');
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/get-auth-paypal.php",
- type: 'POST',
- dataType: "JSON",
- data: $(".test-form input,.test-form select,.test-form textarea").serialize(),
- error: function () {
- $("#error").html("<p>Page Not Found!!</p>");
- },
- beforeSend: function () {
- $("#paypal_auth").html('<i class="fa fa-spinner fa-spin"></i> Processing');
- $("#paypal_auth").addClass("disabled");
- },
- success: function (results) {
- if (results.status == 'success') {
- window.location = results.redirect_url;
- //$("#paypal_process").html('Continue With PayPal');
- }
- else {
- $("#message").html('<div class="alert alert-danger">'+results.message+'</div>');
- $("#paypal_auth").html('Confirm & Pay');
- $("#paypal_auth").removeClass("disabled");
- $('#nav-steps a[href="#payment"]').tab('show');
- $('#payment-type a[href="#payment-card"]').tab('show');
- $("html, body").animate({"scrollTop": "0px"}, 100);
- }
- }
- });
- return false;
- });
- $("body").on("click", "#authorize_auth", function() {
- $("#message").html('');
- $.ajax({
- //path to php script which process data
- url : "https://www.victorytailgate.com/checkout-mobile/ajax/payment/process-authorize-payment.php",
- data : $(".test-form input,.test-form select,.test-form textarea").serialize(),
- type: 'POST',
- dataType : "JSON",
- /*error : function() {
- alert("page not found!!");
- },
- */
- beforeSend : function() {
- $("#authorize_auth").html('<i class="fa fa-spinner fa-spin"></i> Processing');
- $("#authorize_auth").addClass("disabled");
- },
- success: function (results) {
- if (results.status == 'success') {
- window.location = results.redirect_url;
- }
- else {
- $("#message").html('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> '+results.message+'</div>');
- $("#authorize_auth").html('Confirm & Pay');
- $("#authorize_auth").removeClass("disabled");
- $('#nav-steps a[href="#payment"]').tab('show');
- $('#payment-type a[href="#payment-card"]').tab('show');
- $("html, body").animate({"scrollTop": "0px"}, 100);
- }
- }
- });
- return (false);
- });
- $("body").on("click", "#bigred_auth", function() {
- $("#message").html('');
- $.ajax({
- //path to php script which process data
- url : "https://www.victorytailgate.com/checkout-mobile/ajax/payment/process-bigred.php",
- data : $(".test-form input,.test-form select,.test-form textarea").serialize(),
- type: 'POST',
- dataType : "JSON",
- /*error : function() {
- alert("page not found!!");
- },
- */
- beforeSend : function() {
- $("#bigred_auth").html('<i class="fa fa-spinner fa-spin"></i> Processing');
- $("#bigred_auth").addClass("disabled");
- },
- success: function (results) {
- if (results.status == 'success') {
- window.location = results.redirect_url;
- }
- else {
- $("#message").html('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> '+results.message+'</div>');
- $("#bigred_auth").html('Confirm & Pay');
- $("#bigred_auth").removeClass("disabled");
- $('#nav-steps a[href="#payment"]').tab('show');
- $('#payment-type a[href="#payment-card"]').tab('show');
- $("html, body").animate({"scrollTop": "0px"}, 100);
- }
- }
- });
- return (false);
- });
- //edit payment info mobile
- $("body").on("click", "[data-edit-payment-info]", function(e){
- $("body").animate({"scrollTop": "0px"}, 1000);
- $('#nav-steps a[href="#payment"]').tab('show');
- $('#payment-type a[href="#payment-card"]').tab('show');
- e.preventDefault();
- });
- //edit shipping info
- $("body").on("click", "[data-edit-shipping-info]", function(e){
- $("body").animate({"scrollTop": "0px"}, 1000);
- $('#nav-steps a[href="#shipping"]').tab('show');
- e.preventDefault();
- });
- //promo code
- $("body").on("submit", "#promo-form", function () {
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/promo-legacy.php",
- data: $(this).serialize(),
- type: 'POST',
- dataType: "JSON",
- /*error : function() {
- alert("page not found!!");
- },
- */
- beforeSend: function () {
- //$('.loadingBtn').show();
- //$('.addCart').hide();
- },
- success: function (result) {
- $("#promo-text").html(result.message);
- getCartTotals();
- }
- });
- return (false);
- });
- //remove promo code
- $("body").on("click", "a[data-remove-promo-code]", function () {
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/promo-legacy.php",
- data: {"promo" : "remove"},
- type: 'POST',
- dataType: "JSON",
- /*error : function() {
- alert("page not found!!");
- },
- */
- beforeSend: function () {
- //$('.loadingBtn').show();
- //$('.addCart').hide();
- },
- success: function (result) {
- $("#promo-text").html(result.message);
- $('[name="promo"]').val("");
- getCartTotals();
- }
- });
- return (false);
- });
- $('[name="ship_to_state"]').on("change", function(){
- if($(this).val() == "FL"){
- console.log("show");
- $('[name="pickup"]').prop("checked",false);
- $('.pickup_in_store').show();
- isPickup();
- }else{
- console.log("hidden");
- $('[name="pickup"]').prop("checked",false);
- $('.pickup_in_store').hide();
- isPickup();
- }
- });
- $('[name="pickup"]').on("click", function() {
- isPickup();
- });
- function isPickup(){
- var checked = $('[name="pickup"]').is(':checked');
- var v = "";
- if(checked){
- v = 1;
- }else{
- v = "";
- }
- $.ajax({
- type: "POST",
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/is-pickup-legacy.php",
- data: { "pickup" : v },
- success: function(data) {
- getCartTotals();
- }
- });
- }
- //promo code
- $("body").on("click", ".item-link.remove", function () {
- var bundle_id = $(this).data("bundle_id");
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/remove-cart-item.php",
- data: {
- bundle_id : bundle_id
- },
- type: 'POST',
- dataType: "JSON",
- beforeSend: function () {
- },
- success: function (result) {
- if(result.status == 'success'){
- $("#message").html('').show();
- $("#message").html('<div class="alert alert-success">'+result.message+'</div>');
- //.fadeOut(5000, function() { $(this).empty(); });
- $.each( result.cart_ids, function( key, value ) {
- $('[data-media="'+value+'"]').fadeOut(300, function() { $(this).remove(); });
- //var numItems = $('.cart_items').length;
- //console.log(numItems);
- });
- $("body").animate({"scrollTop": "0px"}, 1000);
- }else{
- $("#message").html('');
- alert(result.message);
- }
- getCartTotals();
- }
- });
- return (false);
- });
- //promo code
- $("body").on("change", ".update_quantity", function () {
- var bundle_id = $(this).data("bundle_id");
- var new_value = $(this).val();
- $.ajax({
- //path to php script which process data
- url: "https://www.victorytailgate.com/checkout-mobile/ajax/update-cart-quantity.php",
- data: {
- bundle_id : bundle_id,
- quantity : new_value
- },
- type: 'POST',
- dataType: "JSON",
- beforeSend: function () {
- },
- success: function (result) {
- if(result.status == 'success'){
- $("#message").html('').show();
- $("#message").html('<div class="alert alert-success">'+result.message+'</div>');
- //.fadeOut(5000, function() { $(this).empty(); });
- $.each( result.cart_ids, function( key, value ) {
- $('[data-media="'+value+'"] select[name=quantity]').val(new_value);
- $('[data-media="'+value+'"] .media-heading.quantity ').html(new_value);
- });
- }else{
- alert("Error updating quantities!");
- }
- getCartTotals();
- }
- });
- return (false);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement