74 lines
1.6 KiB
PHP
74 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\User\Services\FIB;
|
|
|
|
use Exception;
|
|
use Illuminate\Http\Client\ConnectionException;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CreatePaymentService
|
|
{
|
|
protected string $url;
|
|
protected string $channelName;
|
|
protected string $accessToken;
|
|
protected array $headers;
|
|
protected array $inputParameters;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->url = config('fib.createPayment.url');
|
|
$this->channelName = '';
|
|
}
|
|
|
|
public function setAccessToken(string $accessToken): void
|
|
{
|
|
$this->accessToken = $accessToken;
|
|
}
|
|
|
|
public function setHeaders(): void
|
|
{
|
|
$this->headers = [
|
|
'Authorization' => 'Bearer ' . $this->accessToken,
|
|
'Content-Type' => 'application/json',
|
|
];
|
|
}
|
|
|
|
public function setInputParameters(array $inputParameters): void
|
|
{
|
|
$this->inputParameters = $inputParameters;
|
|
}
|
|
|
|
/**
|
|
* @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, $this->inputParameters)
|
|
->json();
|
|
}
|
|
}
|