From 19465985c60451c58313ee1c03f35d23b2583f46 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 15 Jul 2024 14:27:12 +1000 Subject: [PATCH] Storecove API --- .../EDocument/Gateway/Storecove/Storecove.php | 99 +++++++++++++++++++ config/ninja.php | 2 +- 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 app/Services/EDocument/Gateway/Storecove/Storecove.php diff --git a/app/Services/EDocument/Gateway/Storecove/Storecove.php b/app/Services/EDocument/Gateway/Storecove/Storecove.php new file mode 100644 index 000000000000..e5d4a479f495 --- /dev/null +++ b/app/Services/EDocument/Gateway/Storecove/Storecove.php @@ -0,0 +1,99 @@ + ["invoice"], + "network" => "peppol", + "metaScheme" => "iso6523-actorid-upis", + "scheme" => "de:lwid", + "identifier" => "10101010-STO-10" + ]; + + private array $dbn_discovery = [ + "documentTypes" => ["invoice"], + "network" => "dbnalliance", + "metaScheme" => "iso6523-actorid-upis", + "scheme" => "gln", + "identifier" => "1200109963131" + ]; + + + public function __construct(){} + + //config('ninja.storecove_api_key'); + + + //https://app.storecove.com/en/docs#_test_identifiers + //check if identifier is able to send on the network. + + + + public function discovery($identifier, $scheme, $network = 'peppol') + { + $network_data = []; + + match ($network) { + 'peppol' => $network_data = array_merge($this->peppol_discovery, ['scheme' => $scheme, 'identifier' => $identifier]), + 'dbn' => $network_data = array_merge($this->dbn_discovery, ['scheme' => $scheme, 'identifier' => $identifier]), + default => $network_data = array_merge($this->peppol_discovery, ['scheme' => $scheme, 'identifier' => $identifier]), + }; + + $uri = "https://api.storecove.com/api/v2/discovery/receives"; + + $r = $this->httpClient($uri, (HttpVerb::POST)->value, $network_data, $this->getHeaders()); + + return ($r->successful() && $r->json()['code'] == 'OK') ? true : false; + + } + + private function getHeaders(array $headers = []) + { + + return array_merge([ + 'Accept' => 'application/json', + 'Content-type' => 'application/json', + ], $headers); + + } + + public function httpClient(string $uri, string $verb, array $data, ?array $headers = []) + { + + $r = Http::withToken($this->access_token) + ->withHeaders($this->getHeaders($headers)) + ->{$verb}("{$this->api_endpoint_url}{$uri}", $data); + + return $r; + } + +// curl \ +// -X POST \ +// -H "Accept: application/json" \ +// -H "Authorization: Bearer API_KEY_HERE" \ +// -H "Content-Type: application/json" \ +// --data @discovery.json +} \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index e6bd9d75ae72..13c37af3e35c 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -240,5 +240,5 @@ return [ 'private_key' => env('NINJA_PRIVATE_KEY', false), ], 'upload_extensions' => env('ADDITIONAL_UPLOAD_EXTENSIONS', ''), - + 'storecove_api_key' => env('STORECOVE_API_KEY', false), ];