63 lines
1.3 KiB
PHP
Executable File
63 lines
1.3 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 CancelPaymentService
|
|
{
|
|
protected string $url;
|
|
protected string $channelName;
|
|
protected string $accessToken;
|
|
protected array $headers;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->url = config('fib.cancelPayment.url');
|
|
$this->channelName = '';
|
|
}
|
|
|
|
public function setHeaders(): void
|
|
{
|
|
$this->headers = [
|
|
'Authorization' => 'Bearer ' . $this->accessToken,
|
|
'Content-Type' => 'application/json',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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
|
|
*/
|
|
public function sendRequest(): array
|
|
{
|
|
return Http::withHeaders($this->headers)
|
|
->throw()
|
|
->withoutVerifying()
|
|
->post($this->url)
|
|
->json();
|
|
}
|
|
}
|