From e9db4e92c3b76558be03f255fa0e98e192e7284d Mon Sep 17 00:00:00 2001 From: Nicolas Sanavia Date: Mon, 18 Oct 2021 17:43:26 +0200 Subject: [PATCH 1/8] feat: add hook --- src/Entities/Documenti.php | 109 ++++++++++++++++++++++-- src/Events/DocumentRequestPerformed.php | 99 +++++++++++++++++++++ 2 files changed, 202 insertions(+), 6 deletions(-) create mode 100644 src/Events/DocumentRequestPerformed.php diff --git a/src/Entities/Documenti.php b/src/Entities/Documenti.php index 8db3568..16424a0 100644 --- a/src/Entities/Documenti.php +++ b/src/Entities/Documenti.php @@ -2,6 +2,7 @@ namespace OfflineAgency\FattureInCloud\Entities; +use OfflineAgency\FattureInCloud\Events\DocumentRequestPerformed; use OfflineAgency\FattureInCloud\FattureInCloud; use OfflineAgency\FattureInCloud\Requests\Documenti as Request; @@ -18,7 +19,16 @@ public function lista($data = []) { Request::lista($data); - return $this->auth->post("{$this->docType}/lista", $data); + $response = $this->auth->post("{$this->docType}/lista", $data); + + event(new DocumentRequestPerformed( + $this->docType, + 'lista', + $data, + $response + )); + + return $response; } /** @@ -30,7 +40,16 @@ public function dettagli($data = []) { Request::dettagli($data); - return $this->auth->post("{$this->docType}/dettagli", $data); + $response = $this->auth->post("{$this->docType}/dettagli", $data); + + event(new DocumentRequestPerformed( + $this->docType, + 'dettagli', + $data, + $response + )); + + return $response; } /** @@ -42,7 +61,16 @@ public function nuovo($data = []) { Request::nuovo($data); - return $this->auth->post("{$this->docType}/nuovo", $data); + $response = $this->auth->post("{$this->docType}/nuovo", $data); + + event(new DocumentRequestPerformed( + $this->docType, + 'nuovo', + $data, + $response + )); + + return $response; } /** @@ -54,7 +82,16 @@ public function modifica($data = []) { Request::modifica($data); - return $this->auth->post("{$this->docType}/modifica", $data); + $response = $this->auth->post("{$this->docType}/modifica", $data); + + event(new DocumentRequestPerformed( + $this->docType, + 'modifica', + $data, + $response + )); + + return $response; } /** @@ -66,7 +103,16 @@ public function elimina($data = []) { Request::elimina($data); - return $this->auth->post("{$this->docType}/elimina", $data); + $response = $this->auth->post("{$this->docType}/elimina", $data); + + event(new DocumentRequestPerformed( + $this->docType, + 'elimina', + $data, + $response + )); + + return $response; } /** @@ -78,6 +124,57 @@ public function info($data = []) { Request::info($data); - return $this->auth->post("{$this->docType}/info", $data); + $response = $this->auth->post("{$this->docType}/info", $data); + + event(new DocumentRequestPerformed( + $this->docType, + 'info', + $data, + $response + )); + + return $response; + } + + /** + * @param array $data + * @return array|mixed|object|string + * @throws \Exception + */ + public function infoMail($data = []) + { + Request::infoMail($data); + + $response = $this->auth->post("{$this->docType}/infomail", $data); + + event(new DocumentRequestPerformed( + $this->docType, + 'infoMail', + $data, + $response + )); + + return $response; + } + + /** + * @param array $data + * @return array|mixed|object|string + * @throws \Exception + */ + public function inviaMail($data = []) + { + Request::inviaMail($data); + + $response = $this->auth->post("{$this->docType}/inviamail", $data); + + event(new DocumentRequestPerformed( + $this->docType, + 'inviaMail', + $data, + $response + )); + + return $response; } } diff --git a/src/Events/DocumentRequestPerformed.php b/src/Events/DocumentRequestPerformed.php new file mode 100644 index 0000000..83791d8 --- /dev/null +++ b/src/Events/DocumentRequestPerformed.php @@ -0,0 +1,99 @@ +setDocType( + $docType + ); + + $this->setMethod( + $method + ); + + $this->setRequest( + $request + ); + + $this->setResponse( + $response + ); + } + + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } + + /* GETTERs AND SETTERs */ + + public function getDocType() + { + return $this->docType; + } + + public function setDocType( + $docType + ): void + { + $this->docType = $docType; + } + + public function getMethod() + { + return $this->method; + } + + public function setMethod( + $method + ): void + { + $this->method = $method; + } + + public function getRequest() + { + return $this->request; + } + + public function setRequest( + $request + ): void + { + $this->request = $request; + } + + public function getResponse() + { + return $this->response; + } + + public function setResponse( + $response + ): void + { + $this->response = $response; + } +} From a5b7f155087d278e5bf9eaa23018ccb5c3e2dbd4 Mon Sep 17 00:00:00 2001 From: Nicolas Sanavia Date: Tue, 19 Oct 2021 12:43:44 +0200 Subject: [PATCH 2/8] feat: add additional data to documents endpoints --- src/Entities/Documenti.php | 76 ++++++++++++++++++------- src/Events/DocumentRequestPerformed.php | 18 ++++++ 2 files changed, 72 insertions(+), 22 deletions(-) diff --git a/src/Entities/Documenti.php b/src/Entities/Documenti.php index 16424a0..6962ea9 100644 --- a/src/Entities/Documenti.php +++ b/src/Entities/Documenti.php @@ -12,10 +12,13 @@ class Documenti extends FattureInCloud /** * @param array $data - * - * @return mixed|string + * @param array $additional_data + * @return array|mixed|object|string */ - public function lista($data = []) + public function lista( + array $data = [], + array $additional_data = [] + ) { Request::lista($data); @@ -25,6 +28,7 @@ public function lista($data = []) $this->docType, 'lista', $data, + $additional_data, $response )); @@ -33,10 +37,13 @@ public function lista($data = []) /** * @param array $data - * - * @return mixed|string + * @param array $additional_data + * @return array|mixed|object|string */ - public function dettagli($data = []) + public function dettagli( + array $data = [], + array $additional_data = [] + ) { Request::dettagli($data); @@ -46,6 +53,7 @@ public function dettagli($data = []) $this->docType, 'dettagli', $data, + $additional_data, $response )); @@ -54,10 +62,13 @@ public function dettagli($data = []) /** * @param array $data - * - * @return mixed|string + * @param array $additional_data + * @return array|mixed|object|string */ - public function nuovo($data = []) + public function nuovo( + array $data = [], + array $additional_data = [] + ) { Request::nuovo($data); @@ -67,6 +78,7 @@ public function nuovo($data = []) $this->docType, 'nuovo', $data, + $additional_data, $response )); @@ -75,10 +87,13 @@ public function nuovo($data = []) /** * @param array $data - * - * @return mixed|string + * @param array $additional_data + * @return array|mixed|object|string */ - public function modifica($data = []) + public function modifica( + array $data = [], + array $additional_data = [] + ) { Request::modifica($data); @@ -88,6 +103,7 @@ public function modifica($data = []) $this->docType, 'modifica', $data, + $additional_data, $response )); @@ -96,10 +112,13 @@ public function modifica($data = []) /** * @param array $data - * - * @return mixed|string + * @param array $additional_data + * @return array|mixed|object|string */ - public function elimina($data = []) + public function elimina( + array $data = [], + array $additional_data = [] + ) { Request::elimina($data); @@ -109,6 +128,7 @@ public function elimina($data = []) $this->docType, 'elimina', $data, + $additional_data, $response )); @@ -117,10 +137,13 @@ public function elimina($data = []) /** * @param array $data - * - * @return mixed|string + * @param array $additional_data + * @return array|mixed|object|string */ - public function info($data = []) + public function info( + array $data = [], + array $additional_data = [] + ) { Request::info($data); @@ -130,6 +153,7 @@ public function info($data = []) $this->docType, 'info', $data, + $additional_data, $response )); @@ -138,10 +162,13 @@ public function info($data = []) /** * @param array $data + * @param array $additional_data * @return array|mixed|object|string - * @throws \Exception */ - public function infoMail($data = []) + public function infoMail( + array $data = [], + array $additional_data = [] + ) { Request::infoMail($data); @@ -151,6 +178,7 @@ public function infoMail($data = []) $this->docType, 'infoMail', $data, + $additional_data, $response )); @@ -159,10 +187,13 @@ public function infoMail($data = []) /** * @param array $data + * @param array $additional_data * @return array|mixed|object|string - * @throws \Exception */ - public function inviaMail($data = []) + public function inviaMail( + array $data = [], + array $additional_data = [] + ) { Request::inviaMail($data); @@ -172,6 +203,7 @@ public function inviaMail($data = []) $this->docType, 'inviaMail', $data, + $additional_data, $response )); diff --git a/src/Events/DocumentRequestPerformed.php b/src/Events/DocumentRequestPerformed.php index 83791d8..957a48a 100644 --- a/src/Events/DocumentRequestPerformed.php +++ b/src/Events/DocumentRequestPerformed.php @@ -16,12 +16,14 @@ class DocumentRequestPerformed public $docType; public $method; public $request; + public $additional_info; public $response; public function __construct( string $docType, string $method, array $request, + array $additional_info, object $response ) { @@ -37,6 +39,10 @@ public function __construct( $request ); + $this->setAdditionalInfo( + $additional_info + ); + $this->setResponse( $response ); @@ -85,6 +91,18 @@ public function setRequest( $this->request = $request; } + public function getAdditionalInfo() + { + return $this->additional_info; + } + + public function setAdditionalInfo( + $additional_info + ): void + { + $this->additional_info = $additional_info; + } + public function getResponse() { return $this->response; From cea93ecf0f110468e9de1b3c82849675a40599dc Mon Sep 17 00:00:00 2001 From: Nicolas Sanavia Date: Tue, 19 Oct 2021 16:43:35 +0200 Subject: [PATCH 3/8] remove: broadcastOn on event --- src/Events/DocumentRequestPerformed.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Events/DocumentRequestPerformed.php b/src/Events/DocumentRequestPerformed.php index 957a48a..8c75677 100644 --- a/src/Events/DocumentRequestPerformed.php +++ b/src/Events/DocumentRequestPerformed.php @@ -3,7 +3,6 @@ namespace OfflineAgency\FattureInCloud\Events; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; @@ -48,11 +47,6 @@ public function __construct( ); } - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } - /* GETTERs AND SETTERs */ public function getDocType() From 16d325c590e774f5749dd467df03a5e9bb4aaf50 Mon Sep 17 00:00:00 2001 From: Nicolas Sanavia Date: Wed, 20 Oct 2021 17:33:42 +0200 Subject: [PATCH 4/8] fix: call method --- src/Auth.php | 198 ++++++++++++++++++------ src/Events/DocumentRequestPerformed.php | 20 ++- 2 files changed, 168 insertions(+), 50 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 2c17c05..029e26d 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -3,23 +3,19 @@ namespace OfflineAgency\FattureInCloud; use Exception; +use OfflineAgency\FattureInCloud\Events\DocumentRequestPerformed; class Auth { - private $errors = []; + private $attempts; private $params = []; - /** - * Auth constructor. - * - * @param string $apiUid - * @param string $apiKey - * - * @throws Exception - */ - public function __construct($apiUid = '', $apiKey = '') + public function __construct( + $apiUid = '', + $apiKey = '' + ) { - $this->errors = config('fatture-in-cloud.errors'); + $this->attempts = 0; if (empty($apiUid) || empty($apiKey)) { throw new \Exception('You need to pass apiUid and apiKey'); @@ -31,72 +27,176 @@ public function __construct($apiUid = '', $apiKey = '') ]; } - /** - * Exec API call. - * - * @param string $url - * @param array $data - * @param string $method - * - * @return array|mixed - */ - private function call($url = '', $data = [], $method = 'post') + private function call( + $url = '', + $data = [], + $method = 'post', + $additional_data = [], + $action = '', + $type = '' + ) { try { - $url = config('fatture-in-cloud.endpoint').$url; + $url = config('fatture-in-cloud.endpoint') . $url; $options = [ 'http' => [ - 'header' => "Content-type: text/json\r\n", - 'method' => $method, + 'header' => "Content-type: text/json\r\n", + 'method' => $method, 'content' => json_encode($data), ], ]; $context = stream_context_create($options); - $result = file_get_contents($url, false, $context); + $response = file_get_contents($url, false, $context); - return self::parseResponse($result); + $response = $this->parseResponse( + $response, + $url, + $data, + $method, + $additional_data, + $action, + $type + ); + + event(new DocumentRequestPerformed( + $type, + $action, + $data, + $additional_data, + $response, + $this->parseHeaders($http_response_header) + )); + + return $response; } catch (Exception $e) { - return (object) [ - 'error' => $e->getMessage(), - 'code' => $e->getCode(), + $response = (object)[ + 'error' => $e->getMessage(), + 'code' => $e->getCode(), + 'success' => false, + ]; + + event(new DocumentRequestPerformed( + $type, + $action, + $data, + $additional_data, + $response, + $this->parseHeaders($http_response_header) + )); + + return (object)[ + 'error' => $e->getMessage(), + 'code' => $e->getCode(), 'success' => false, ]; } } - /** - * Parse response. - * - * @param $response - * - * @throws Exception - * - * @return mixed - */ - private function parseResponse($response) + private function parseResponse( + $response, + $url, + $data, + $method, + $additional_data, + $action, + $type + ) { $json = json_decode($response); - if (isset($json->error)) { - throw new \Exception($json->error, $this->errors[$json->error_code]['code']); + if ( + isset($json->error) + && isset($json->error_code) + ) { + if ($json->error_code == 2007) { + $this->handleThrottle( + $json, + $url, + $data, + $method, + $additional_data, + $action, + $type + ); + } else { + throw new \Exception($json->error, $json->error_code); + } } return $json; } - /** - * POST call. - * - * @param $path - * @param array $data - * - * @return mixed|string - */ + private function handleThrottle( + $json, + $url, + $data, + $method, + $additional_data, + $action, + $type + ) + { + $attempts = $this->attempts; + $times = config('nom.config', 3); + + if ($attempts < $times) { + $this->attempts++; + $seconds = $this->getRetrySeconds( + $json->error + ); + + $seconds = $seconds * 1000; + usleep($seconds); + + $this->call( + $url, + $data, + $method, + $additional_data, + $action, + $type + ); + } else { + throw new \Exception('Timeout error', 'OA0001'); + } + } + + private function getRetrySeconds( + $error_message + ) + { + $seconds = 0; + $split_error_message = explode('Attendi ', $error_message); + if (count($split_error_message) > 1) { + $split_error_message = explode(' secondi', $split_error_message[1]); + $seconds = (int)$split_error_message[0]; + } + return $seconds * 1000; + } + public function post($path, $data = []) { $params = array_merge($this->params, $data); return $this->call($path, $params, 'POST'); } + + private function parseHeaders( + $headers + ): array + { + $head = array(); + foreach ($headers as $k => $v) { + $t = explode(':', $v, 2); + if (isset($t[1])) + $head[trim($t[0])] = trim($t[1]); + else { + $head[] = $v; + if (preg_match("#HTTP/[0-9\.]+\s+([0-9]+)#", $v, $out)) + $head['reponse_code'] = intval($out[1]); + } + } + return $head; + } } diff --git a/src/Events/DocumentRequestPerformed.php b/src/Events/DocumentRequestPerformed.php index 8c75677..62f73d6 100644 --- a/src/Events/DocumentRequestPerformed.php +++ b/src/Events/DocumentRequestPerformed.php @@ -17,13 +17,15 @@ class DocumentRequestPerformed public $request; public $additional_info; public $response; + public $response_header; public function __construct( string $docType, string $method, array $request, array $additional_info, - object $response + object $response, + array $response_header ) { $this->setDocType( @@ -45,6 +47,10 @@ public function __construct( $this->setResponse( $response ); + + $this->setResponseHeader( + $response_header + ); } /* GETTERs AND SETTERs */ @@ -108,4 +114,16 @@ public function setResponse( { $this->response = $response; } + + public function getResponseHeader() + { + return $this->response_header; + } + + public function setResponseHeader( + $response_header + ): void + { + $this->response_header = $response_header; + } } From 2047f4e261aadaeca133f5e641152bcc2da5b6db Mon Sep 17 00:00:00 2001 From: Nicolas Sanavia Date: Wed, 20 Oct 2021 17:49:33 +0200 Subject: [PATCH 5/8] fix: document callback --- src/Auth.php | 18 +++++- src/Entities/Documenti.php | 113 +++++++++++++------------------------ 2 files changed, 55 insertions(+), 76 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 029e26d..3a699c3 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -170,16 +170,28 @@ private function getRetrySeconds( $split_error_message = explode('Attendi ', $error_message); if (count($split_error_message) > 1) { $split_error_message = explode(' secondi', $split_error_message[1]); - $seconds = (int)$split_error_message[0]; + $seconds = (int)$split_error_message[0]; } return $seconds * 1000; } - public function post($path, $data = []) + public function post( + $path, + $data = [], + $additional_data = [], + $action = '', + $type = '' + ) { $params = array_merge($this->params, $data); - return $this->call($path, $params, 'POST'); + return $this->call( + $path, $params, + 'POST', + $additional_data, + $action, + $type + ); } private function parseHeaders( diff --git a/src/Entities/Documenti.php b/src/Entities/Documenti.php index 6962ea9..527f6d6 100644 --- a/src/Entities/Documenti.php +++ b/src/Entities/Documenti.php @@ -2,7 +2,6 @@ namespace OfflineAgency\FattureInCloud\Entities; -use OfflineAgency\FattureInCloud\Events\DocumentRequestPerformed; use OfflineAgency\FattureInCloud\FattureInCloud; use OfflineAgency\FattureInCloud\Requests\Documenti as Request; @@ -22,17 +21,13 @@ public function lista( { Request::lista($data); - $response = $this->auth->post("{$this->docType}/lista", $data); - - event(new DocumentRequestPerformed( - $this->docType, - 'lista', + return $this->auth->post( + "{$this->docType}/lista", $data, $additional_data, - $response - )); - - return $response; + 'lista', + $this->docType + ); } /** @@ -47,17 +42,13 @@ public function dettagli( { Request::dettagli($data); - $response = $this->auth->post("{$this->docType}/dettagli", $data); - - event(new DocumentRequestPerformed( - $this->docType, - 'dettagli', + return $this->auth->post( + "{$this->docType}/dettagli", $data, $additional_data, - $response - )); - - return $response; + 'dettagli', + $this->docType + ); } /** @@ -72,17 +63,13 @@ public function nuovo( { Request::nuovo($data); - $response = $this->auth->post("{$this->docType}/nuovo", $data); - - event(new DocumentRequestPerformed( - $this->docType, - 'nuovo', + return $this->auth->post( + "{$this->docType}/nuovo", $data, $additional_data, - $response - )); - - return $response; + 'nuovo', + $this->docType + ); } /** @@ -97,17 +84,13 @@ public function modifica( { Request::modifica($data); - $response = $this->auth->post("{$this->docType}/modifica", $data); - - event(new DocumentRequestPerformed( - $this->docType, - 'modifica', + return $this->auth->post( + "{$this->docType}/modifica", $data, $additional_data, - $response - )); - - return $response; + 'modifica', + $this->docType + ); } /** @@ -122,17 +105,13 @@ public function elimina( { Request::elimina($data); - $response = $this->auth->post("{$this->docType}/elimina", $data); - - event(new DocumentRequestPerformed( - $this->docType, - 'elimina', + return $this->auth->post( + "{$this->docType}/elimina", $data, $additional_data, - $response - )); - - return $response; + 'elimina', + $this->docType + ); } /** @@ -147,17 +126,13 @@ public function info( { Request::info($data); - $response = $this->auth->post("{$this->docType}/info", $data); - - event(new DocumentRequestPerformed( - $this->docType, - 'info', + return $this->auth->post( + "{$this->docType}/info", $data, $additional_data, - $response - )); - - return $response; + 'info', + $this->docType + ); } /** @@ -172,17 +147,13 @@ public function infoMail( { Request::infoMail($data); - $response = $this->auth->post("{$this->docType}/infomail", $data); - - event(new DocumentRequestPerformed( - $this->docType, - 'infoMail', + return $this->auth->post( + "{$this->docType}/infomail", $data, $additional_data, - $response - )); - - return $response; + 'infoMail', + $this->docType + ); } /** @@ -197,16 +168,12 @@ public function inviaMail( { Request::inviaMail($data); - $response = $this->auth->post("{$this->docType}/inviamail", $data); - - event(new DocumentRequestPerformed( - $this->docType, - 'inviaMail', + return $this->auth->post( + "{$this->docType}/inviamail", $data, $additional_data, - $response - )); - - return $response; + 'inviaMail', + $this->docType + ); } } From 4d2761b7b5c30cc50b3de5143ac00d7dfdbc312e Mon Sep 17 00:00:00 2001 From: Nicolas Sanavia Date: Thu, 21 Oct 2021 09:48:08 +0200 Subject: [PATCH 6/8] fix: error code on handle throttle --- src/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth.php b/src/Auth.php index 3a699c3..961e713 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -109,7 +109,7 @@ private function parseResponse( isset($json->error) && isset($json->error_code) ) { - if ($json->error_code == 2007) { + if ($json->error_code == 2002) { $this->handleThrottle( $json, $url, From 9402bb7d24eabc1b1131f4539930ab69714e8e98 Mon Sep 17 00:00:00 2001 From: Nicolas Sanavia Date: Thu, 21 Oct 2021 10:39:23 +0200 Subject: [PATCH 7/8] fix: get errors codes from config on handle throttle method --- config/fatture-in-cloud.php | 3 +++ src/Auth.php | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/fatture-in-cloud.php b/config/fatture-in-cloud.php index 6f93599..db64bd6 100644 --- a/config/fatture-in-cloud.php +++ b/config/fatture-in-cloud.php @@ -50,4 +50,7 @@ 'message' => 'Non è possibile completare la richiesta perché è stato raggiunto il limite massimo di anagrafiche.', ], ], + 'timeout-errors-codes' => [ + 2002 + ] ]; diff --git a/src/Auth.php b/src/Auth.php index 961e713..888b011 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -109,7 +109,8 @@ private function parseResponse( isset($json->error) && isset($json->error_code) ) { - if ($json->error_code == 2002) { + $timeout_errors_codes = config('fatture-in-cloud.timeout-errors-codes'); + if (in_array($json->error_code, $timeout_errors_codes)) { $this->handleThrottle( $json, $url, From d055e8591739fcaaacf099129c7a0c536afda76f Mon Sep 17 00:00:00 2001 From: Nicolas Sanavia Date: Thu, 21 Oct 2021 10:55:48 +0200 Subject: [PATCH 8/8] feat: add methods description --- composer.json | 2 +- src/Auth.php | 75 ++++++++++++++++++++++++++++++------ src/FattureInCloudFacade.php | 6 ++- 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 705a250..ed77850 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "OfflineAgency\\FattureInCloud\\FattureInCloudServiceProvider" ], "aliases": { - "FattureInCloud": "GarbinLuca\\FattureInCloud\\FattureInCloudFacade" + "FattureInCloud": "OfflineAgency\\FattureInCloud\\FattureInCloudFacade" } } } diff --git a/src/Auth.php b/src/Auth.php index 888b011..9965fde 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -10,9 +10,14 @@ class Auth private $attempts; private $params = []; + /** + * @param string $apiUid + * @param string $apiKey + * @throws Exception + */ public function __construct( - $apiUid = '', - $apiKey = '' + string $apiUid = '', + string $apiKey = '' ) { $this->attempts = 0; @@ -27,13 +32,22 @@ public function __construct( ]; } + /** + * @param string $url + * @param array $data + * @param string $method + * @param array $additional_data + * @param string $action + * @param string $type + * @return mixed|object + */ private function call( - $url = '', - $data = [], - $method = 'post', - $additional_data = [], - $action = '', - $type = '' + string $url = '', + array $data = [], + string $method = 'post', + array $additional_data = [], + string $action = '', + string $type = '' ) { try { @@ -94,6 +108,17 @@ private function call( } } + /** + * @param $response + * @param $url + * @param $data + * @param $method + * @param $additional_data + * @param $action + * @param $type + * @return mixed + * @throws Exception + */ private function parseResponse( $response, $url, @@ -128,6 +153,16 @@ private function parseResponse( return $json; } + /** + * @param $json + * @param $url + * @param $data + * @param $method + * @param $additional_data + * @param $action + * @param $type + * @throws Exception + */ private function handleThrottle( $json, $url, @@ -163,6 +198,10 @@ private function handleThrottle( } } + /** + * @param $error_message + * @return float|int + */ private function getRetrySeconds( $error_message ) @@ -176,12 +215,20 @@ private function getRetrySeconds( return $seconds * 1000; } + /** + * @param $path + * @param array $data + * @param array $additional_data + * @param string $action + * @param string $type + * @return mixed|object + */ public function post( $path, - $data = [], - $additional_data = [], - $action = '', - $type = '' + array $data = [], + array $additional_data = [], + string $action = '', + string $type = '' ) { $params = array_merge($this->params, $data); @@ -195,6 +242,10 @@ public function post( ); } + /** + * @param $headers + * @return array + */ private function parseHeaders( $headers ): array diff --git a/src/FattureInCloudFacade.php b/src/FattureInCloudFacade.php index 95d13f1..2270a9f 100644 --- a/src/FattureInCloudFacade.php +++ b/src/FattureInCloudFacade.php @@ -2,10 +2,12 @@ namespace OfflineAgency\FattureInCloud; -class FattureInCloudFacade extends \Illuminate\Support\Facades\Facade +use Illuminate\Support\Facades\Facade; + +class FattureInCloudFacade extends Facade { public static function getFacadeAccessor() { return 'fatture-in-cloud'; } -} \ No newline at end of file +}