File: example.php

Recommend this page to a friend!
  Classes of Pierre-Henry Soria  >  PHP EU VAT Validation  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP EU VAT Validation
Validate VAT number using VIES API
Author: By
Last change: Bump Year (copyright header)
Date: 1 year ago
Size: 965 bytes
 

Contents

Class file image Download
<?php
/**
 * @author Pierre-Henry Soria <pierrehenrysoria@gmail.com>
 * @copyright (c) 2017-2019, Pierre-Henry Soria. All Rights Reserved.
 * @license GNU General Public License; <https://www.gnu.org/licenses/gpl-3.0.en.html>
 */

require 'src/autoloader.php';

use
PH7\Eu\Vat\Provider\Europa;
use
PH7\Eu\Vat\Validator;

$oVatValidator = new Validator(new Europa, '0472429986', 'BE');

if (
$oVatValidator->check()) {
   
$sRequestDate = $oVatValidator->getRequestDate();
   
// Optional, format the date
   
$sFormattedRequestDate = (new DateTime)->format('d-m-Y');

    echo
'Business Name: ' . $oVatValidator->getName() . '<br />';
    echo
'Address: ' . $oVatValidator->getAddress() . '<br />';
    echo
'Request Date: ' . $sFormattedRequestDate . '<br />';
    echo
'Member State: ' . $oVatValidator->getCountryCode() . '<br />';
    echo
'VAT Number: ' . $oVatValidator->getVatNumber() . '<br />';
} else {
    echo
'Invalid VAT number';
}


For more information send a message to info at phpclasses dot org.