$(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 = '
Service Name
'; servicesName += '
Dinner & Cruise
'; var servicesData = event_date + ' ' + prod['time']; var servicesQty = '
Amount
'; servicesQty += '
'+qty+' seat(s)
'; 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 += '
'+menu['label']+'
'; servicesQty += '
'+products[key]+' meal(s)
'; }); $('.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); } });