9) { $c = $c - 9; } $s += $c; } if ((10 - $s % 10) % 10 != ord($partita_iva[10]) - ord('0')) { return false; } return true; } /** * Controlla se la partita iva inserita è valida. * * @param string $vat_number * * @return bool */ public static function isValidVatNumber($vat_number) { if (empty($vat_number)) { $result['valid-format'] = true; } // Controllo sulla sintassi if (starts_with($vat_number, 'IT') && !static::vatCheckIT($vat_number)) { $result['valid-format'] = false; return $result; } /* // Controllo con API europea ufficiale if (extension_loaded('soap')) { try { $validator = new VatCalculator(); if (!$validator->isValidVATNumber($vat_number)) { return false; } } catch (VATCheckUnavailableException $e) { } } */ // Controllo attraverso apilayer if (Services::isEnabled()) { $response = Services::request('post', 'check_iva', [ 'partita_iva' => $vat_number, ]); $data = Services::responseBody($response); if (!empty($data['result'])) { $result['valid-format'] = $data['result']['format_valid']; $result['valid'] = $data['result']['valid']; $fields = []; // Ragione sociale $fields['ragione_sociale'] = $data['result']['company_name']; // Indirizzo $address = $data['result']['company_address']; $info = explode(PHP_EOL, $address); $fields['indirizzo'] = $info[0]; $info = explode(' ', $info[1]); $fields['cap'] = $info[0]; $fields['provincia'] = end($info); $citta = array_slice($info, 1, -1); $fields['citta'] = implode(' ', $citta); $result['fields'] = $fields; } } return $result; } /** * Controlla se l'email inserita è valida. * * @param string $email * * @return array */ public static function isValidEmail($email) { $result = []; if (!v::email()->validate($email)) { $result['valid-format'] = false; return $result; } // Controllo attraverso apilayer if (Services::isEnabled()) { $response = Services::request('post', 'check_email', [ 'email' => $email, ]); $data = Services::responseBody($response); if (!empty($data['result'])) { $result['valid-format'] = $data['result']['format_valid']; $result['smtp-check'] = $data['result']['smtp_check']; } } return $result; } public static function isValidTaxCode($codice_fiscale) { if (empty($codice_fiscale)) { return true; } $validator = new CodiceFiscale\Validator($codice_fiscale); return $validator->isFormallyValid(); } }