2024-07-15 06:27:12 +02:00
|
|
|
<?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.
|
|
|
|
|
|
|
|
|
2024-07-15 09:09:58 +02:00
|
|
|
//response = { "code": "OK", "email": false}
|
2024-07-15 06:27:12 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-07-15 09:09:58 +02:00
|
|
|
//response = "guid" : "xx",
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the receiver cannot be found, then an
|
|
|
|
* email is sent to that user if a appropriate
|
|
|
|
* email is included in the document payload
|
|
|
|
*
|
|
|
|
* {
|
|
|
|
"routing": {
|
|
|
|
"emails": [
|
|
|
|
"test@example.com"
|
|
|
|
],
|
|
|
|
"eIdentifiers": []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*
|
2024-07-16 00:31:56 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
// documentType : invoice/invoice_response/order
|
|
|
|
// rawDocumentData : {
|
|
|
|
// document: base64_encode($ubl)
|
|
|
|
// parse: true
|
|
|
|
// parseStrategy: ubl
|
|
|
|
// }
|
2024-07-15 09:09:58 +02:00
|
|
|
*/
|
|
|
|
public function sendDocument($document)
|
|
|
|
{
|
2024-07-16 00:31:56 +02:00
|
|
|
|
|
|
|
$payload = [
|
|
|
|
'documentType' => 'invoice',
|
|
|
|
'rawDocumentData' => base64_encode($document),
|
|
|
|
'parse' => true,
|
|
|
|
'parseStrategy', 'ubl'
|
|
|
|
];
|
|
|
|
|
2024-07-15 09:09:58 +02:00
|
|
|
$uri = "https://api.storecove.com/api/v2/document_submissions";
|
|
|
|
|
2024-07-16 00:31:56 +02:00
|
|
|
$r = $this->httpClient($uri, (HttpVerb::POST)->value, $payload, $this->getHeaders());
|
2024-07-15 09:09:58 +02:00
|
|
|
|
|
|
|
if($r->successful())
|
|
|
|
return $r->json()['guid'];
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//document submission sending evidence
|
2024-07-16 00:31:56 +02:00
|
|
|
public function getSendingEvidence(string $guid)
|
2024-07-15 09:09:58 +02:00
|
|
|
{
|
|
|
|
$uri = "https://api.storecove.com/api/v2/document_submissions/{$guid}";
|
|
|
|
$r = $this->httpClient($uri, (HttpVerb::GET)->value, [], $this->getHeaders());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-07-15 06:27:12 +02:00
|
|
|
private function getHeaders(array $headers = [])
|
|
|
|
{
|
|
|
|
|
|
|
|
return array_merge([
|
|
|
|
'Accept' => 'application/json',
|
|
|
|
'Content-type' => 'application/json',
|
|
|
|
], $headers);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-07-16 00:31:56 +02:00
|
|
|
private function httpClient(string $uri, string $verb, array $data, ?array $headers = [])
|
2024-07-15 06:27:12 +02:00
|
|
|
{
|
|
|
|
|
2024-07-15 09:09:58 +02:00
|
|
|
$r = Http::withToken(config('ninja.storecove_api_key'))
|
2024-07-15 06:27:12 +02:00
|
|
|
->withHeaders($this->getHeaders($headers))
|
2024-07-15 09:09:58 +02:00
|
|
|
->{$verb}($uri, $data);
|
2024-07-15 06:27:12 +02:00
|
|
|
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
2024-07-16 00:31:56 +02:00
|
|
|
|
2024-07-15 06:27:12 +02:00
|
|
|
}
|