mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Qvalias
This commit is contained in:
parent
2221353622
commit
6f25be937d
144
app/Services/EDocument/Gateway/Qvalia/Partner.php
Normal file
144
app/Services/EDocument/Gateway/Qvalia/Partner.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?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\Qvalia;
|
||||
|
||||
class Partner
|
||||
{
|
||||
|
||||
private string $partner_number;
|
||||
|
||||
public function __construct(public Qvalia $qvalia)
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
|
||||
}
|
120
app/Services/EDocument/Gateway/Qvalia/Qvalia.php
Normal file
120
app/Services/EDocument/Gateway/Qvalia/Qvalia.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?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\Qvalia;
|
||||
|
||||
use App\DataMapper\Analytics\LegalEntityCreated;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Turbo124\Beacon\Facades\LightLogs;
|
||||
|
||||
class Qvalia
|
||||
{
|
||||
/** @var string $base_url */
|
||||
private string $base_url = 'https://api.qvalia.com';
|
||||
|
||||
/** @var string $sandbox_base_url */
|
||||
private string $sandbox_base_url = 'https://api-qa.qvalia.com';
|
||||
|
||||
private bool $test_mode = true;
|
||||
|
||||
/** @var array $peppol_discovery */
|
||||
private array $peppol_discovery = [
|
||||
"documentTypes" => ["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
|
||||
}
|
||||
}
|
@ -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),
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user