• Plugin Author Diego

    (@daigo75)


    The code examples below show how to use the EU VAT Assistant to call the VIES service to validate a EU VAT number.

    /**
     * DISCLAIMER
     * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
     * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
     * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
     * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
     * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
     *
     * 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
     * in relation to it. Should you need a consultation, or assistance to customise this code, you can contact us to avail
     * of our paid consultation services: https://aelia.co/contact
     */
    
    // Basic validation of a VAT number
    $vat_number_valid = apply_filters('wc_aelia_eu_vat_assistant_validate_vat_number', $vat_number_valid, $country, $vat_number);
    
    // Possible responses
    const VAT_NUMBER_VALIDATION_NO_NUMBER = 'no-number';
    const VAT_NUMBER_VALIDATION_VALID = 'valid';
    const VAT_NUMBER_VALIDATION_NOT_VALID = 'not-valid';
    const VAT_NUMBER_VALIDATION_NON_EU = 'non-eu';
    const VAT_NUMBER_COULD_NOT_BE_VALIDATED = 'could-not-be-validated';
    const VAT_NUMBER_ENTERED_MANUALLY_NOT_VALIDATED = 'entered-manually-not-validated';
    
    // Validation of a VAT number, returning the raw response. The response will
    // be an array with the data returned by the VIES service. You will have to parse
    // such response yourself to extract the necessary data
    $response = apply_filters('wc_aelia_eu_vat_assistant_validate_vat_number', $vat_number_valid, $country, $vat_number, true);
    
    // Validation of a VAT number, returning the raw response, passing the requester VAT number. This will
    // return the consultation number as part of the response, in $response['raw_response']['requestidentifier']
    $response = apply_filters('wc_aelia_eu_vat_assistant_validate_vat_number', $vat_number_valid, $country, $vat_number, true, $requester_country, $requester_vat_number);
    
    // Sample response
    /*
    array (size=6)
      'valid' => boolean true
      'company_name' => string ''
      'company_address' => string ''
      'errors' => 
        array
          0 => string ''
      'raw_response' => 
        array
          'countrycode' => string 'GB'
          'vatnumber' => string '12345678901234'
          'requestdate' => string '2020-01-01+00:00'
          'valid' => string 'true' 
          'tradername' => string 'John, Doe'
          'tradercompanytype' => string '---'
          'traderaddress' => string '1 Main Street, London'
          'requestidentifier' => string 'WAPIAAABBBCCCDDDEEE'
          'euva_validation_result' => string 'valid'
    */
  • The topic ‘FAQ – Validate EU VAT number via code’ is closed to new replies.