| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- $(document).ready(function() {
-
- const package_id = window.localStorage.getItem('budss_product_id');
- const qty = window.localStorage.getItem('budss_qty');
- const event_date = window.localStorage.getItem('budss_event_date');
- const event_id = window.localStorage.getItem('budss_event_time');
- const products = JSON.parse(window.localStorage.getItem('budss_products'));
- const paymentStatus = window.localStorage.getItem('paymentStarted');
-
- if (paymentStatus) {
- window.location.href = '/';
- }
-
- var events = null;
- var timer = 0;
- var remainingTime = 0;
-
- var sendObject = {};
-
- remainingTime = window.localStorage.getItem('remainingTime');
- timer = setInterval(function() {
- remainingTime--;
- window.localStorage.setItem('remainingTime', remainingTime);
- if (remainingTime < 60) {
- $('.cart_timer').css('color','#ff0000');
- }
- if (remainingTime === 0) {
- window.location.href='/#schedule';
- }
- const minutes = Math.floor(remainingTime / 60);
- const remainingSeconds = remainingTime % 60;
- $('.cart_timer').html(`${minutes}:${remainingSeconds.toString().padStart(2, '0')}`);
- },1000);
-
- $.getJSON('/api/getevents/?package_id=' + package_id + '&participants=' + qty, function(data) {
- events = data;
-
- const prod = events.find(function(item) {
- return item['id'] === parseInt(event_id) ? item : null;
- });
-
- var servicesName = '<div class="summary-title">Service Name</div>';
- servicesName += '<div class="summary-text">Dinner & Cruise<br></div>';
-
- var servicesData = event_date + ' ' + prod['time'];
-
- var servicesQty = '<div class="summary-title">Amount</div>';
- servicesQty += '<div class="summary-text">'+qty+' seat(s)</div>';
-
- var price = 0;
- sendObject['cart'] = [];
- Object.keys(products).forEach(key => {
- let prodID = parseInt(key.replace('id_',''));
- let menu = prod['products'].find(function(item) {
- return item['id'] === prodID.toString() ? item : null;
- });
- sendObject['cart'].push({
- product_id: prodID,
- qty: products[key],
- discount: 0,
- event_id: parseInt(event_id)
- });
- price += parseInt(menu['price'])*parseInt(products[key]);
- servicesName += '<div class="summary-text">'+menu['label']+'<br></div>';
- servicesQty += '<div class="summary-text">'+products[key]+' meal(s)</div>';
- });
- $('.services-name').html(servicesName);
- $('.services-data').html(servicesData);
- $('.services-qty').html(servicesQty);
- $('.sum-price').html(formatCurrencyHUFWithDots(price));
- sendObject['total'] = price;
- sendObject['language'] = 'EN';
- sendObject['back_url'] = 'https://budapestsightseeing.hu/payment/';
- sendObject['uuid'] = window.localStorage.getItem('budss_uid');
- });
-
- $('#checkbox-13').on('click', function() {
- if ($('#checkbox-13').is(':checked')) {
- $('.company-fields').show();
- }
- else {
- $('.company-fields').hide();
- }
- });
-
- $('#payButton').on('click', function() {
- $('.w-form-fail').hide();
- if (isValidEmail($('#email').val()) && $('#email').val() === $('#email2').val()) {
- sendObject['customerEmail'] = $('#email').val();
- $('#email').removeClass('input-error');
- $('#email2').removeClass('input-error');
- }
- else {
- sendObject['customerEmail'] = '';
- $('#email').addClass('input-error');
- $('#email2').addClass('input-error');
- }
- if ($('#fname').val() === '') {
- $('#fname').addClass('input-error');
- }
- else {
- $('#fname').removeClass('input-error');
- }
- if ($('#lname').val() === '') {
- $('#lname').addClass('input-error');
- }
- else {
- $('#lname').removeClass('input-error');
- }
- if ($('#country').val() === '') {
- $('#country').addClass('input-error');
- }
- else {
- $('#country').removeClass('input-error');
- }
- if ($('#zip').val() === '') {
- $('#zip').addClass('input-error');
- }
- else {
- $('#zip').removeClass('input-error');
- }
- if ($('#city').val() === '') {
- $('#city').addClass('input-error');
- }
- else {
- $('#city').removeClass('input-error');
- }
- if ($('#street').val() === '') {
- $('#street').addClass('input-error');
- }
- else {
- $('#street').removeClass('input-error');
- }
- sendObject['phone'] = $('#phone').val();
- sendObject['invoice'] = {};
- sendObject['invoice'] = {
- name: $('#fname').val() + ' ' + $('#lname').val(),
- country: $('#country option:selected').attr('data-code'),
- country_id: $('#country').val(),
- zip: $('#zip').val(),
- city: $('#city').val(),
- address: $('#street').val() + ' ' + $('#housenumber').val(),
- vatnumber: $('#tax').val(),
- company: $('#company').val()
- };
- const checkedAccept = $('#Custom-Checkbox-ON-3').is(':checked');
- if (!checkedAccept) {
- $('#Custom-Checkbox-ON-3').parent('label').addClass('checkbox-error');
- }
- else {
- $('#Custom-Checkbox-ON-3').parent('label').removeClass('checkbox-error');
- }
-
- if (sendObject['customerEmail'] !== '' &&
- sendObject['phone'] !== '' &&
- sendObject['invoice']['name'] !== '' &&
- sendObject['invoice']['country'] !== '' &&
- sendObject['invoice']['zip'] !== '' &&
- sendObject['invoice']['city'] !== '' &&
- sendObject['invoice']['address'] !== '' && checkedAccept === true) {
- $('#email-form').hide();
- $('#paymentRedirect').show();
- $('html,body').scrollTop(0);
- $.post('/api/order/', { data: JSON.stringify(sendObject) }, function(resp) {
- const results = JSON.parse(resp);
- window.localStorage.setItem('paymentStarted', true);
- window.location.href=results.paymentUrl;
- });
- }
- else {
- $('.w-form-fail').show();
- }
- });
-
- function formatCurrencyHUFWithDots(amount) {
- if (typeof amount !== 'number') {
- throw new Error('A megadott értéknek számnak kell lennie.');
- }
- return amount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.') + ' HUF';
- }
-
- function isValidEmail(email) {
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
- return emailRegex.test(email);
- }
- });
|