businessdad

EU VAT Assistant - Validate EU VAT number via code

Mar 22nd, 2020
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.96 KB | None | 0 0
  1. /**
  2.  * Aelia EU VAT Assistant for WooCommerce - Validate VAT numbers via code.
  3.  * This code shows how to use the EU VAT Assistant to call the VIES service to validate a EU VAT number.
  4.  * DISCLAIMER
  5.  * This code is free of charge and there is no warranty for it, to the extent permitted by applicable law.
  6.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  7.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  8.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  9.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  10.  *
  11.  * The code is provided as an example and it's not covered by our support service. We won't be able to offer free support
  12.  * in relation to it. Should you need a consultation, or assistance to customise this code, you can contact us to avail
  13.  * of our paid consultation services: https://aelia.co/contact
  14.  */
  15.  
  16. // Basic validation of a VAT number
  17. $vat_number_valid = apply_filters('wc_aelia_eu_vat_assistant_validate_vat_number', $vat_number_valid, $country, $vat_number);
  18.  
  19. // Possible responses
  20. const VAT_NUMBER_VALIDATION_NO_NUMBER = 'no-number';
  21. const VAT_NUMBER_VALIDATION_VALID = 'valid';
  22. const VAT_NUMBER_VALIDATION_NOT_VALID = 'not-valid';
  23. const VAT_NUMBER_VALIDATION_NON_EU = 'non-eu';
  24. const VAT_NUMBER_COULD_NOT_BE_VALIDATED = 'could-not-be-validated';
  25. const VAT_NUMBER_ENTERED_MANUALLY_NOT_VALIDATED = 'entered-manually-not-validated';
  26.  
  27. // Validation of a VAT number, returning the raw response. The response will
  28. // be an array with the data returned by the VIES service. You will have to parse
  29. // such response yourself to extract the necessary data
  30. $response = apply_filters('wc_aelia_eu_vat_assistant_validate_vat_number', $vat_number_valid, $country, $vat_number, true);
  31.  
  32. // Validation of a VAT number, returning the raw response, passing the requester VAT number. This will
  33. // return the consultation number as part of the response, in $response['raw_response']['requestidentifier']
  34. $response = apply_filters('wc_aelia_eu_vat_assistant_validate_vat_number', $vat_number_valid, $country, $vat_number, true, $requester_country, $requester_vat_number);
  35.  
  36.  
  37. // Sample response
  38. /*
  39. array (size=6)
  40.   'valid' => boolean true
  41.   'company_name' => string ''
  42.   'company_address' => string ''
  43.   'errors' =>
  44.     array
  45.       0 => string ''
  46.   'raw_response' =>
  47.     array
  48.       'countrycode' => string 'GB'
  49.       'vatnumber' => string '12345678901234'
  50.       'requestdate' => string '2020-01-01+00:00'
  51.       'valid' => string 'true'
  52.       'tradername' => string 'John, Doe'
  53.       'tradercompanytype' => string '---'
  54.       'traderaddress' => string '1 Main Street, London'
  55.       'requestidentifier' => string 'WAPIAAABBBCCCDDDEEE'
  56.       'euva_validation_result' => string 'valid'
  57. */
Add Comment
Please, Sign In to add comment