51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Lib\Axepta;
|
|
|
|
use GuzzleHttp\Client;
|
|
use Illuminate\Support\Str;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
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',
|
|
'Idempotency-Key' => (string) Str::uuid(),
|
|
],
|
|
'json' => $payload,
|
|
]);
|
|
}
|
|
|
|
public function get(string $uri, string $token): ResponseInterface
|
|
{
|
|
return $this->client->get($uri, [
|
|
'headers' => [
|
|
'Authorization' => "Bearer {$token}",
|
|
'Content-Type' => 'application/json',
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function postForm(string $uri, array $formParams): ResponseInterface
|
|
{
|
|
return $this->client->post($uri, [
|
|
'form_params' => $formParams,
|
|
]);
|
|
}
|
|
}
|