(function($) { $(document).ready(function(){ //console.log('abc'); codes_list = {"fr":{"company":"Alphatrad France","payment_form_url":"https:\/\/www.alphatrad.fr\/paiement-securise","sites":["fr"]},"es":{"company":"Alphatrad Spain","payment_form_url":"https:\/\/www.alphatrad.es\/formulario-de-pago","sites":["es","cat"]},"de":{"company":"Alphatrad Germany","payment_form_url":"https:\/\/www.alphatrad.de\/online-zahlung","sites":["de"]},"at":{"company":"Alphatrad Austria","payment_form_url":"https:\/\/www.alphatrad.at\/online-zahlung","sites":["at"]},"fdk":{"company":"Alphatrad Denmark","payment_form_url":"http:\/\/optilingua-oversaettelser.dk\/sikker-betaling","sites":["dk"]},"it":{"company":"Traducta Italy","payment_form_url":"https:\/\/www.traducta.it\/pagamento-sicuro-servizi-traduzioni","sites":["it"]},"lu":{"company":"Alphatrad Luxembourg","payment_form_url":"http:\/\/www.alphatrad.lu\/paiement-securise","sites":["lu"]},"nl":{"company":"Traducta Netherlands","payment_form_url":"http:\/\/traducta.nl\/veilig-betalen","sites":["nl"]},"pt":{"company":"Alphatrad Portugal","payment_form_url":"https:\/\/www.alphatrad.pt\/pagamento-seguro","sites":["pt"]},"ch":{"company":"Traducta Switzerland","payment_form_url":"https:\/\/www.traducta.ch\/online-zahlung","sites":["ch"]},"gb":{"company":"Alphatrad UK","payment_form_url":"http:\/\/www.alphatrad.co.uk\/online-payment","sites":["uk"]},"v":{"company":"ViaVerbia Belgium","payment_form_url":"https:\/\/viaverbia.be\/veilig-betalen","sites":["be","luv"]}}; site = $('input[name="site"]').val(); remove_error_messages(); // User may change the language of the form // we keep this selection in a cookie for a while $('#user-payment-language input').click(function(){ var lang = $(this).val(); $.cookie('user_pay_lang', lang, { expires: 30, path: '/' }); location.reload(); }); $("#submit_button").click(function() { $('.check_errors_msg').remove(); var checkErrors = false; var condError = false; var msg = ''; if (!$("input[name=type_dossier]").is(":checked")){ $('#type_dossier_c').prepend('Document type not selected'); checkErrors = true; } if ($('#document-number-p1').val() == '' || $('#document-number-p2').val() == '') { $('#document-number-c').append('Required field'); $('#document-number').addClass('has-error'); checkErrors = true; } else { var code = $('#document-number-p1').val(); // check if the number is valid for this site //console.log(site); //console.log(destination); if ( !check_code_this(code)) { // the document number is not valid for this site // check if it is valid for another site // if yes then suggest the new site payment page url var other = check_code_other(code); //console.log(other); if(other) { // code not valid for this site, suggest another site var m = 'This Invoice/Quotation belongs to {COMPANY}, for payment please go to {URL}.'; m = m.replace('{COMPANY}', other['company']); m = m.replace(new RegExp('{URL}', 'g'), other['payment_form_url']); $('#document-number-c').append(''+m+''); $('#document-number').addClass('has-error'); checkErrors = true; } else { // code not valid at all //console.log('code not valid'); $('#document-number-c').append('The document number is not valid. Please check the number on your invoice or quotation.'); $('#document-number').addClass('has-error'); checkErrors = true; } } // check if the number is valid for another site else { } //console.log(code_check); } if ($('#amount').val() == '') { $('#amount_c').append('Enter the amount'); $('#amount').addClass('has-error'); checkErrors = true; } for (var i in fields) { var f = fields[i]; if ($('#'+f).val() == '') { $('#'+f+'_c').append('Required field'); $('#'+f).addClass('has-error'); checkErrors = true; } } // payment method selection if (!$("input[name=payment_method]").is(":checked")){ $('#payment_method_c').prepend('Please select payment method'); checkErrors = true; } if(!checkErrors) { var conno = $('input[rel=condition]').length; if(conno > 1) { msg += 'Please check the boxes above to continue.'; } else { msg += 'Please check the box above to continue.'; } $('input[rel=condition]').each(function() { if(!$(this).is(':checked')) { checkErrors = true; } }); if(checkErrors) { show_msg(msg); return false; } else { // depending on the choosen payment method we have different actions var pm = $("input[name=payment_method]:checked").val(); if(pm == 'cic') { // retrieve mac $.ajax({ type: "POST", dataType: "json", url: "/bo/payment/"+codeVersion+"/ajax/cic-get-mac.php", cache: false, data: $('#payment_form').serialize() }) .done(function(data) { if(data.errors == 'false') { // populate control fields to form and submit $('#montant').val(data.amount); $('#reference').val(data.reference); $('#MAC').val(data.mac); $('#texte-libre').val(data.info); $('#url_retour_ok').val(data.urlOK); $('#url_retour_err').val(data.urlKO); $('#version').val(data.version); $('#TPE').val(data.TPE); $('#url_retour').val(data.urlKO); $('#url_retour_ok').val(data.urlOK); $('#url_retour_err').val(data.urlKO); $('#lgue').val(data.lgue); $('#societe').val(data.societe); // set form target to cic server $('#payment_form').attr('action', data.cicUrl); // submit form $("#payment_form").submit(); } else { alert('Errors'); } }); } else if(pm == 'paypal'){ $("#payment_form").submit(); } else { alert('Payment method error'); return false; } } return false; } else { msg = 'There were errors processing the form. Please correct them and submit it again. Thank you!'; show_msg(msg); return false; } }); }); })(jQuery);