Supporto versione in OSMServices

This commit is contained in:
Thomas Zilio 2019-07-19 17:58:03 +02:00
parent 69b81da1e1
commit 457a633469
3 changed files with 23 additions and 42 deletions

View File

@ -24,6 +24,7 @@ class Services
$json = array_merge($data, [
'token' => setting('OSMCloud Services API Token'),
'version' => setting('OSMCloud Services API Version'),
'resource' => $resource,
]);

View File

@ -1,5 +1,6 @@
<?php
use API\Services;
use Mpociot\VatCalculator\Exceptions\VATCheckUnavailableException;
use Mpociot\VatCalculator\VatCalculator;
use Respect\Validation\Validator as v;
@ -122,57 +123,30 @@ class Validate
}
// Controllo attraverso apilayer
$access_key = setting('apilayer API key for Email');
if (!empty($access_key)) {
if (!extension_loaded('curl')) {
flash()->warning(tr('Estensione cURL non installata'));
return true;
}
$qs = '&email='.urlencode($email);
$qs .= "&smtp=$smtp";
$qs .= '&format=1';
$qs .= '&resource=check_email';
$url = "https://services.osmcloud.it/api/?token=$access_key".$qs;
$curl_options = [
CURLOPT_URL => $url,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => 'gzip,deflate',
];
$ch = curl_init();
curl_setopt_array($ch, $curl_options);
$output = curl_exec($ch);
curl_close($ch);
$data = json_decode($output, false);
if (Services::isEnabled()) {
$response = Services::request('get', 'check_email', [
'email' => $email,
'smtp' => $smtp,
'format' => 1,
]);
$data = Services::responseBody($response);
/*se la riposta è null verificando il formato, il record mx o il server smtp imposto la relativa proprietà dell'oggetto a 0*/
if ($data->format_valid == null) {
$data->format_valid = 0;
if ($data['format_valid'] == null) {
$data['format_valid'] = 0;
}
if ($data->mx_found == null && $smtp) {
$data->mx_found = 0;
if ($data['mx_found'] == null && $smtp) {
$data['mx_found'] = 0;
}
if ($data->smtp_check == null && $smtp) {
$data->smtp_check = 0;
if ($data['smtp_check'] == null && $smtp) {
$data['smtp_check'] = 0;
}
$data->smtp = $smtp;
$data['smtp'] = $smtp;
$data->json_last_error = json_last_error();
$data->json_last_error_msg = json_last_error_msg();
return empty($data->format_valid) ? false : $data;
return empty($data['format_valid']) ? false : $data;
}
return true;

View File

@ -111,3 +111,9 @@ INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `e
(NULL, 'v1', 'update', 'sessione_intervento', 'Modules\\Interventi\\API\\v1\\Sessioni', '1'),
(NULL, 'v1', 'retrieve', 'articoli_intervento', 'Modules\\Interventi\\API\\v1\\Articoli', '1'),
(NULL, 'v1', 'create', 'articolo_intervento', 'Modules\\Interventi\\API\\v1\\Articoli', '1');
-- Supporto alla personalizzazione dell'API remota OSMCloud
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES
(NULL, 'OSMCloud Services API Version', 'v2', 'string', 0, 'Fatturazione Elettronica', 11);
DELETE FROM `zz_settings` WHERE `nome` = 'apilayer API key for Email';
DELETE FROM `zz_settings` WHERE `nome` = 'apilayer API key for VAT number';