Files
backend/backend/app/Services/FIB/CheckPaymentStatusService.php

68 lines
1.5 KiB
PHP
Executable File

<?php
namespace App\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class CheckPaymentStatusService
{
protected string $url;
protected string $channelName;
protected AuthorizationService $authorizationService;
public function __construct(AuthorizationService $authorizationService)
{
$this->url = config('fib.checkPaymentStatus.url');
$this->channelName = 'fib_status';
$this->authorizationService = $authorizationService;
}
/**
* @throws Exception
*/
public function run(): array
{
try {
return $this->sendRequest();
}
catch (Exception $e) {
Log::channel($this->channelName)
->error(get_class($this),
[
'message' => $e->getMessage(),
]
);
throw $e;
}
}
/**
* @throws ConnectionException
* @throws Exception
*/
public function sendRequest(): array
{
return Http::withHeaders([
'Authorization' => 'Bearer ' . $this->getToken(),
'Content-Type' => 'application/json',
])
->throw()
->withoutVerifying()
->post($this->url)
->json();
}
/**
* @throws Exception
*/
public function getToken(): string
{
$data = $this->authorizationService->run();
return $data['access_token'];
}
}