1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 
<?php
/* --------------------------------------------------------------
   VatNumberValidator.inc.php 2015-02-18 gm
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2015 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/

MainFactory::load_class('VatNumberValidatorInterface');

/**
 * Class VatNumberValidator
 *
 * This class provides methods for validating VAT numbers
 *
 * @category   System
 * @package    Customer
 * @subpackage Validation
 * @implements VatNumberValidatorInterface
 */
class VatNumberValidator implements VatNumberValidatorInterface
{
    /**
     * VAT validation.
     * @var vat_validation_ORIGIN
     */
    protected $vatValidation;


    /**
     * Initialize the VAT number validator.
     *
     * @param vat_validation_ORIGIN $vatValidation VAT validation.
     */
    public function __construct(vat_validation_ORIGIN $vatValidation = null)
    {
        $this->vatValidation = ($vatValidation) ? : new vat_validation();
    }


    /**
     * Returns the VAT number status code ID.
     *
     * @param string $p_vatNumber VAT number.
     * @param int    $p_countryId Country ID.
     * @param bool   $p_isGuest   Is customer a guest?
     *
     * @return int VAT number status code ID.
     */
    public function getVatNumberStatusCodeId($p_vatNumber, $p_countryId, $p_isGuest)
    {
        $this->vatValidation->reset($p_vatNumber, '', '', $p_countryId, (int)$p_isGuest);
        $vatInfo = $this->vatValidation->getVatInfo();

        return (int)$vatInfo['vat_id_status'];
    }


    /**
     * Returns the customer status ID.
     *
     * @param string $p_vatNumber VAT number.
     * @param int    $p_countryId Country ID.
     * @param bool   $p_isGuest   Is customer a guest?
     *
     * @return int Customer status ID.
     */
    public function getCustomerStatusId($p_vatNumber, $p_countryId, $p_isGuest)
    {
        $this->vatValidation->reset($p_vatNumber, '', '', $p_countryId, (int)$p_isGuest);
        $vatInfo = $this->vatValidation->getVatInfo();

        return (int)$vatInfo['status'];
    }


    /**
     * Returns the error status
     *
     * @param string $p_vatNumber VAT number.
     * @param int    $p_countryId Country ID.
     * @param bool   $p_isGuest   Is customer a guest?
     *
     * @return bool Error status.
     */
    public function getErrorStatus($p_vatNumber, $p_countryId, $p_isGuest)
    {
        $this->vatValidation->reset($p_vatNumber, '', '', $p_countryId, (int)$p_isGuest);
        $vatInfo = $this->vatValidation->getVatInfo();

        return $vatInfo['error'];
    }


    /**
     * Writes the validation results to cache.
     *
     * @param string $p_vatNumber VAT number.
     * @param int    $p_countryId Country ID.
     * @param bool   $p_isGuest   Is customer a guest?
     *
     * TODO Write validation results to cache.
     */
    protected function _putValidationCache($p_vatNumber, $p_countryId, $p_isGuest)
    {
        /*
        $coo_vat_validation = new vat_validation($vatNumber, '', '', $country->getId(), $p_guest);

        $customerStatus = $coo_vat_validation->vat_info['status'];
        $numberStatus = $coo_vat_validation->vat_info['vat_id_status'];
        $infoError = $coo_vat_validation->vat_info['error'];
        */
    }
}