Warning: Undefined array key "HTTP_ACCEPT_LANGUAGE" in /home/jyvy9879/WWW_intuisphere/webapp-v2/php/Localization.php on line 55
// Configuration defaults
// Traductions JavaScript
const TRANSLATIONS = {
"select_your_country": "Select your country",
"european_union": "European Union",
"outside_european_union": "Outside the European Union",
"please_enter_email": "Please enter your e-mail address.",
"please_enter_valid_email": "Please enter a valid e-mail address.",
"please_select_country": "Please select your country.",
"vat_number_min_8_chars": "The VAT number must contain at least 8 characters.",
"vat_number_format_error": "The VAT number must begin with the country code (2 letters) followed by figures. Example: FR12345678901",
"please_enter_full_name": "Please enter the full name or the company name.",
"please_enter_address_line_1": "Please enter the address (line 1).",
"please_enter_postal_code": "Please enter the postcode.",
"postal_code_too_short": "The postcode seems too short.",
"please_enter_city": "Please enter the city.",
"city_name_too_short": "The name of the town seems too short.",
"email_address": "E-mail address",
"payment_preparation": "Preparing payment",
"creating_payment_session": "Creating your secure payment session",
"bank_transfer": "Bank transfer",
"loading_banking_information": "Loading bank details",
"payment_error": "Payment error",
"payment_session_error": "An error has occurred while creating your payment session.",
"try_again": "Try again",
"back": "Back to",
"error_loading_banking": "Error loading bank details.",
"beneficiary": "Beneficiary",
"iban": "IBAN",
"bic": "BIC",
"bank": "Bank",
"address": "Address",
"important": "IMPORTANT",
"what_happens_next": "What happens next",
"processing_time": "Processing time",
"note": "Note",
"test_data_filled": "Test data completed!",
"bank_details": "Bank details",
"consent_required_error": "You must accept the waiver of the right of withdrawal to continue."
};
function generateRequestUUID() {
const timestamp = Date.now();
const random = Math.random().toString(36).substr(2, 9);
return `req_${timestamp}_${random}`;
}
function initializeCountries() {
/*
const countrySelect = document.getElementById('country');
countrySelect.innerHTML = '';
const euGroup = document.createElement('optgroup');
euGroup.label = TRANSLATIONS['european_union'];
const nonEuGroup = document.createElement('optgroup');
nonEuGroup.label = TRANSLATIONS['outside_european_union'];
COUNTRIES.forEach(country => {
const option = document.createElement('option');
option.value = country.code;
option.textContent = country.name;
option.setAttribute('data-eu', (country.isEU) ? "true" : "false");
if (country.isEU) {
euGroup.appendChild(option);
} else {
nonEuGroup.appendChild(option);
}
});
countrySelect.appendChild(euGroup);
countrySelect.appendChild(nonEuGroup);
*/
}
function initializeCurrencies() {
const currencySelect = document.getElementById('currency');
currencySelect.innerHTML = '';
CURRENCIES.forEach(currency => {
const option = document.createElement('option');
option.value = currency.code;
option.textContent = currency.name;
currencySelect.appendChild(option);
});
}
function initializeEmail() {
const emailInput = document.getElementById('email');
const emailLabel = document.getElementById('emailLabel');
if (REQUIRED_EMAIL && REQUIRED_EMAIL.trim() !== '') {
emailInput.value = REQUIRED_EMAIL;
emailInput.readOnly = true;
emailInput.style.backgroundColor = '#f8f9fa';
emailInput.style.cursor = 'not-allowed';
emailLabel.textContent = TRANSLATIONS['email_address'];
emailInput.removeAttribute('required');
}
}
function showVatConfirmationModal() {
document.getElementById('vatConfirmationModal').style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closeVatModal() {
document.getElementById('vatConfirmationModal').style.display = 'none';
document.body.style.overflow = 'auto';
document.getElementById('vatNumber').focus();
document.getElementById('vatNumber').scrollIntoView({ behavior: 'smooth', block: 'center' });
}
function confirmWithoutVat() {
vatConfirmed = true;
document.getElementById('vatConfirmationModal').style.display = 'none';
document.body.style.overflow = 'auto';
proceedToNextStep();
}
function proceedToNextStep() {
document.getElementById(`step${currentStep}`).classList.remove('active');
currentStep = 2;
document.getElementById(`step${currentStep}`).classList.add('active');
updateProgress();
updatePricing();
updatePaymentOptions();
}
function nextStep(step) {
if (validateCurrentStep()) {
if (currentStep === 1 && step === 2)
{
const country = countrySelector.getSelectedCountry().toUpperCase()
const vatNumber = document.getElementById('vatNumber')
let num_tva = vatNumber.value;
num_tva = num_tva.toUpperCase().replace(/[^A-Z0-9]/g, '');
if (selectedCustomerType === 'business' && !num_tva && !vatConfirmed && isEuCountry) {
showVatConfirmationModal();
return;
}
}
document.getElementById(`step${currentStep}`).classList.remove('active');
currentStep = step;
document.getElementById(`step${currentStep}`).classList.add('active');
updateProgress();
if (step === 2) {
updatePricing();
updatePaymentOptions();
}
if (step === 3) {
setupStep3();
}
}
}
function previousStep(step) {
if (step === 1) {
vatConfirmed = false;
}
if (currentStep === 3) {
resetStep3();
}
document.getElementById(`step${currentStep}`).classList.remove('active');
currentStep = step;
document.getElementById(`step${currentStep}`).classList.add('active');
updateProgress();
}
function resetStep3() {
const step3 = document.getElementById('step3');
step3.innerHTML = `
🔒 Secure payment
You will be redirected to our secure payment partner Stripe to complete your purchase.
💼 Bank details
Beneficiary: Intuisphere
IBAN: FR76 1234 5678 9012 3456 789
BIC: ABCDFRPP
Bank: Example Bank
⚠️ IMPORTANT
Please include this reference in your bank transfer:
WEB-2024-001234
💡 What happens next?
- Your licence will be activated on receipt of the transfer
- You will receive a confirmation e-mail with your activation codes
- Average processing time: 1-2 working days (SEPA) or 3-5 days (International)
`;
updatePricing();
}
function updateProgress() {
const progress = (currentStep / 3) * 100;
document.getElementById('progressFill').style.width = `${progress}%`;
//ajout pour update le prix special SEPA
updatePricing()
}
function validateCurrentStep() {
if (currentStep === 1) {
const email = document.getElementById('email').value.trim();
//const country = document.getElementById('country').value.trim();
const country = countrySelector.getSelectedCountry()
// isEuCountry = WaEuropeInfos.isInEurope(country);
const vatNumber = document.getElementById('vatNumber').value.replace(/[\s\.\-_\/\\,;:]+/g, '');
document.getElementById('email').value = email;
document.getElementById('vatNumber').value = vatNumber;
const fullName = document.getElementById('fullName').value.trim();
document.getElementById('fullName').value = fullName;
if (!document.getElementById('email').readOnly) {
if (!email) {
alert(TRANSLATIONS['please_enter_email']);
document.getElementById('email').focus();
document.getElementById('email').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
if (!isValidEmail(email)) {
alert(TRANSLATIONS['please_enter_valid_email']);
document.getElementById('email').focus();
document.getElementById('email').select();
document.getElementById('email').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
}
/*
if (!country) {
alert(TRANSLATIONS['please_select_country']);
document.getElementById('country').focus();
document.getElementById('country').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
*/
if (vatNumber)
{
const country = countrySelector.getSelectedCountry().toUpperCase()
const vatNumber = document.getElementById('vatNumber')
let num_tva = vatNumber.value;
num_tva = num_tva.toUpperCase().replace(/[^A-Z0-9]/g, '');
//vatNumber.value = num_tva;
// {valid: boolean, message: string, formatted: string}
const res = Wa_IntraVatNumber.validateWithPrefix(num_tva,country)
if (res.valid==false)
{
alert(res.message)
document.getElementById('vatNumber').focus();
document.getElementById('vatNumber').select();
document.getElementById('vatNumber').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
vatNumber.value = Wa_IntraVatNumber.format(res.formatted,country);
//alert(JSON.stringify(res))
/*
if (vatNumber.length < 8) {
alert(TRANSLATIONS['vat_number_min_8_chars']);
document.getElementById('vatNumber').focus();
document.getElementById('vatNumber').select();
document.getElementById('vatNumber').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
const vatRegex = /^[A-Z]{2}[0-9A-Z]{2,}$/;
if (!vatRegex.test(vatNumber.toUpperCase())) {
alert(TRANSLATIONS['vat_number_format_error']);
document.getElementById('vatNumber').focus();
document.getElementById('vatNumber').select();
document.getElementById('vatNumber').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
*/
//document.getElementById('vatNumber').value = vatNumber.toUpperCase();
}
if (!fullName) {
alert(TRANSLATIONS['please_enter_full_name']);
document.getElementById('fullName').focus();
document.getElementById('fullName').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
if (selectedCustomerType === 'business') {
const street1 = document.getElementById('street1').value.trim();
const street2 = document.getElementById('street2').value.trim();
const zipCode = document.getElementById('zipCode').value.trim();
const city = document.getElementById('city').value.trim();
document.getElementById('street1').value = street1;
document.getElementById('street2').value = street2;
document.getElementById('zipCode').value = zipCode;
document.getElementById('city').value = city;
if (!street1) {
alert(TRANSLATIONS['please_enter_address_line_1']);
document.getElementById('street1').focus();
document.getElementById('street1').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
if (!zipCode) {
alert(TRANSLATIONS['please_enter_postal_code']);
document.getElementById('zipCode').focus();
document.getElementById('zipCode').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
if (zipCode.length < 3) {
alert(TRANSLATIONS['postal_code_too_short']);
document.getElementById('zipCode').focus();
document.getElementById('zipCode').select();
document.getElementById('zipCode').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
if (!city) {
alert(TRANSLATIONS['please_enter_city']);
document.getElementById('city').focus();
document.getElementById('city').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
if (city.length < 2) {
alert(TRANSLATIONS['city_name_too_short']);
document.getElementById('city').focus();
document.getElementById('city').select();
document.getElementById('city').scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
}
}
if (currentStep === 2)
{
const consentCheckbox = document.getElementById('consentWithdrawal');
const consentError = document.getElementById('consentError');
const consentBlock = document.getElementById('consentBlock');
if (consentCheckbox.checked == false)
{
consentError.style.display = 'block';
consentBlock.classList.add('buynow-consent-block--error');
consentBlock.scrollIntoView({ behavior: 'smooth', block: 'center' });
return false;
}
consentError.style.display = 'none';
consentBlock.classList.remove('buynow-consent-block--error');
}
return true;
}
function isValidEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
function updatePaymentOptions() {
const currencyCode = document.getElementById('currency').value;
const sepaOption = document.getElementById('sepaOption');
const internationalOption = document.getElementById('internationalOption');
if (currencyCode !== 'EUR') {
sepaOption.style.display = 'none';
if (selectedPayment === 'sepa') {
selectedPayment = 'card';
document.querySelectorAll('.payment-option').forEach(opt => opt.classList.remove('selected'));
document.querySelector('[data-payment="card"]').classList.add('selected');
}
}
else {
sepaOption.style.display = '';
}
if (!SHOW_INTERNATIONAL_TRANSFER) {
internationalOption.style.display = 'none';
if (selectedPayment === 'international') {
selectedPayment = 'card';
document.querySelectorAll('.payment-option').forEach(opt => opt.classList.remove('selected'));
document.querySelector('[data-payment="card"]').classList.add('selected');
}
} else {
internationalOption.style.display = '';
}
// alert('updatePaymentOptions')
}
function updateFieldTvaNumber()
{
const currencyCode = document.getElementById('currency').value;
const country = countrySelector.getSelectedCountry()
// isEuCountry = WaEuropeInfos.isInEurope(country);
const b_is_UE = WaEuropeInfos.isInEurope(country);
const vatFieldContainer = document.getElementById('vatFieldContainer')
const vatNumber = document.getElementById('vatNumber')
const vatCountry = Wa_IntraVatNumber.resolveVatCountry(country);
const placeholder = Wa_IntraVatNumber.getExample(vatCountry);
vatNumber.placeholder = "Ex : "+Wa_IntraVatNumber.format(placeholder,vatCountry)
if (b_is_UE)
{
vatFieldContainer.style.display = 'flex'
}
else
{
vatFieldContainer.style.display = 'none'
vatNumber.value="";
}
}
function updatePricing() {
const currencyCode = document.getElementById('currency').value;
const currency = CURRENCIES.find(c => c.code === currencyCode);
if (!currency) return;
/////
const sepaOption = document.getElementById('sepaOption');
const internationalOption = document.getElementById('internationalOption');
////////
// alert(JSON.stringify(currency))
const { basePrice, originalPrice, symbol ,basePrice_SEPA, originalPrice_SEPA} = currency;
const showOriginalPrice = basePrice !== originalPrice;
let priceText = basePrice;
let originalPriceText = originalPrice;
if (selectedPayment == 'sepa')
{
priceText = basePrice_SEPA;
originalPriceText = originalPrice_SEPA;
}
function updatePrice(priceId, originalPriceId) {
const priceEl = document.getElementById(priceId);
const originalPriceEl = document.getElementById(originalPriceId);
if (priceEl) {
priceEl.textContent = priceText;
}
if (originalPriceEl) {
originalPriceEl.textContent = originalPriceText;
originalPriceEl.style.display = showOriginalPrice ? 'inline' : 'none';
}
}
updatePrice('totalPriceStep1', 'originalPriceStep1');
updatePrice('totalPrice', 'originalPrice');
updatePrice('finalPrice', 'originalPriceFinal');
updatePrice('bankTransferPrice', 'originalPriceBank');
}
function setupStep3() {
if (selectedPayment === 'card') {
processCardPayment();
} else {
showBankTransferStep();
}
}
function processCardPayment() {
const formData = createFormData();
document.getElementById(`step${currentStep}`).innerHTML = `
🔒 ${TRANSLATIONS['payment_preparation']}
⏳ ${TRANSLATIONS['creating_payment_session']}...
`;
fetch('api/stripe-payment.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(formData)
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP Error: ${response.status}`);
}
return response.json();
})
.then(stripeData => {
return stripe.redirectToCheckout({ sessionId: stripeData.sessionId });
})
.catch(error => {
console.error('Payment error:', error);
displayPaymentError();
});
}
function showBankTransferStep() {
const cardPayment = document.getElementById('cardPayment');
const bankTransfer = document.getElementById('bankTransfer');
const step3Title = document.getElementById('step3Title');
cardPayment.style.display = 'none';
bankTransfer.style.display = 'block';
step3Title.textContent = '🏦 ' + TRANSLATIONS['bank_transfer'];
bankTransfer.innerHTML = '⏳ ' + TRANSLATIONS['loading_banking_information'] + '...
';
loadBankTransferData();
}
function loadBankTransferData() {
const formData = createFormData();
const endpoint = selectedPayment === 'sepa' ? 'api/bank-sepa.php' : 'api/bank-international.php';
fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(formData)
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP Error: ${response.status}`);
}
return response.json();
})
.then(bankData => {
displayBankTransferInfo(bankData);
})
.catch(error => {
console.error('Loading error:', error);
displayBankTransferError();
});
}
function displayBankTransferInfo(bankData) {
const orderRef = bankData.transaction_id;
const bankTransferHtml = `
💼 ${TRANSLATIONS['bank_details']}
${TRANSLATIONS['beneficiary']}: ${bankData.beneficiary}
${TRANSLATIONS['iban']}: ${bankData.iban}
${TRANSLATIONS['bic']}: ${bankData.bic}
${TRANSLATIONS['bank']}: ${bankData.bankName}
${bankData.address ? `
${TRANSLATIONS['address']}: ${bankData.address}` : ''}
⚠️ ${TRANSLATIONS['important']}
Please include this reference in your bank transfer:
${orderRef}
💡 ${TRANSLATIONS['what_happens_next']}?
- ${bankData.instructions.activation}
- ${bankData.instructions.confirmation}
- ${TRANSLATIONS['processing_time']}: ${bankData.instructions.delay}
${bankData.instructions.note ? `
${TRANSLATIONS['note']}: ${bankData.instructions.note}
` : ''}
`;
document.getElementById('bankTransfer').innerHTML = bankTransferHtml;
updatePricing();
}
function displayPaymentError() {
document.getElementById(`step${currentStep}`).innerHTML = `
❌ ${TRANSLATIONS['payment_error']}
${TRANSLATIONS['payment_session_error']}
`;
}
function displayBankTransferError() {
const errorHtml = `
❌ ${TRANSLATIONS['error_loading_banking']}
`;
document.getElementById('bankTransfer').innerHTML = errorHtml;
}
function redirectToStripe() {
console.log('Automatic redirection to Stripe...');
}
function fillTestData() {
document.getElementById('email').value = 'test@webacappella.com';
//document.getElementById('country').value = 'FR';
//const countrySelect = document.getElementById('country');
const selected_country = countrySelector.getSelectedCountry()
/*
const selectedOption = countrySelect.options[countrySelect.selectedIndex];
isEuCountry = selectedOption.getAttribute('data-eu') === 'true';
*/
isEuCountry = WaEuropeInfos.isInEurope(selected_country);
updatePricing();
const businessOption = document.querySelector('[data-type="business"]');
if (businessOption) {
const customerOptions = document.querySelectorAll('.customer-option');
customerOptions.forEach(option => option.classList.remove('selected'));
businessOption.classList.add('selected');
selectedCustomerType = 'business';
const businessFields = document.getElementById('businessFields');
const vatFieldContainer = document.getElementById('vatFieldContainer');
businessFields.classList.add('show');
vatFieldContainer.classList.add('show');
}
updateFieldTvaNumber();
setTimeout(() => {
document.getElementById('fullName').value = 'WebServices France LLC';
document.getElementById('street1').value = '15 rue de la République';
document.getElementById('street2').value = 'Building A - 2nd floor';
document.getElementById('zipCode').value = '33130';
document.getElementById('city').value = 'Bègles';
}, 100);
console.log(TRANSLATIONS['test_data_filled']);
}
window.onload = function() {
requestUuid = generateRequestUUID();
console.log('Request UUID:', requestUuid);
initializeCountries();
initializeCurrencies();
initializeEmail();
countrySelector.selectByCode(DEFAULT_COUNTRY)
document.getElementById('currency').value = DEFAULT_CURRENCY;
const selected_country = countrySelector.getSelectedCountry();
isEuCountry = WaEuropeInfos.isInEurope(selected_country);
updatePricing();
updatePaymentOptions();
updateFieldTvaNumber();
const customerOptions = document.querySelectorAll('.customer-option');
customerOptions.forEach(option => {
option.onclick = function() {
customerOptions.forEach(opt => opt.classList.remove('selected'));
this.classList.add('selected');
selectedCustomerType = this.getAttribute('data-type');
const businessFields = document.getElementById('businessFields');
const vatFieldContainer = document.getElementById('vatFieldContainer');
if (selectedCustomerType === 'business') {
businessFields.classList.add('show');
vatFieldContainer.classList.add('show');
} else {
businessFields.classList.remove('show');
vatFieldContainer.classList.remove('show');
}
vatConfirmed = false;
};
});
const container_select_country = document.getElementById('countryPicker1');
container_select_country.addEventListener('countrySelected', function(event) {
const selected_country = event.detail.country.code;
isEuCountry = WaEuropeInfos.isInEurope(selected_country);
updatePricing();
vatConfirmed = false;
// const code_country=selectedOption.value
const prefer_currency = WaCurrency.preferedCurrency(selected_country);
document.getElementById('currency').value = prefer_currency;
updatePricing();
updatePaymentOptions();
updateFieldTvaNumber();
});
document.getElementById('currency').onchange = function() {
updatePricing();
updatePaymentOptions();
updateFieldTvaNumber();
};
const paymentOptions = document.querySelectorAll('.payment-option');
paymentOptions.forEach(option => {
option.onclick = function() {
if (this.style.display === 'none') return;
paymentOptions.forEach(opt => opt.classList.remove('selected'));
this.classList.add('selected');
selectedPayment = this.getAttribute('data-payment');
updatePricing();
};
});
document.getElementById('vatNumber').oninput = function() {
vatConfirmed = false;
};
document.getElementById('consentWithdrawal').onchange = function()
{
if (this.checked)
{
document.getElementById('consentError').style.display = 'none';
document.getElementById('consentBlock').classList.remove('buynow-consent-block--error');
}
};
};
// Fonction pour copier la référence
function copyReference(reference) {
navigator.clipboard.writeText(reference).then(() => {
// Feedback visuel
const btn = event.target;
const originalText = btn.innerHTML;
btn.innerHTML = '✓ Copié !';
btn.style.background = '#10b981';
setTimeout(() => {
btn.innerHTML = originalText;
btn.style.background = '';
}, 2000);
}).catch(err => {
console.error('Erreur copie:', err);
alert('Référence : ' + reference);
});
}