Skip to content

Commit 6a8087e

Browse files
aggiunte funzionalità UfficioPostale
1 parent f05435b commit 6a8087e

13 files changed

Lines changed: 286 additions & 40 deletions

File tree

src/classes/Comuni.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ function getCitiesByCap(string $cap, $ttl = 86400){
2727
return $data->data;
2828
}
2929

30+
/**
31+
*
32+
* A partire dal CAP restistuisce un'array di oggietti di tipo comune
33+
*
34+
* @param string $cap Il cap da ricercare
35+
* @param int $ttl Il tempo di chache degli oggetti ritornati, 0 per no chche
36+
*
37+
* @return array
38+
*/
39+
function getComuneByCatasto(string $codice_catastale, $ttl = 86400){
40+
$data = $this->connect("catastale/$codice_catastale", "GET", [], $ttl);
41+
return $data->data;
42+
}
43+
3044
/**
3145
* Restituisce la lista delle regioni italiani
3246
*

src/classes/FirmaDigitale.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,26 @@ function requestProduct($data){
3737
$urgenza = isset($data['urgenza'])?$data['urgenza']:NULL;
3838
$assistenza = isset($data['assistenza'])?$data['assistenza']:NULL;
3939
$callback = isset($data['callback'])?$data['callback']:NULL;
40+
$quantita = isset($data['quantita'])?$data['quantita']:NULL;
4041

4142
$params = [];
4243
if($anagrafica != NULL){
43-
if($type == "lettore"){
44+
if($type == "lettore" || $type == "vergine"){
4445
$params['anagrafica_spedizione'] = $anagrafica;
46+
}elseif($type == "spid"){
47+
$params['email'] = $anagrafica->email;
48+
$params['cellulare'] = $anagrafica->cellulare;
4549
}else{
4650
$params['anagrafica'] = $anagrafica;
4751
}
4852

4953
}
5054

55+
if($quantita != NULL && ($type == "lettore" || $type == "vergine")){
56+
$params['quantita'] = $quantita;
57+
}
58+
59+
5160
if($spedizione != NULL && ($type == "lettore" || $type == "firma")){
5261
$params['spedizione'] = $spedizione;
5362
}

src/classes/MarcheTemporali.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function availability(string $type, int $qty){
1717
return $data->data;
1818
}
1919

20-
function checkLotto($username, $password){
20+
function checkLotto($username, $password, $tipo){
2121

2222
if(substr($username,0,4) == "FAKE" && substr($password,0,4) == "FAKE"){
2323
$ret = new \stdClass();
@@ -29,7 +29,7 @@ function checkLotto($username, $password){
2929
$ret->error = NULL;
3030
return $ret->data;
3131
}
32-
$data = $this->connect("check_lotto", "POST", ["username"=>$username, "password"=> $password]);
32+
$data = $this->connect("check_lotto", "POST", ["username"=>$username, "password"=> $password,'type'=>$tipo]);
3333

3434
return $data->data;
3535
}

src/classes/OpenApiBase.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function connect(string $endpoint, $type = "GET", $param = [], $ttr = 0,
137137
$return = substr($response, $header_size);
138138
$httpCode = curl_getinfo ( $ch, CURLINFO_RESPONSE_CODE );;
139139
curl_close($ch);
140-
140+
//echo $return;exit;
141141
if(isset($this->parsedHEader['Content-Type']) && strtolower($this->parsedHEader['Content-Type']) == "application/json") {
142142

143143
$data = json_decode($return);
@@ -178,7 +178,7 @@ public function connect(string $endpoint, $type = "GET", $param = [], $ttr = 0,
178178
return $data;
179179
}
180180

181-
private function parseHeader($headers){
181+
protected function parseHeader($headers){
182182
$headers = explode("\n",$headers);
183183
$parsedHeaders = array();
184184
foreach ($headers as $header) {
@@ -199,4 +199,7 @@ private function parseHeader($headers){
199199
return $parsedHeaders;
200200
}
201201

202+
203+
204+
202205
}

src/classes/UfficioPostale.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ function __construct(string $token, array $scopes, object $cache, string $prefi
1818
* @return object
1919
*/
2020
function createRaccomandata(){
21-
return new \OpenApi\classes\utility\UfficioPostale\Raccomandata($this->connect);
21+
return new \OpenApi\classes\utility\UfficioPostale\Raccomandata(function(string $endpoint, $type = "GET", $param = [], $ttr = 0, $force = false, $forceRaw = false){
22+
23+
return $this->connect( $endpoint, $type, $param , $ttr , $force, $forceRaw);
24+
});
2225
}
2326

2427
//function createRaccomandataByData()

src/classes/Uploader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ function gateway(){
2323
if($endpoint == NULL){
2424
throw new \OpenApi\classes\exception\OpenApiUploaderException("No endpoint GET",40018);
2525
}
26+
//echo $endpoint;exit;
2627

2728
$method = $_SERVER['REQUEST_METHOD'];
2829
$data = null;
2930
if($method != "GET" && $method != "DELETE"){
3031
$data = file_get_contents("php://input");
3132
$data = json_decode($data);
3233
}
34+
3335
$data = $this->connect($endpoint, $method,$data);
36+
//var_dump($data);exit;
37+
38+
3439
header("Content-Type: ",$this->parsedHEader['Content-Type']);
3540
if(isset($this->parsedHEader['Content-Type']) && strtolower($this->parsedHEader['Content-Type']) == "application/json") {
3641
echo json_encode($data);

src/classes/VisEngine.php

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ function setHash(string $hash){
2222
$this->hash = $hash;
2323
}
2424

25-
function getDatiFornitore($email){
26-
$data = $this->connect("fornitori/$email", "GET", []);
27-
return $data;
28-
}
29-
30-
function getFornitori(){
31-
$data = $this->connect("fornitori", "GET", []);
32-
return $data;
33-
34-
}
35-
3625
function getFormTool(){
3726
if($this->hash == NULL){
3827
throw new \OpenApi\classes\exception\OpenApiVisEngineException("Visengine hash is not setted",40005);
@@ -69,10 +58,10 @@ function createRequest($ttr = 500){
6958
*
7059
* @return object
7160
*/
72-
function sendRequest(\OpenApi\classes\utility\VisEngine\VisRequest $req) {
61+
function sendRequest(\OpenApi\classes\utility\VisEngine\VisRequest $req, $new_search = FALSE) {
7362

7463

75-
64+
7665
if($req->getNew()){
7766
$params = new \stdClass();
7867
$params->state = $req->getState();
@@ -84,49 +73,93 @@ function sendRequest(\OpenApi\classes\utility\VisEngine\VisRequest $req) {
8473
if($req->getCallbackData() != NULL){
8574
$params->callback_data = $req->getCallbackData();
8675
}
76+
if($req->getFornitore() != NULL){
77+
$params->callback = $req->getFornitore();
78+
}
8779
if($req->getTargetEmail() != NULL){
8880
$params->email_target = $req->getTargetEmail();
8981
}
9082
$data = $this->connect("richiesta", "POST", $params);
91-
83+
//var_dump($data);exit;
9284
$req->setNew(FALSE);
9385
$req->setId($data->data->_id);
9486
$req->setStatoRichiesta($data->data->stato_richiesta);
87+
88+
if(isset($data->data->callback)){
89+
$req->setFornitore($data->data->callback);
90+
}else{
91+
$req->setFornitore(NULL);
92+
}
9593
if(isset($data->data->ricerche)){
9694
$req->setRicerche($data->data->ricerche);
9795
}
9896
return $req;
9997
}else{
100-
98+
10199
$params = new \stdClass();
102100
$params->state = $req->getState();
103101
// $params->test = $req->getTest();
104-
102+
$id_visura = $req->getId();
105103
if($req->getJson() != NULL){
106104
$params->json_visura = $req->getJson();
107105
}
108106

109-
$id_visura = $req->getId();
107+
110108
//echo json_encode($params);exit;
111109
//var_dump($params);exit;
110+
$visura = $this->connect("richiesta/$id_visura", "GET");
111+
112+
if(!$new_search)
113+
{
112114
$data = $this->connect("richiesta/$id_visura", "PUT", $params);
113-
115+
}else{
116+
$data = $this->connect("richiesta/$id_visura", "POST", $params);
117+
}
118+
119+
// var_dump($data);exit;
120+
121+
114122

115123
$req->setNew(FALSE);
116124
$req->setId($data->data->_id);
117125
$req->setStatoRichiesta($data->data->stato_richiesta);
126+
if(isset($data->data->callback)){
127+
$req->setFornitore($data->data->callback);
128+
}
118129
if(isset($data->data->ricerche)){
119130
$req->setRicerche($data->data->ricerche);
120131
}
121132
return $req;
122133
}
123134
}
124135

136+
function getDatiFornitore($email){
137+
$data = $this->connect("fornitori/$email", "GET", []);
138+
return $data;
139+
}
140+
141+
function getFornitori(){
142+
$data = $this->connect("fornitori", "GET", []);
143+
return $data;
144+
145+
}
146+
125147
function getRequestByIdVisura($id_visura){
126148
$visura = $this->connect("richiesta/$id_visura", "GET");
149+
150+
/*if($visura->data->callback){
151+
var_dump($visura->data->callback);exit;
152+
}*/
153+
127154
return $this->getRequestByData($visura);
128155
}
129156

157+
function cancelRequest($id_visura, $motivazione){
158+
$visura = $this->connect("richiesta/$id_visura", "DELETE",["motivo"=>$motivazione]);
159+
return $this->getRequestByIdVisura($id_visura);
160+
}
161+
162+
130163
function getRequestByData($visura){
131164

132165
$this->visura = $this->connect("visure/{$visura->data->hash_visura}", "GET", [], 0);
@@ -136,12 +169,22 @@ function getRequestByData($visura){
136169
$request->setNew(FALSE);
137170
$request->setId($visura->data->_id);
138171
$request->setStatoRichiesta($visura->data->stato_richiesta);
139-
140172
if(isset($visura->data->ricerche)){
141173
$request->setRicerche($visura->data->ricerche);
142174
}else{
143175
$request->setRicerche([]);
144176
}
177+
if($request->getStatoRichiesta() == "Dati disponibili" || $request->getStatoRichiesta() == "Visura evasa"){
178+
$documento = $this->connect("documento/{$visura->data->_id}", "GET", [], 0);
179+
$request->setDocument($documento->data);
180+
}
181+
if($visura->data->stato_richiesta == "Annullata"){
182+
$request->setReasonCancellation($visura->data->motivo_annullamento);
183+
184+
}
185+
if(isset($visura->data->callback) && $visura->data->callback){
186+
$request->setFornitore($visura->data->callback);
187+
}
145188
return $request;
146189
}
147190

@@ -168,6 +211,10 @@ function setRicerca($id_visura, $id_ricerca, $index){
168211

169212
}
170213

214+
function getCatalog($ttr = 86400){
215+
return $this->connect("visure", "GET", NULL, $ttr);
216+
}
217+
171218
}
172219

173220

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace OpenApi\classes\exception;
3+
4+
/**
5+
* Gestisce le eccezioni relative alle funzionalità ufficiopostale
6+
* 40011: si sta tentando di confermare un prodotto postale non ancora inviato
7+
* 40012: si sta tentando di confermare un prodotto postale che non è nello stato di NEW
8+
*/
9+
class OpenApiUPException extends OpenApiExceptionBase
10+
{
11+
public function __construct($message, $code = 0, \Exception $previous = null) {
12+
parent::__construct($message, $code, $previous);
13+
}
14+
}

src/classes/utility/UfficioPostale/Objects/Recipient.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ function __construct($recipient = NULL){
4141

4242
$this->validate = false;
4343

44-
if($recipient == NULL){
44+
if($recipient != NULL){
4545
$this->createFromObject($recipient);
4646
}
4747
}
4848

4949
public function createFromObject($object){
50+
if(is_array($object)){
51+
$object = (object)$object;
52+
}
53+
//var_dump($object);Exit;
5054
$this->data->title = isset($object->title)?$object->title:(isset($object->titolo)?$object->titolo:NULL);
5155
$this->data->at = isset($object->at)?$object->at:(isset($object->co)?$object->co:NULL);
5256
$this->data->firstName = isset($object->firstName)?$object->firstName:(isset($object->nome)?$object->nome:NULL);
@@ -58,9 +62,13 @@ public function createFromObject($object){
5862
$this->data->city = isset($object->city)?$object->city:(isset($object->comune)?$object->comune:NULL);
5963
$this->data->zip = isset($object->zip)?$object->zip:(isset($object->cap)?$object->cap:NULL);
6064
$this->data->province = isset($object->province)?$object->province:(isset($object->provincia)?$object->provincia:NULL);
61-
$this->data->country = isset($object->country)?$object->country:(isset($object->nazione)?$object->nazione:"Italia");
65+
$this->data->country = isset($object->country)?$object->country:(isset($object->nazione)?$object->nazione:"IT");
6266
$this->data->email = isset($object->email)?$object->email:NULL;
6367

68+
$this->data->id = isset($object->id)?$object->id:NULL;
69+
$this->data->state = isset($object->state)?$object->state:NULL;
70+
71+
6472

6573
$this->itData->co = $this->data->at;
6674
$this->itData->titolo = $this->data->title;
@@ -75,6 +83,8 @@ public function createFromObject($object){
7583
$this->itData->provincia = $this->data->province;
7684
$this->itData->nazione = $this->data->country;
7785
$this->itData->email = $this->data->email;
86+
$this->itData->id= $this->data->id;
87+
$this->itData->state= $this->data->state;
7888

7989
}
8090

0 commit comments

Comments
 (0)