Overenie IC DPH v systéme VEIS cez AJAX a jQuery

ajax jquery
ajax jquery
<script>
if (document.querySelector('.woocommerce-checkout') ){
console.log('woocomerce-checkout');

jQuery(document).ready(function( $ ){
    // Your code in here

	var form2 = $("#woocommerce_eu_vat_number");
	var form3 = $("#billing_company_wi_id");
	//var form2 = $("#billing_dic");

	overenie();
	form2.on('change', overenie);
	form3.on('change', overenie);

	function overenie (event) {
			console.log('spustene');
			  var req = $.ajax({
						url: "https://domena.sk/veis/veis2.php",
						type: 'POST',
						data: form2.serialize(),
					   error: function() {
								console.log('erroor')
								if(form2.val().length > 0){
									$('#place_order').attr("disabled", true);
									form2.css("border","1px solid red");
								}
						  		else{
									 $('#place_order').attr("disabled", false);
						   			form2.css("border","1px solid #ddd");
								}
							},
					  success: function(data, status, xhr) {
							// handle success
						},
					});

				req.done(function bbb(data) {
					var hodnota = $.parseJSON(data);
					console.log(hodnota)
					console.log(hodnota['valid'])
					if(hodnota['valid']==true){
						console.log('ideme')
						//$('#billing_company').val(hodnota['name'])
						//var mesto = hodnota['address'].split('\n')[1].split(" ")
						//$('#billing_address_1').val(hodnota['address'].split('\n')[0])
						//$('#billing_city').val(mesto[0])
						//$('#billing_postcode').val(mesto[1])
						$('#place_order').attr("disabled", false);
						form2.css("border","1px solid #ddd");
					}
					else{
 						console.log('neideme')
						form2.css("border","1px solid #ddd");

						if(form2.val().length > 0){
							$('#place_order').attr("disabled", true);
							form2.css("border","1px solid red");
						}
					}
				});
			}
	
	
});

}
</script>
<?php
$ico = $_POST['billing_vat_number'];
$icoKod = substr($ico,0,2);
$icoCislo =substr($ico,2);

$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");

// var_dump($client->checkVat(array(
//   'countryCode' => 'SK',
//   'vatNumber' => 2121115601
// )));


$request= $client->checkVat(array(
    'countryCode' => $icoKod,
    'vatNumber' => $icoCislo
));

//print_r($request);
echo json_encode($request);

Náhodné platné EU VAT čísla na testovanie:

  • SK2121115601
  • PL6292465417
  • HU12461660
    CZ27903745
  • CZ530125060
  • RO14399840
  • RO11607939

Na stránke využívam plugin WooCommerce EU VAT Number, ktorý po overení dič automaticky odráta daň.
Na profi validáciu ostatných údajov v pokladni odporúčam foxentry.com

Viac jQuery AJAX metód nájdeš na : https://www.w3schools.com/jquery/jquery_ref_ajax.asp

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená.