mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Storecove API
This commit is contained in:
parent
745c594f3b
commit
19465985c6
99
app/Services/EDocument/Gateway/Storecove/Storecove.php
Normal file
99
app/Services/EDocument/Gateway/Storecove/Storecove.php
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Services\EDocument\Gateway;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
|
||||||
|
enum HttpVerb: string
|
||||||
|
{
|
||||||
|
case POST = 'post';
|
||||||
|
case PUT = 'put';
|
||||||
|
case GET = 'get';
|
||||||
|
case PATCH = 'patch';
|
||||||
|
case DELETE = 'delete';
|
||||||
|
}
|
||||||
|
|
||||||
|
class Storecove {
|
||||||
|
|
||||||
|
private array $peppol_discovery = [
|
||||||
|
"documentTypes" => ["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
|
||||||
|
}
|
@ -240,5 +240,5 @@ return [
|
|||||||
'private_key' => env('NINJA_PRIVATE_KEY', false),
|
'private_key' => env('NINJA_PRIVATE_KEY', false),
|
||||||
],
|
],
|
||||||
'upload_extensions' => env('ADDITIONAL_UPLOAD_EXTENSIONS', ''),
|
'upload_extensions' => env('ADDITIONAL_UPLOAD_EXTENSIONS', ''),
|
||||||
|
'storecove_api_key' => env('STORECOVE_API_KEY', false),
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user