2026-06-23 17:53:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Lib\Axepta;
|
|
|
|
|
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
|
use Illuminate\Support\Str;
|
2026-09-25 16:25:31 +02:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2026-06-23 17:53:34 +02:00
|
|
|
|
|
|
|
|
class AxeptaApiGateway
|
|
|
|
|
{
|
|
|
|
|
private Client $client;
|
|
|
|
|
|
|
|
|
|
public function __construct(AxeptaConfig $config, ?Client $client = null)
|
|
|
|
|
{
|
|
|
|
|
$this->client = $client ?? new Client([
|
|
|
|
|
'base_uri' => $config->endpoint,
|
|
|
|
|
'timeout' => 5.0,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function post(string $uri, array $payload, string $token): ResponseInterface
|
|
|
|
|
{
|
|
|
|
|
return $this->client->post($uri, [
|
|
|
|
|
'headers' => [
|
|
|
|
|
'Authorization' => "Bearer {$token}",
|
|
|
|
|
'Content-Type' => 'application/json',
|
2026-09-25 16:25:31 +02:00
|
|
|
'Idempotency-Key' => (string) Str::uuid(),
|
2026-06-23 17:53:34 +02:00
|
|
|
],
|
2026-09-25 16:25:31 +02:00
|
|
|
'json' => $payload,
|
2026-06-23 17:53:34 +02:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get(string $uri, string $token): ResponseInterface
|
|
|
|
|
{
|
|
|
|
|
return $this->client->get($uri, [
|
|
|
|
|
'headers' => [
|
|
|
|
|
'Authorization' => "Bearer {$token}",
|
|
|
|
|
'Content-Type' => 'application/json',
|
2026-09-25 16:25:31 +02:00
|
|
|
],
|
2026-06-23 17:53:34 +02:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function postForm(string $uri, array $formParams): ResponseInterface
|
|
|
|
|
{
|
|
|
|
|
return $this->client->post($uri, [
|
2026-09-25 16:25:31 +02:00
|
|
|
'form_params' => $formParams,
|
2026-06-23 17:53:34 +02:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|