From 6f25be937dcdcfc557c2475367c0f140f660f5c6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 16 Sep 2024 10:52:12 +1000 Subject: [PATCH] Qvalias --- .../EDocument/Gateway/Qvalia/Partner.php | 144 ++++++++++++++++++ .../EDocument/Gateway/Qvalia/Qvalia.php | 120 +++++++++++++++ config/ninja.php | 4 +- 3 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 app/Services/EDocument/Gateway/Qvalia/Partner.php create mode 100644 app/Services/EDocument/Gateway/Qvalia/Qvalia.php diff --git a/app/Services/EDocument/Gateway/Qvalia/Partner.php b/app/Services/EDocument/Gateway/Qvalia/Partner.php new file mode 100644 index 000000000000..4cb82f65f52a --- /dev/null +++ b/app/Services/EDocument/Gateway/Qvalia/Partner.php @@ -0,0 +1,144 @@ +partner_number = config('ninja.qvalia_partner_number'); + } + + /** + * getAccount + * + * Get Partner Account Object + * @return mixed + */ + public function getAccount() + { + $uri = "/partner/{$this->partner_number}/account"; + + $r = $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::GET)->value, []); + + return $r->object(); + } + + /** + * getPeppolId + * + * Get information on a peppol ID + * @param string $id + * @return mixed + */ + public function getPeppolId(string $id) + { + $uri = "/partner/{$this->partner_number}/peppol/lookup/{$id}"; + + $uri = "/partner/{$this->partner_number}/account"; + + $r = $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::GET)->value, []); + + return $r->object(); + + } + + /** + * getAccountId + * + * Get information on a Invoice Ninja Peppol Client Account + * @param string $id + * @return mixed + */ + public function getAccountId(string $id) + { + $uri = "/partner/{$this->partner_number}/account/{$id}"; + } + + /** + * createAccount + * + * Create a new account for the partner + * @param array $data + * @return mixed + */ + public function createAccount(array $data) + { + $uri = "/partner/{$this->partner_number}/account"; + + return $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::POST)->value, $data)->object(); + } + + /** + * updateAccount + * + * Update an existing account for the partner + * @param string $accountRegNo + * @param array $data + * @return mixed + */ + public function updateAccount(string $accountRegNo, array $data) + { + $uri = "/partner/{$this->partner_number}/account/{$accountRegNo}"; + + return $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::PUT)->value, $data)->object(); + } + + /** + * deleteAccount + * + * Delete an account for the partner + * @param string $accountRegNo + * @return mixed + */ + public function deleteAccount(string $accountRegNo) + { + $uri = "/partner/{$this->partner_number}/account/{$accountRegNo}"; + + return $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::DELETE)->value)->object(); + } + + /** + * updatePeppolId + * + * Update a Peppol ID for an account + * @param string $accountRegNo + * @param string $peppolId + * @param array $data + * @return mixed + */ + public function updatePeppolId(string $accountRegNo, string $peppolId, array $data) + { + $uri = "/partner/{$this->partner_number}/account/{$accountRegNo}/peppol/{$peppolId}"; + + return $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::PUT)->value, $data)->object(); + } + + /** + * deletePeppolId + * + * Delete a Peppol ID for an account + * @param string $accountRegNo + * @param string $peppolId + * @return mixed + */ + public function deletePeppolId(string $accountRegNo, string $peppolId) + { + $uri = "/partner/{$this->partner_number}/account/{$accountRegNo}/peppol/{$peppolId}"; + + return $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::DELETE)->value)->object(); + } + +} diff --git a/app/Services/EDocument/Gateway/Qvalia/Qvalia.php b/app/Services/EDocument/Gateway/Qvalia/Qvalia.php new file mode 100644 index 000000000000..2c0f9bb9e084 --- /dev/null +++ b/app/Services/EDocument/Gateway/Qvalia/Qvalia.php @@ -0,0 +1,120 @@ + ["invoice"], + "network" => "peppol", + "metaScheme" => "iso6523-actorid-upis", + "scheme" => "de:lwid", + "identifier" => "DE:VAT" + ]; + + /** @var array $dbn_discovery */ + private array $dbn_discovery = [ + "documentTypes" => ["invoice"], + "network" => "dbnalliance", + "metaScheme" => "iso6523-actorid-upis", + "scheme" => "gln", + "identifier" => "1200109963131" + ]; + + private ?int $legal_entity_id; + + public Partner $parter; + + //integrationid - returned in headers + + public function __construct() + { + $this->init(); + $this->partner = new Partner($this); + } + + private function init(): self + { + + if($this->test_mode) + $this->base_url = $this->sandbox_base_url; + + return $this; + } + + public function sendDocument($legal_entity_id) + { + $uri = "/transaction/{$legal_entity_id}/invoices/outgoing"; + $verb = 'POST'; + } + + + /** + * httpClient + * + * @param string $uri + * @param string $verb + * @param array $data + * @param array $headers + * @return \Illuminate\Http\Client\Response + */ + public function httpClient(string $uri, string $verb, array $data, ?array $headers = []) + { + + try { + $r = Http::withToken(config('ninja.qvalia_api_key')) + ->withHeaders($this->getHeaders($headers)) + ->{$verb}("{$this->base_url}{$uri}", $data)->throw(); + } + catch (ClientException $e) { + // 4xx errors + + nlog("LEI:: {$this->legal_entity_id}"); + nlog("Client error: " . $e->getMessage()); + nlog("Response body: " . $e->getResponse()->getBody()->getContents()); + } catch (ServerException $e) { + // 5xx errors + + nlog("LEI:: {$this->legal_entity_id}"); + nlog("Server error: " . $e->getMessage()); + nlog("Response body: " . $e->getResponse()->getBody()->getContents()); + } catch (\Illuminate\Http\Client\RequestException $e) { + + nlog("LEI:: {$this->legal_entity_id}"); + nlog("Request error: {$e->getCode()}: " . $e->getMessage()); + $responseBody = $e->response->body(); + nlog("Response body: " . $responseBody); + + return $e->response; + + } + + return $r; // @phpstan-ignore-line + } +} diff --git a/config/ninja.php b/config/ninja.php index abb79e7fa787..e20e167bb412 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -242,5 +242,7 @@ return [ 'private_key' => env('NINJA_PRIVATE_KEY', false), ], 'upload_extensions' => env('ADDITIONAL_UPLOAD_EXTENSIONS', ''), - 'storecove_api_key' => env('STORECOVE_API_KEY', false), + 'storecove_api_key' => env('STORECOVE_API_KEY', false), + 'qvalia_api_key' => env('QVALIA_API_KEY', false), + 'qvalia_partner_number' => env('QVALIA_PARTNER_NUMBER', false), ];