Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.44 KB | None | 0 0
  1. /**
  2. * Created by jvargas on 6/8/2016.
  3. */
  4.  
  5. console.log(123);
  6. var collapseOne = $('#collapseOne');
  7. var collapseTwo = $('#collapseTwo');
  8. var collapseThree = $('#collapseThree');
  9.  
  10. $(document).ready(function () {
  11. $('#card_number').mask('0#');
  12. $('#CVV').mask('0000');
  13. $("#zip").mask("00000");
  14. $("#billing_phone").mask("0#");
  15. var el = document.querySelector("#card-expiration")
  16. VMasker(el).maskPattern("99/99");
  17.  
  18. $('[data-payment-collapse]').hide();
  19. checkShippingView();
  20. doPayPal();
  21.  
  22. var $payment_form_instance = $('#payment_form'),
  23. payment_form = $payment_form_instance.parsley();
  24.  
  25. payment_form.subscribe('parsley:form:success', function (e) {
  26.  
  27. var card_number = $('#card_number');
  28. var card_number_val = card_number.val();
  29. var card_val = card_number_val.substr(card_number_val.length - 4);
  30. var card_result = card_number.validateCreditCard();
  31.  
  32. if (card_result.card_type === null){
  33. var card_type_name = ""
  34. }else{
  35. card_type_name = card_result.card_type.name;
  36. }
  37. $("[data-payment-type]").html('<span id="card_number" class="'+card_type_name+'"></span> <span class="yomama">**** **** **** **** '+card_val+'</span>');
  38.  
  39. var panel = $('[data-payment-panel]');
  40. panel.addClass("completed-step");
  41. $("#payment-panel-complete").show();
  42. $('[data-payment-collapse]').show();
  43. $('[data-payment-complete]').show();
  44.  
  45. collapseOne.collapse('hide');
  46. collapseTwo.collapse('show');
  47.  
  48.  
  49. //mobile specific
  50. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  51. $("body").animate({"scrollTop": "0px"}, 1000);
  52. }
  53. $('#nav-steps a[href="#shipping"]').tab('show');
  54.  
  55. fbq('track', 'AddPaymentInfo');
  56.  
  57. });
  58.  
  59. payment_form.subscribe('parsley:form:error', function (e) {
  60. console.log("error!")
  61. return false;
  62. });
  63.  
  64. $("#billing-continue").on("click", function () {
  65. payment_form.validate();
  66. });
  67.  
  68. var $shipping_form_instance = $('#shipping_form'),
  69. shipping_form = $shipping_form_instance.parsley();
  70.  
  71. shipping_form.subscribe('parsley:form:success', function (e) {
  72. console.log("success");
  73. addShipAddress();
  74. $("#shipping-address-review").show();
  75.  
  76. var panel = $('[data-shipping-panel]');
  77. $('[data-shipping-complete]').show();
  78. panel.addClass("completed-step");
  79. $('[data-shipping-collapse]').show();
  80.  
  81. collapseTwo.collapse('hide');
  82. collapseThree.collapse('show');
  83.  
  84. //mobile specific
  85. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  86. $("body").animate({"scrollTop": "0px"}, 1000);
  87. }
  88. $('#nav-steps a[href="#review"]').tab('show');
  89.  
  90.  
  91. });
  92.  
  93. shipping_form.subscribe('parsley:form:error', function (e) {
  94. console.log("error!")
  95. return false;
  96. });
  97.  
  98. $("#shipping-continue").on("click", function () {
  99. shipping_form.validate();
  100. });
  101.  
  102.  
  103. $(function () {
  104. $('[data-toggle="popover"]').popover({
  105. "trigger" : "hover"
  106. })
  107. })
  108. });
  109.  
  110. (function ($) {
  111. $('.spinner .btn:first-of-type').on('click', function () {
  112. $('.spinner input').val(parseInt($('.spinner input').val(), 10) + 1);
  113. });
  114. $('.spinner .btn:last-of-type').on('click', function () {
  115. $('.spinner input').val(parseInt($('.spinner input').val(), 10) - 1);
  116. });
  117. })(jQuery);
  118.  
  119. function addShipAddress() {
  120. var ship_to_address_full_name = $("input[name='ship_to_full_name']").val();
  121. var ship_to_address = $("input[name='ship_to_address']").val();
  122. var ship_to_address2 = $("input[name='ship_to_address2']").val();
  123. var ship_to_city = $("input[name='ship_to_city']").val();
  124. var ship_to_state = $("select[name='ship_to_state']").val();
  125. var ship_to_zip = $("input[name='ship_to_zip']").val();
  126.  
  127. $('[data-shipping-full-name]').html(ship_to_address_full_name);
  128. $('[data-address]').html(ship_to_address+' '+ship_to_address2);
  129. $('[data-city]').html(ship_to_city);
  130. $('[data-state]').html(ship_to_state);
  131. $('[data-zip]').html(ship_to_zip);
  132.  
  133. }
  134.  
  135. function checkShippingView(){
  136. var ship_to_address = $("input[name='ship_to_address']").val();
  137. if(ship_to_address == '') {
  138. $("#shipping-address-review").hide();
  139. $("[data-shipping-collapse]").hide();
  140. }else{
  141. addShipAddress();
  142. $("#shipping-address-review").show();
  143. $("[data-shipping-collapse]").show();
  144. }
  145. }
  146.  
  147. function doPayPal() {
  148.  
  149. if(paymentId != ''){
  150.  
  151. var panel = $('[data-payment-panel]');
  152. panel.addClass("completed-step");
  153. $("#payment-panel-complete").show();
  154. $('[data-payment-collapse]').show();
  155. $('[data-payment-complete]').show();
  156.  
  157. $("[data-payment-type]").html("<img src='https://www.victorytailgate.com/checkout-mobile/img/paypal.png'>");
  158. collapseThree.collapse("show");
  159. $('#nav-steps a[href="#review"]').tab('show');
  160.  
  161.  
  162. $.ajax({
  163. //path to php script which process data
  164. url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/paypal-confirm.php",
  165. data: {"paymentId": paymentId, "PayerID": payerID},
  166. type: 'GET',
  167. dataType: "JSON",
  168. success: function (result) {
  169. $.each(result[0], function (k, v) {
  170. //console.log(k);
  171. //console.log(v);
  172. $("input[name='" + k + "'],select[name='" + k + "']").val(v);
  173. });
  174. checkShippingView();
  175. getZip();
  176. }
  177. });
  178.  
  179. }
  180. }
  181.  
  182. $('#collapseOne').on('hidden.bs.collapse', function () {
  183. $('html, body').animate({scrollTop: $('#headingTwo').offset().top -10}, 'slow');
  184. });
  185.  
  186. $('#collapseTwo').on('hidden.bs.collapse', function () {
  187. $('html, body').animate({scrollTop: $('#headingThree').offset().top -10}, 'slow');
  188. });
  189.  
  190. $('#collapseOne').on('shown.bs.collapse', function () {
  191. $('html, body').animate({scrollTop: $('#headingOne').offset().top -10}, 'slow');
  192. });
  193.  
  194. $('#collapseTwo').on('shown.bs.collapse', function () {
  195. $('html, body').animate({scrollTop: $('#headingTwo').offset().top -10}, 'slow');
  196. });
  197. $('#collapseOne').on('show.bs.collapse', function () {
  198. var panel = $('[data-payment-panel]');
  199. panel.removeClass("completed-step");
  200. $('#collapseTwo').collapse("hide");
  201. $('#collapseThree').collapse("hide");
  202. $("#payment-panel-complete").hide();
  203. $('[data-payment-collapse]').hide();
  204. $('[data-shipping-collapse]').hide();
  205. $('[data-payment-complete]').hide();
  206. });
  207. $('#collapseTwo').on('hide.bs.collapse', function () {
  208. var panel = $('[data-shipping-panel]');
  209. panel.addClass("completed-step");
  210. });
  211. $('#collapseTwo').on('show.bs.collapse', function () {
  212. var panel = $('[data-shipping-panel]');
  213. panel.removeClass("completed-step");
  214. $('[data-shipping-complete]').hide();
  215. $("[data-shipping-collapse]").hide();
  216. $("#shipping-address-review").hide();
  217. collapseOne.collapse("hide");
  218. collapseThree.collapse("hide");
  219. $("#full-name").focus();
  220.  
  221. });
  222.  
  223. $('#collapseThree').on('show.bs.collapse', function () {
  224. var panel = $('[data-review-panel]');
  225. panel.removeClass("completed-step");
  226. });
  227.  
  228. $('#collapseThree').on('hide.bs.collapse', function () {
  229. var panel = $('[data-review-panel]');
  230. panel.addClass("completed-step");
  231. });
  232.  
  233. //do ajax request for removal of clear cart
  234. $('body').on('click', '#clear-cart', function () {
  235.  
  236. //process ajax request
  237. $.ajax({
  238. //path to php script which process data
  239. url: "https://www.victorytailgate.com/checkout-mobile/ajax/clear-cart-legacy.php",
  240. type: 'POST',
  241. dataType: "JSON",
  242. data: '',
  243. success: function (results) {
  244. if (results.status == "success") {
  245. window.location.href = '/shopping-cart.php';
  246. }
  247. else {
  248. alert(results.message);
  249. }
  250. }
  251. });
  252. return false;
  253. });
  254.  
  255. function getCartTotals() {
  256. $.ajax({
  257. //path to php script which process data
  258. url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/get-cart-totals-legacy.php",
  259. data: '',
  260. type: 'POST',
  261. dataType: "JSON",
  262. success: function (result) {
  263. $.each(result, function (k, v) {
  264. $('[data-' + k + ']').html("$" + v);
  265. });
  266. }
  267. });
  268. }
  269.  
  270. $('#zip').keyup(function () {
  271. if ($('#zip').val().length == 5) {
  272. getZip();
  273. getCartTotals();
  274. }
  275. });
  276.  
  277. function getZip(){
  278. $.ajax({
  279. //path to php script which process data
  280. url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/get-tax-rate.php",
  281. data: {"ship_to_zip": $('#zip').val()},
  282. type: 'POST',
  283. dataType: "JSON",
  284. success: function () {
  285. getCartTotals();
  286. }
  287. });
  288. }
  289.  
  290. $('body').on('click', '#shipping-continue', function () {
  291. $.ajax({
  292. //path to php script which process data
  293. url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/get-tax-rate.php",
  294. data: {"ship_to_zip": $('#zip').val()},
  295. type: 'POST',
  296. dataType: "JSON",
  297. success: function () {
  298. }
  299. });
  300. getCartTotals();
  301. });
  302.  
  303. $('body').on('change', '#state', function () {
  304.  
  305. //process ajax request
  306. $.ajax({
  307. //path to php script which process data
  308. url: "https://www.victorytailgate.com/checkout-mobile/ajax/shipstate-legacy.php",
  309. type: 'POST',
  310. dataType: "JSON",
  311. data: {"ship_to_state": $(this).val()},
  312. success: function (results) {
  313.  
  314. }
  315. });
  316. getCartTotals();
  317. return false;
  318. });
  319.  
  320. $('body').on('click', '#paypal_process', function () {
  321. $.ajax({
  322. //path to php script which process data
  323. url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/process-paypal-legacy.php",
  324. type: 'POST',
  325. dataType: "JSON",
  326. data: '',
  327. error: function () {
  328. $("#error").html("<p>Page Not Found!!</p>");
  329. },
  330. beforeSend: function () {
  331. $("#paypal_process").html('<i class="fa fa-spinner fa-spin"></i> Processing');
  332. $("#paypal_process").addClass("disabled");
  333. },
  334. success: function (results) {
  335. if (results.status == 'success') {
  336. window.location = results.message;
  337. //$("#paypal_process").html('Continue With PayPal');
  338. }
  339. else {
  340. $("#message").html('<div class="alert alert-danger">'+results.message+'</div>');
  341. $("#paypal_process").html('Continue With PayPal');
  342. $("#paypal_process").removeClass("disabled");
  343. }
  344.  
  345. }
  346. });
  347. return false;
  348. });
  349.  
  350. $('body').on('click', '#paypal_auth', function () {
  351. $("#message").html('');
  352. $.ajax({
  353. //path to php script which process data
  354. url: "https://www.victorytailgate.com/checkout-mobile/ajax/payment/get-auth-paypal.php",
  355. type: 'POST',
  356. dataType: "JSON",
  357. data: $(".test-form input,.test-form select,.test-form textarea").serialize(),
  358. error: function () {
  359. $("#error").html("<p>Page Not Found!!</p>");
  360. },
  361. beforeSend: function () {
  362. $("#paypal_auth").html('<i class="fa fa-spinner fa-spin"></i> Processing');
  363. $("#paypal_auth").addClass("disabled");
  364. },
  365. success: function (results) {
  366. if (results.status == 'success') {
  367. window.location = results.redirect_url;
  368. //$("#paypal_process").html('Continue With PayPal');
  369. }
  370. else {
  371. $("#message").html('<div class="alert alert-danger">'+results.message+'</div>');
  372. $("#paypal_auth").html('Confirm & Pay');
  373. $("#paypal_auth").removeClass("disabled");
  374. $('#nav-steps a[href="#payment"]').tab('show');
  375. $('#payment-type a[href="#payment-card"]').tab('show');
  376. $("html, body").animate({"scrollTop": "0px"}, 100);
  377. }
  378.  
  379. }
  380. });
  381. return false;
  382. });
  383.  
  384. $("body").on("click", "#authorize_auth", function() {
  385. $("#message").html('');
  386. $.ajax({
  387. //path to php script which process data
  388. url : "https://www.victorytailgate.com/checkout-mobile/ajax/payment/process-authorize-payment.php",
  389. data : $(".test-form input,.test-form select,.test-form textarea").serialize(),
  390. type: 'POST',
  391. dataType : "JSON",
  392. /*error : function() {
  393. alert("page not found!!");
  394. },
  395. */
  396. beforeSend : function() {
  397. $("#authorize_auth").html('<i class="fa fa-spinner fa-spin"></i> Processing');
  398. $("#authorize_auth").addClass("disabled");
  399. },
  400. success: function (results) {
  401. if (results.status == 'success') {
  402. window.location = results.redirect_url;
  403. }
  404. else {
  405. $("#message").html('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> '+results.message+'</div>');
  406. $("#authorize_auth").html('Confirm & Pay');
  407. $("#authorize_auth").removeClass("disabled");
  408. $('#nav-steps a[href="#payment"]').tab('show');
  409. $('#payment-type a[href="#payment-card"]').tab('show');
  410. $("html, body").animate({"scrollTop": "0px"}, 100);
  411. }
  412.  
  413. }
  414. });
  415. return (false);
  416. });
  417.  
  418. $("body").on("click", "#bigred_auth", function() {
  419. $("#message").html('');
  420. $.ajax({
  421. //path to php script which process data
  422. url : "https://www.victorytailgate.com/checkout-mobile/ajax/payment/process-bigred.php",
  423. data : $(".test-form input,.test-form select,.test-form textarea").serialize(),
  424. type: 'POST',
  425. dataType : "JSON",
  426. /*error : function() {
  427. alert("page not found!!");
  428. },
  429. */
  430. beforeSend : function() {
  431. $("#bigred_auth").html('<i class="fa fa-spinner fa-spin"></i> Processing');
  432. $("#bigred_auth").addClass("disabled");
  433. },
  434. success: function (results) {
  435. if (results.status == 'success') {
  436. window.location = results.redirect_url;
  437. }
  438. else {
  439. $("#message").html('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> '+results.message+'</div>');
  440. $("#bigred_auth").html('Confirm & Pay');
  441. $("#bigred_auth").removeClass("disabled");
  442. $('#nav-steps a[href="#payment"]').tab('show');
  443. $('#payment-type a[href="#payment-card"]').tab('show');
  444. $("html, body").animate({"scrollTop": "0px"}, 100);
  445. }
  446.  
  447. }
  448. });
  449. return (false);
  450. });
  451.  
  452. //edit payment info mobile
  453. $("body").on("click", "[data-edit-payment-info]", function(e){
  454. $("body").animate({"scrollTop": "0px"}, 1000);
  455. $('#nav-steps a[href="#payment"]').tab('show');
  456. $('#payment-type a[href="#payment-card"]').tab('show');
  457. e.preventDefault();
  458. });
  459.  
  460. //edit shipping info
  461. $("body").on("click", "[data-edit-shipping-info]", function(e){
  462. $("body").animate({"scrollTop": "0px"}, 1000);
  463. $('#nav-steps a[href="#shipping"]').tab('show');
  464. e.preventDefault();
  465. });
  466.  
  467.  
  468. //promo code
  469. $("body").on("submit", "#promo-form", function () {
  470.  
  471.  
  472. $.ajax({
  473. //path to php script which process data
  474. url: "https://www.victorytailgate.com/checkout-mobile/ajax/promo-legacy.php",
  475. data: $(this).serialize(),
  476. type: 'POST',
  477. dataType: "JSON",
  478. /*error : function() {
  479. alert("page not found!!");
  480. },
  481. */
  482. beforeSend: function () {
  483. //$('.loadingBtn').show();
  484. //$('.addCart').hide();
  485. },
  486. success: function (result) {
  487. $("#promo-text").html(result.message);
  488. getCartTotals();
  489. }
  490. });
  491. return (false);
  492. });
  493.  
  494. //remove promo code
  495. $("body").on("click", "a[data-remove-promo-code]", function () {
  496.  
  497.  
  498. $.ajax({
  499. //path to php script which process data
  500. url: "https://www.victorytailgate.com/checkout-mobile/ajax/promo-legacy.php",
  501. data: {"promo" : "remove"},
  502. type: 'POST',
  503. dataType: "JSON",
  504. /*error : function() {
  505. alert("page not found!!");
  506. },
  507. */
  508. beforeSend: function () {
  509. //$('.loadingBtn').show();
  510. //$('.addCart').hide();
  511. },
  512. success: function (result) {
  513. $("#promo-text").html(result.message);
  514. $('[name="promo"]').val("");
  515. getCartTotals();
  516. }
  517. });
  518. return (false);
  519. });
  520.  
  521. $('[name="ship_to_state"]').on("change", function(){
  522. if($(this).val() == "FL"){
  523. console.log("show");
  524. $('[name="pickup"]').prop("checked",false);
  525. $('.pickup_in_store').show();
  526. isPickup();
  527. }else{
  528. console.log("hidden");
  529. $('[name="pickup"]').prop("checked",false);
  530. $('.pickup_in_store').hide();
  531. isPickup();
  532. }
  533. });
  534.  
  535. $('[name="pickup"]').on("click", function() {
  536. isPickup();
  537. });
  538.  
  539. function isPickup(){
  540. var checked = $('[name="pickup"]').is(':checked');
  541. var v = "";
  542. if(checked){
  543. v = 1;
  544. }else{
  545. v = "";
  546. }
  547. $.ajax({
  548. type: "POST",
  549. url: "https://www.victorytailgate.com/checkout-mobile/ajax/is-pickup-legacy.php",
  550. data: { "pickup" : v },
  551. success: function(data) {
  552. getCartTotals();
  553. }
  554. });
  555. }
  556.  
  557. //promo code
  558. $("body").on("click", ".item-link.remove", function () {
  559. var bundle_id = $(this).data("bundle_id");
  560.  
  561. $.ajax({
  562. //path to php script which process data
  563. url: "https://www.victorytailgate.com/checkout-mobile/ajax/remove-cart-item.php",
  564. data: {
  565. bundle_id : bundle_id
  566. },
  567. type: 'POST',
  568. dataType: "JSON",
  569. beforeSend: function () {
  570. },
  571. success: function (result) {
  572.  
  573. if(result.status == 'success'){
  574. $("#message").html('').show();
  575. $("#message").html('<div class="alert alert-success">'+result.message+'</div>');
  576. //.fadeOut(5000, function() { $(this).empty(); });
  577.  
  578. $.each( result.cart_ids, function( key, value ) {
  579. $('[data-media="'+value+'"]').fadeOut(300, function() { $(this).remove(); });
  580. //var numItems = $('.cart_items').length;
  581. //console.log(numItems);
  582. });
  583.  
  584. $("body").animate({"scrollTop": "0px"}, 1000);
  585.  
  586. }else{
  587. $("#message").html('');
  588. alert(result.message);
  589. }
  590. getCartTotals();
  591. }
  592. });
  593. return (false);
  594. });
  595.  
  596. //promo code
  597. $("body").on("change", ".update_quantity", function () {
  598. var bundle_id = $(this).data("bundle_id");
  599. var new_value = $(this).val();
  600. $.ajax({
  601. //path to php script which process data
  602. url: "https://www.victorytailgate.com/checkout-mobile/ajax/update-cart-quantity.php",
  603. data: {
  604. bundle_id : bundle_id,
  605. quantity : new_value
  606. },
  607. type: 'POST',
  608. dataType: "JSON",
  609. beforeSend: function () {
  610. },
  611. success: function (result) {
  612.  
  613. if(result.status == 'success'){
  614. $("#message").html('').show();
  615. $("#message").html('<div class="alert alert-success">'+result.message+'</div>');
  616. //.fadeOut(5000, function() { $(this).empty(); });
  617.  
  618. $.each( result.cart_ids, function( key, value ) {
  619. $('[data-media="'+value+'"] select[name=quantity]').val(new_value);
  620. $('[data-media="'+value+'"] .media-heading.quantity ').html(new_value);
  621. });
  622.  
  623. }else{
  624. alert("Error updating quantities!");
  625. }
  626. getCartTotals();
  627. }
  628. });
  629. return (false);
  630. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement