b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Trustpilot / Reviews / Helper /
Filename/home/dev2.destoffenstraat.com/app/code/Trustpilot/Reviews/Helper/TrustpilotHttpClient.php
Size2.47 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified25-Feb-2022 04:42
Last accessed22-Aug-2025 20:03
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

namespace Trustpilot\Reviews\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Trustpilot\Reviews\Helper\HttpClient;
use Trustpilot\Reviews\Helper\TrustpilotPluginStatus;
use \Magento\Store\Model\StoreManagerInterface;
use \Magento\Framework\UrlInterface;

class TrustpilotHttpClient extends AbstractHelper
{
protected $_httpClient;
protected $_apiUrl;
protected $_storeManager;
protected $_pluginStatus;

public function __construct(
HttpClient $httpClient,
StoreManagerInterface $storeManager,
TrustpilotPluginStatus $pluginStatus)
{
$this->_pluginStatus = $pluginStatus;
$this->_httpClient = $httpClient;
$this->_storeManager = $storeManager;
$this->_apiUrl = \Trustpilot\Reviews\Model\Config::TRUSTPILOT_API_URL;
}

public function post($url, $origin, $data, $storeId)
{
$httpRequest = 'POST';
$response = $this->_httpClient->request(
$url,
$httpRequest,
$origin,
$data
);
if ($response['code'] > 250 && $response['code'] < 254) {
$this->_pluginStatus->setPluginStatus($response, $storeId);
}
return $response;
}

public function buildUrl($key, $endpoint)
{
return $this->_apiUrl . $key . $endpoint;
}

public function checkStatusAndPost($url, $origin, $data, $storeId)
{
$code = $this->_pluginStatus->checkPluginStatus($origin, $storeId);
if ($code > 250 && $code < 254) {
return array(
'code' => $code,
);
}
return $this->post($url, $origin, $data, $storeId);
}

public function postInvitation($key, $storeId, $data = array())
{
$origin = $this->_storeManager->getStore($storeId)->getBaseUrl(UrlInterface::URL_TYPE_WEB);
return $this->checkStatusAndPost($this->buildUrl($key, '/invitation'), $origin, $data, $storeId);
}

public function postSettings($key, $data)
{
$origin = $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_WEB);
return $this->post($this->buildUrl($key, '/settings'), $origin, $data, $storeId);
}

public function postBatchInvitations($key, $storeId, $data = array())
{
$origin = $this->_storeManager->getStore($storeId)->getBaseUrl(UrlInterface::URL_TYPE_WEB);
return $this->checkStatusAndPost($this->buildUrl($key, '/batchinvitations'), $origin, $data, $storeId);
}
}