1 <?php
2 /* --------------------------------------------------------------
3 VatNumberValidator.inc.php 2015-02-18 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('VatNumberValidatorInterface');
13
14 /**
15 * Class VatNumberValidator
16 *
17 * This class provides methods for validating VAT numbers
18 *
19 * @category System
20 * @package Customer
21 * @subpackage Validation
22 * @implements VatNumberValidatorInterface
23 */
24 class VatNumberValidator implements VatNumberValidatorInterface
25 {
26 /**
27 * VAT validation.
28 * @var vat_validation_ORIGIN
29 */
30 protected $vatValidation;
31
32
33 /**
34 * Initialize the VAT number validator.
35 *
36 * @param vat_validation_ORIGIN $vatValidation VAT validation.
37 */
38 public function __construct(vat_validation_ORIGIN $vatValidation = null)
39 {
40 $this->vatValidation = ($vatValidation) ? : new vat_validation();
41 }
42
43
44 /**
45 * Returns the VAT number status code ID.
46 *
47 * @param string $p_vatNumber VAT number.
48 * @param int $p_countryId Country ID.
49 * @param bool $p_isGuest Is customer a guest?
50 *
51 * @return int VAT number status code ID.
52 */
53 public function getVatNumberStatusCodeId($p_vatNumber, $p_countryId, $p_isGuest)
54 {
55 $this->vatValidation->reset($p_vatNumber, '', '', $p_countryId, (int)$p_isGuest);
56 $vatInfo = $this->vatValidation->getVatInfo();
57
58 return (int)$vatInfo['vat_id_status'];
59 }
60
61
62 /**
63 * Returns the customer status ID.
64 *
65 * @param string $p_vatNumber VAT number.
66 * @param int $p_countryId Country ID.
67 * @param bool $p_isGuest Is customer a guest?
68 *
69 * @return int Customer status ID.
70 */
71 public function getCustomerStatusId($p_vatNumber, $p_countryId, $p_isGuest)
72 {
73 $this->vatValidation->reset($p_vatNumber, '', '', $p_countryId, (int)$p_isGuest);
74 $vatInfo = $this->vatValidation->getVatInfo();
75
76 return (int)$vatInfo['status'];
77 }
78
79
80 /**
81 * Returns the error status
82 *
83 * @param string $p_vatNumber VAT number.
84 * @param int $p_countryId Country ID.
85 * @param bool $p_isGuest Is customer a guest?
86 *
87 * @return bool Error status.
88 */
89 public function getErrorStatus($p_vatNumber, $p_countryId, $p_isGuest)
90 {
91 $this->vatValidation->reset($p_vatNumber, '', '', $p_countryId, (int)$p_isGuest);
92 $vatInfo = $this->vatValidation->getVatInfo();
93
94 return $vatInfo['error'];
95 }
96
97
98 /**
99 * Writes the validation results to cache.
100 *
101 * @param string $p_vatNumber VAT number.
102 * @param int $p_countryId Country ID.
103 * @param bool $p_isGuest Is customer a guest?
104 *
105 * TODO Write validation results to cache.
106 */
107 protected function _putValidationCache($p_vatNumber, $p_countryId, $p_isGuest)
108 {
109 /*
110 $coo_vat_validation = new vat_validation($vatNumber, '', '', $country->getId(), $p_guest);
111
112 $customerStatus = $coo_vat_validation->vat_info['status'];
113 $numberStatus = $coo_vat_validation->vat_info['vat_id_status'];
114 $infoError = $coo_vat_validation->vat_info['error'];
115 */
116 }
117 }
118