HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/quadcode/app/Helpers/RoistatHelper.php
<?php

namespace App\Helpers;

use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class RoistatHelper
{

    private string $integrationHost;
    private string $integrationToken;
    private string $apiHost;
    private int $apiProjectId;
    private string $apiToken;

    const LOG_CHANNEL = 'roistat';


    public function __construct()
    {
        $this->integrationHost = env('ROISTAT_INTEGRATION_HOST');
        $this->integrationToken = env('ROISTAT_INTEGRATION_TOKEN');
        $this->apiHost = env('ROISTAT_API_HOST');
        $this->apiProjectId = env('ROISTAT_API_PROJECT_ID');
        $this->apiToken = env('ROISTAT_API_TOKEN');
    }

    public function check(): bool
    {
        return !empty($this->integrationHost) && !empty($this->integrationToken) && !empty($this->apiHost) && !empty($this->apiProjectId) && !empty($this->apiToken);
    }

    private function getIntegration(string $apiMethod, array $data = []): Response
    {
        $data['key'] = $this->integrationToken;
        Log::channel(self::LOG_CHANNEL)->info('Integration get', compact('data'));
        $response = Http::get($this->integrationHost . '/' . $apiMethod, $data);
        Log::channel(self::LOG_CHANNEL)->info('Integration get response', $response->json());

        return $response;
    }

    private function getApi(string $apiMethod, array $data = []): Response
    {
        $data['project'] = $this->apiProjectId;
        Log::channel(self::LOG_CHANNEL)->info('API get', compact('data'));
        $response = Http::withHeaders(['Api-key' => $this->apiToken])->get($this->apiHost . '/' . $apiMethod, $data);
        Log::channel(self::LOG_CHANNEL)->info('API get response', $response->json());

        return $response;
    }

    public function getLeads(array $data): Response
    {
        return $this->getApi('project/proxy-leads', $data);
    }


    public function add(array $data): Response
    {
        return $this->getIntegration('leads/add', $data);
    }

}